Navigation: Realtest Script Language > Syntax Element Details >







General-Purpose Functions


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




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 PositionSum(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), PositionSum(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, PositionSum(1), and PositionSum(Not(my_rule)) will all return the same value.

Another possible use of PositionSum would be to calculate your own statistics about currently open positions, e.g. PositionSum(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).

One more use of PositionSum might be to count how many other positions have the same characteristic (e.g. economic sector or industry) as the current one. For this purpose use the This function, e.g. PositionSum(Top(InfoTRBC,2) = This(Top(InfoTRBC,2))).

Note that PositionSum 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 PositionSum(expression)[offset] will probably not have meaningful results.




Copyright © 2020-2024 Systematic Solutions, LLC