AmiBroker - current equity during backtest? - Aussie Stock Forums

# Thread: AmiBroker - current equity during backtest?

1. ## AmiBroker - current equity during backtest?

Is there any way in an AmiBroker back test to get the current equity value? I know there's an Equity function, but it doesn't seem to do what I'm looking for (either that or I don't understand exactly what it is doing ).

When setting the PositionSize variable, you can set it to a negative number for a percentage of equity (which I assume means percentage of current equity during the test, not percentage of initial capital). However, is there a variable or function that tells you exactly how much that current equity is?

What I want to do is be able to set an absolute position size based initially on percentage of equity, but then possibly modified downwards based on number of shares that represents relative to average daily volume. I can get the current buy price (BuyPrice variable), but to calculate how many shares 10% of equity is, I need to know what the current equity amount is.

For example, a simple 10% of equity (-10 position size) might give me a buy volume that's too high for the average daily traded volume, such that it would be unrealistic to expect to be able to fill that order without affecting the price significantly. I'd like to say that if it's greater than say EMA(V,100)*0.1, then reduce it to that value.

Thanks for any help.

Cheers,
GP

2. ## Re: AmiBroker - current equity during backtest?

This may only be a partial reply but you can limit the posistionsize within the AA settings - Portfolio - limit trade size as % of entry bar volume

the other is to use a formula in positionsize
something like this may work, (sorry not tested). I feel it needs more involved coding but with luck the simple may work. Just a matter of explroing various options

PositionSize = Min( -10, EMA(V,100)*0.1*BuyPrice );

3. ## Re: AmiBroker - current equity during backtest?

Kaveman,

Thanks for the ideas.

Originally Posted by kaveman
limit trade size as % of entry bar volume
Yeah I saw that option, but the way I read it, it's saying it only checks the one bar. If a break-out day caused a buy signal and had unusually high volume (as you might hope it would), then it might still give a position size that's too big.

PositionSize = Min( -10, EMA(V,100)*0.1*BuyPrice );
I have a feeling that will do as any good code should do: calculate the minimum without regard to the fact it's intended to be position size, in which case -10 will always be the minimum.

Cheers,
GP

4. ## Re: AmiBroker - current equity during backtest?

In the new version you can actually get the dollar value of your equity but it isn't for the faint hearted. I did a quick look in the documentation and found some bits and pieces but not the whole answer in one place. Look in the "advanced portfolio backtester interface" of the help. Below is something that I pinched and should start you on what you want.

MIT

SetOption("UseCustomBacktestProc", True);

if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject();
bo.PreProcess();

for (bar = 0; bar < BarCount; bar++)
{
for (sig = bo.GetFirstSignal(bar); sig; sig =
bo.GetNextSignal(bar))
{
if (sig.isEntry())
{
sig.PosSize = **** Your Equation. You can access equity by bo.equity ****;
}
}
}
bo.PostProcess();
}

Buy = Cross(EMA(C, 10), EMA(C, 30));
Sell = Cross(EMA(C, 30), EMA(C, 10));

5. ## Re: AmiBroker - current equity during backtest?

Thanks Mit.

I'm still using version 4.60, but I notice 4.70 seems to be available now.

And I'm not familiar with that backtester object thing, or the OO method of function referencing.

Looks like I'll have to get the upgrade soon and get up-to-date. I just hope it won't break anything during the upgrade

Cheers,
GP

6. ## Re: AmiBroker - current equity during backtest?

G'day,
I'm trying to get my head around this customising blacktesting stuff (thanks MIT for the bit of code) by trying to implement a portfolio stop, so that I don't enter into a trade if the Equity drops below its stop, but allow trading to continue with open trades. Using the following code it dosn't quite work,

======

SetOption("UseCustomBacktestProc", True);

if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject();
bo.PreProcess();

for (bar = 0; bar < BarCount; bar++)
{
for (sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar))
{

if( sig.isEntry() )
{
sig.PosSize = -10 ;
}

if( sig.isEntry() )
{
if (bo.Equity > 40000)
{
}
}

if( sig.isExit() )
{
}

}

}

bo.PostProcess();
=====
It seems when the stop is hit it contriues and ignores the pos size for trades below the stop???
I've been able to display an alert & also stop trading if the stop is broken. But not able to continue with open trades, any ideas?

Regards

7. ## Re: AmiBroker - current equity during backtest?

see if that works

8. ## Re: AmiBroker - current equity during backtest?

Close, but you need to use the equity calculated on the previous bar or it includes the current signal
this may work ok

the main thing this might not do is take into account multiple buy signals on one day which could take the equity below 40k, but I am not sure if using todays equity would be the answer equity()>=40000

try some backtests and see what happens.

simple answers often are the best, but only if they work

9. ## Re: AmiBroker - current equity during backtest?

Thank, guys, I tried both suggestions, you would think they would work, but still no go, for some reason it seems to ignore the results of the equity function.

I might contact AB & see if they can help.

Regards

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Aussie Stock Forums