Position Sizing on available Cash


I am a beginner and looking for a way to calculate position sizing based on the available cash.

I have read some Posts with Topic "Position Sizing bases on Equity", likewise a post with the topic "position sizing based on available cash" which does not correspond to my question. What they write there is correct in this Posts, but only as long as I am not reducing an open position through ScaleOut.

Simple example:

InitialCapital = 100,000
MaxPos = 5
SPSPercentOfEquity = 100 / Maxpos

I start with 100,000 cash.

I am now opening 2 positions.

Then have 2 positions with 20,000 = 40,000 and 60,000 cash. Equity = 100,000

From the 2 open positions with a total of 40,000, I am reducing 20,000 through ScaleOut.

I then have 2 open positions with a total of 20,000 and 80,000 cash. Then equity = 100,000

Then I'll open three more positions. I reached MaxPos.
Equity = 100,000, 3 more positions = 3 X 20,000 = 60,000
I now have 5 open positions = 80,000 and 20,000 cash.

The cash position will increase more and more through scaleouts.

Maybe someone can give me a tip or a short CBT example of how I can program PositionSizing based on the amount of cash available. I searched the forum, help, and documentation and found nothing. A quick hint is enough.

Sorry for the stupid beginner question and thanks for a hint.

You would need to use mid-level custom backtest http://www.amibroker.com/guide/a_custombacktest.html

The bo.Cash propery holds current cash, so you should iterate thru signals (GetFirstSignal/GetNextSignal - the code is in the manual) and set

sig.PosSize = bo.Cash / 5;

before calling ProcessTradeSignals.

If you used Code Snippets (ready-to-use snippet for medium level CBT), you just add a single line, as shown below:


1 Like

Thanks Tomasz for the quick answer.
I should have come up with the idea myself without wasting your time.

I have now changed my code as follows ...

// ******** Custom Backtester **********

if (Status("action") == actionPortfolio) 
    cash = 0;
    bo = GetBacktesterObject();
    for (i = 0; i < BarCount; i++)	//  Loop through all bars
        for (sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
			if (sig.IsEntry()) sig.PosSize = bo.Cash / (MaxPos - bo.GetOpenPosQty);
        bo.ProcessTradeSignals( i );
        cash[ i ] = bo.cash;         

// ********** ScaleOuts verarbeiten ************

SetPositionSize( Ref(PosScaleOut,-Delays), IIf( Buy == sigScaleOut, spsPercentOfPosition, spsNoChange ) );

Everything seems to be working fine now. I disabled RuinStop. The ScaleOuts were also processed without a query to IsEntry ().

Once again, thank you very much for your help.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.