Navigation: Backtest Engine Details >

Asset Allocation and Position Sizing





RealTest takes a bottom-up approach to asset allocation and position sizing in a multi-strategy portfolio.

The initial AccountSize can be defined in the Settings section of your script or via the Settings Panel.

This value becomes the S.StartEquity value and the initial value of S.Equity for each strategy and of the combined system.

On each subsequent date of the backtest, as trades are entered and exited, all of the statistics series including S.Equity are updated.

The daily S.Equity (equity curve) value for a strategy will be the prior day's value plus the net change in value due to closed trade gains or losses plus (optionally) open position mark-to-market value changes. The combined system equity value is calculated the same way by using all positions from all strategies.

By default, S.Equity includes open position mark-to-market value, making it the Net Liquidation Value (NLV) of the account. To model a cash account, in which open position gains can not be reinvested until the position has been closed, use the strategy-level MarkToMarket setting. The default is MarkToMarket: True. For any strategy that specifies MarkToMarket: False, S.Equity will only change when positions are exited. If no strategy marks to market, then the combined system doesn't either.

Each Strategy definition will usually include a Quantity formula, and can optionally include an Allocation formula.

Quantity is evaluated at entry time for every new position, and Allocation is evaluated at the start of every date of a backtest.

If Allocation is not specified, the default is always the combined system S.Equity value.

In formula terms, this is expressed as Allocation: Combined(S.Equity). If that is your desired allocation, you can simply omit it.

Other Allocation possibilities include:

Allocation: S.Equity // don't compound strategy gains together, keep them separate, as if each had its own account

Allocation: S.StartEquity // model an account where all gains are immediately withdrawn and all losses immediately replaced

The current value of the Allocation formula is accessible via the S.Alloc syntax. Whether or not you define a custom allocation formula, it is advisable to use S.Alloc as your reference to current account value when specifying Quantity (position size).

If Quantity is not specified, the default position size will be S.Alloc, i.e., the entire current allocation.

By default, the Quantity formula specifies the number of shares (or contracts for futures) to buy or sell short when entering a new position. The formula can optionally be redefined as either the dollar value of the position or a percent of allocation, by adding QtyType to the strategy.

A very common Quantity formula, as seen in many of the example scripts, is:

In this example, positions is a parameter that defaults to 5. Position size is therefore 20%.

The equivalent to the above using the two other quantity types would be:


So given this flexibility to size positions any way you want, how do you control the caps on position count and investment level?

By default, RealTest places no limit on either of these things. This makes it quite easy to model a system that no broker would ever let you trade!

That said, it's quite easy to specify whatever risk limitations you want to apply.

To limit the total open position count of a strategy, add a MaxPositions formula.

To limit the total dollars invested, add a MaxInvested formula.

To limit the total percent invested, add a MaxExposure formula.

These three formulas, if specified, are evaluated each time new positions are ready to be entered in the backtest. By default, if a potential entry would push the position count beyond MaxPositions, or would cost enough to push the amount of cash invested in open positions beyond MaxInvested, or do the equivalent in percentage terms based on MaxExposure, then the entry is skipped.

In the latter case, you can optionally have the size of this last position reduced to make it fit within MaxInvested and MaxExposure, and allow it to still be taken, by adding Reduce: True to the strategy definition.

To gain greater understanding of how all of the above works, we suggest the following:

Run some tests with "Skipped" selected under "Keep Trades" in the Settings Panel. Look at the trade list and note the "Reason" column. This will show exactly why each skipped entry occurred.

To go deeper, check "Log" under "Test Output" and re-run the test. Now you have an extremely detailed log output that shows daily investment levels, new position values, and many other things.

Look through all the available graphs for a test result. These include counts of entries, exits and open positions, dollar investment level, a percent "exposure" and "usage". Peer under the hood of these graphs by pressing F9 to view their formulas.





Copyright © 2020-2022 Systematic Solutions, LLC