How do I scale position numbers based on growing portfolio equity

Hello all,

First time posting. I would like to scale the number of positions taken in a trading system based on the growing equity in a portfolio.
eg: With \$20000 equity take 1 position.
With 40000 take 2.
With 60000 take 3.
etc....

I have tried using nested IIF statements such as;

``````PEquity = Foreign ("~~~EQUITY","C");
IIf (PEquity > 200000, posqty = 20,
IIf (PEquity > 100000, posqty = 10,
IIf (PEquity > 80000, posqty = 4,
IIf (PEquity > 60000, posqty = 3,
IIf (PEquity > 40000, posqty = 2,

posqty = 1)))));

SetOption("MaxOpenPositions", posqty);

// desired position size is 100% portfolio equity
// divided by PosQty positions

PositionSize = -100/posqty;
PositionScore = 100-RSI(); // prefer stocks that have low RSI;
``````

but this doesn't seem to work. I only see one trade open at a time when backtesting. What am I missing? Is there a better way to code this?
Regards,

Graeme

You could approximate that behavior by using a fixed value for each position (e.g. \$20,000 for the first three steps in your example), but to really do what you're asking would require you to use a Custom Back Test (CBT). Not sure where you are on the AmiBroker learning curve, but writing a CBT is not generally recommended unless you have a lot of AB experience or a solid programming background.

The basic problem is that you can't see your portfolio equity from the Phase 1 AFL. The equity that you're retrieving is the equity generated by running a single-symbol back test.

1 Like

Thanks for taking the time to reply.

Unfortunately I am a relative novice in terms of my programming skills - but I can learn.

With further reading I now understand better some of the limits of the post-factum equity calculation in backtests.

I can somewhat simulate the desired outcome. ie Take the growing equity curve and increase the positions taken by running a manual walk-forward process.
eg: Back-test 12 months - record the final equity gain (or loss).
Add the profit (or loss) to the beginning equity for the next 12 months - increase the number of positions if applicable - Back-test....iterate forward 12 months after each run with the recalculated equity and positions number ... and so on...

Seems like a process that could be automated - but it is beyond my skills at this stage.

Regards,

Graeme