[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Equity %, AFL bug? (long...)



PureBytes Links

Trading Reference Links

Hi all,

I wrote some small code to test how the backtester report works and I noticed a few glitches.

I run the tests on INTC from 7/1/2007 to 7/31/2007, initial equity is 2000.

AmiBroker version is 5.20.0 and 5.24.0

This code works fine... Well, I just noticed that the first signal is
a sell on the very first bar, so the help contains an error in the
"Common Coding mistakes in AFL" section (the first index of the Buy
vector is 1, right?). Anyway, it works fine, 4 buy and 5 sell signals.
---------------------------------------
RoundLotSize = 1;
PositionSize = 2000;

Buy = 0;

for (i = 0; i < BarCount; i++) {
	if (i % 5 == 0)
		Buy[i] = True;
	if (i % 5 == 1)
		Sell[i] = True;
}
---------------------------------------


the result of the following is the same as with the previous one
(outside the loop it doesn't make a difference if you change False to
True):
---------------------------------------
RoundLotSize = 1;
PositionSize = 2000;

Buy = 0;

for (i = 0; i < BarCount; i++) {
	if (i % 5 == 0)
		Buy[i] = True;
	if (i % 5 == 1)
		Sell[i] = True;
}
Buy[0] = False;
Buy[1] = False;
Buy[2] = False;
Buy[3] = False;
Buy[4] = False;
Buy[5] = False;
Buy[6] = False;
Buy[7] = False;
Buy[8] = False;
Buy[9] = False;
Buy[10] = False;
Buy[11] = False;
Buy[12] = False;
Buy[13] = False;
Buy[14] = False;
Buy[15] = False;
Buy[16] = False;
Buy[17] = False;
Buy[18] = False;
Buy[19] = False;
---------------------------------------
I was guessing that indexing only works inside a loop but if you put
the last 20 lines inside the loop, the result is still the same.


how about this one:
---------------------------------------
RoundLotSize = 1;
PositionSize = 2000;

Buy = 0;

for (i = 0; i < BarCount; i++) {
	if (i == 0)
		Buy[i] = True;
	if (i == 1)
		Sell[i] = True;
}
---------------------------------------
No buy or sell signals.

End of part one :)


Now, exposure %. I reduced the range so that the backtest is done from
7/3/2007 to 15/3/2007. Buy on 5th and sell on the same bar . The
resulting trade:
Buy on 7/9/2007 at 23.84
Sell on 7/9/2007 at 23.84
1 bar
Report shows 12.37% exposure.

2nd test: buy on 5th, sell on 6th
Buy on 7/9/2007 at 23.84
Sell on 7/10/2007 at 23.85
2 bars
Report shows 12.37% exposure.

3rd test: buy on 5th, sell on 7th
Buy on 7/9/2007 at 23.84
Sell on 7/11/2007 at 23.46
3 bars
Report shows 24.73% exposure.

The results should be ~12.5%, ~25%, ~37.5% (the number of bars in the
period is 8 ). I guess the problem is that when calculating the 'Sum
of bar exposures' the last bar is not included in the sum except when
the exit is on the same bar as the entry (in which case there is only
one bar).

That's all for now :)

BR/Szabi




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/