Position sizing and Monte Carlo

before going further in my development I want to make sure my expectations of Monte Carlo are correct, which they may be or not.

I read this:

Of particular interest:

B.2 sequentially perform gain/loss calculation for each randomly picked trade, using position sizing defined by the user to produce system equity

To remove risks of serial correlation affecting the results of Monte Carlo simulation it is highly encouraged to use fixed position sizing (either fixed dollar value of trades or fixed number of shares/contracts), so the order in which given trade occurs in original sequence does not affect its profit/loss due to compounding.

Which i'm not sure i interpret correctly.

Anyway here is my context:

I created a custom position sizing algo using the custom backtester. Here is an extract of the portion of code of interest:

 if (sig.IsEntry() )    //  If this signal an entry

				currentEquity = bo.Equity;    
				//_TRACE("currentEquity from main file: " + currentEquity);
				if (fixedRatioPositionSizingEnabled)
					currentPositionSize = FixedRatioNumberOfContracts( currentEquity, delta, INITIALEQUITY );
					sig.PosSize = -2000 - currentPositionSize;    //  Set modified position size back into object

This is in the second loop of the CBT that will loop over each signal from each bar.

The function it is calling FixedRatioNumberOfContracts() is custom code that compute and return the number of contracts as defined exacly in Ryan Jones book from the Fixed Ratio chapter.

In Monte Carlo setting I set "Position Sizing to : Don't change".

  1. My first question is: will Monte Carlo simulation "understand" my position sizing custom code that doesn't rely on predefined position sizing options, and produce valid simulation ?

I'm worried about this because of my lack of exact understanding on how Monte Carlo simulation is handling this scenario in the context of custom position sizing procedure.

To illustrate let's take this hypothetical trades sequence with custom position sizing:

(trade, Profit, Number of Contract):
A: + 12 : 1
B: + 10 : 1
C: + 21 : 2
D: - 30 : 3
E: + 15 : 2
F: + 25 : 3
G: - 34 : 3

  1. What will Monte Carlo do if in a calculation of a new trade sequence, it places G (3 contracts, large loss) as A / first in new sequence of trades?
    Will it be smart enough to reduce loss and contract to expected size for a first sequence trade?
    Or will this not be able to because of custom position sizing?
1 Like

Monte Carlo does not analyze your code and does not care about your code at all.
All it does is shuffling trades from the existing trade list generated by backtest. It is precisely documented in https://www.amibroker.com/guide/h_montecarlo.html and there is nothing can be added to that. All that is needed is reading carefully and slowly each sentence and each word.

About the setting you asked for I can just quote the manual:

Don't change - uses original position size as used during backtest. Keep in mind that it always uses original dollar value of the trade (or whatever currency you use), even if your formula is using percent of portfolio equity.

Thank you for your answer.
So am I right to assume, that in the scenario of a position sized list of trades, where first trade has a gain of $10 with 1 contract, and the last one a loss of $1000 with 100 contracts, in the Monte Carlo shuffle of trades, that last trade can happen FIRST in a particular shuffled sequence, thus creating huge drawdown as first trade in that sequence?

I read all carefully but need to make sure I understand how things work.

As written in docs https://www.amibroker.com/guide/h_montecarlo.html:

Position sizing

defines position sizing method used by MC simulator in "trade list" mode:

Don't change - uses original position size as used during backtest. Keep in mind that it always uses original dollar value of the trade (or whatever currency you use), even if your formula is using percent of portfolio equity.

Fixed size - uses fixed number of shares/contracts per trade

Constant value - uses fixed dollar amount for opening any trade

Percent of equity - uses defined percent of current simulated equity value. Be careful when using this setting - it causes that position size of one trade depends on profits on previous trades (compounding profits) and creates serial dependence. It may also lead to extra compounding effect when you have overlapping trades in your original backtest as bootstrap performs trades sequentially (so they don't overlap). For this reason its use is limited to cases when no overlapping trades occur.

So obviously if you use "Don't change" the setting you will get the situation you described.

1 Like

Thank you for your answer.
A potential development path to explore: handle more position sizing methods in the software, so it would shuffle trades on each MC run before applying its own built in position sizing.

I was able to get what I want in the CBT so it's not really a problem, but would be a good addition to the software.

Again, you don't need CBT for that and all functionality is already there. You just need to read docs till the very end https://www.amibroker.com/guide/h_montecarlo.html - scroll down to the last chapter " How about Monte Carlo randomization instead of bootstrap test?"

Hi everyone,

Can someone please confirm the definition of overlapping trades?

If you have multiple trades on a single bar (end of day data) that are opened and closed on that same bar are these trades overlapping?

Or does overlapping trades referrer to trades that continue for multiple bars and are open or closed on different bars. eg trade 1 opens on the 10th and closes on 13th while trade 2 opens on the 11th and closes on the 16th.

I'm assuming scenario 2?