General-Purpose Functions


Evaluates an expression for each currently open position and returns the sum of the results




This is a specialized function meant to be used in entry-related formulas that need to know how many positions are open or will still be open after tomorrow's exits.

Referring to PSum(1) is equivalent to referring to S.Positions in that context.

Assuming a strategy uses ExitRule: my_rule where my_rule is an exit condition formula, and does exits at the next open (the default), PSum(Not(my_rule)) can be used to count the number of positions that will be open after tomorrow morning's exits but before any new entries. This kind of logic may be necessary when using a TestScan to produce a list of daily orders for the kind of strategy where you only want to use available position slots with no extra entry orders.

Other than the above example, in most use cases it is not necessary to deliberately calculate how many position slots will be available after tomorrow's exits. RealTest handles this automatically in both backtests and automatic order list generation (TestOutput: Orders). In these more typical scenarios, S.Positions, PSum(1), and PSum(Not(my_rule)) will all return the same value.

Another possible use of PSum would be to calculate your own statistics about currently open positions, e.g. PSum(Shares * (C - FillPrice)) would (assuming a long position) tell you the current net mark-to-market value of your open positions (equivalent to S.M2M).

Note that PSum cannot be used to refer to past positions in a strategy. It only has access to positions open on the current date in the test. Therefore PSum(expression)[offset] will probably have unmeaningful results.




Copyright © 2020-2022 Systematic Solutions, LLC