- Joined
- 8 June 2008
- Posts
- 13,239
- Reactions
- 19,540
Backtesting Trade Ideas
I think that we each need to have a standardised approach to test all our trade ideas so we can compare each trade idea against each other in a consistent manner then we can make an informed decision on whether or not to continue with development with the idea.
I have fallen into the trap of testing an idea and it looked great only to find out I had some setting ticked ( or unticked ) which then caused errors in the backtest report. One thing you find out quickly is that AmiBroker does not make any mistakes it is the operator ( me ) who provides poor information which causes errors in accuracy.
I have tried a few options over the last year or so and to be honest I still don’t have the perfect way to test hence the idea for this thread so a consistent approach can be developed with input from interested forum members.
Analysis Settings Options
1. The first way I started testing was by adjusting the analysis settings manually via the control panel and then saving into a AmiBroker Analysis Settings (*.ABS) files, which worked great until I had a few different files and made mistakes by not loading a file or having the incorrect file open
View attachment 1047482. Now I initialise trading parameters in the AFL code via the SetOption function which takes out the human error ( that’s me again ) by having the incorrect options selected for a particular setting.
o AmiBroker guide Back-testing your trading ideas - https://www.amibroker.com/guide/h_backtest.html
o I like to have the following options pre-configured
SetOption ( "CommissionMode", 2 ); // $ per tradeo But obviously there is a heap more settings that can be adjusted and I think that I will look at having a file with all available options in it so it overrides any accidentally set in the Analysis window which may cause incorrect backtesting results
SetOption ( "CommissionAmount", 30 ); // $ Amount per trade
SetOption ( "InitialEquity", 100000 );
SetOption ( "AccountMargin", 100); // 100 means no margin
PositionSize = 10000;
SetPositionSize( PositionSize, spsValue ); // Dollar value of size
MaxPos = 20;
SetOption( "MaxOpenPositions", MaxPos );
SetTradeDelays( 1, 1, 1, 1 ); // Trade following day
SetOption ( "AllowSameBarExit", 0); // Off only allows next bar exit
SetOption ( "SeparateLongShortRank", 1); // Separate list for short system created
3. Custom Backtest Procedures
o As mentioned here in the AmiBroker Tips and Tricks thread https://www.aussiestockforums.com/posts/1075825/ you can load in you CBT file automatically and bring in some custom metrics which we have already started to learn how to develop in the previous posts.
Backtesting Strategies
1. What stock universe do you want to work with?
o All Ordinaries, ASX200, ASX 300 etc2. Market Time Frame to be used
o If you use a narrow time frame you might be only testing a bull market3. Optimisation
o What is In Sample period - Generally, where you are getting good results or optimised over a set time frame and you will be in a bull market for a long system
o What is Out of Sample period - Separate to the In Sample period where you might encounter different market conditions and your system is not optimised to this period and you could expect poorer results
o I think this is a great tool to see the effect of a rule or parameter you have added to your system.4. Walk Forward
o How much is too much. I am always cautious here but for me if you are using indicators with a period like MA(C,8.5) then I think you are over optimising and wasting your time.
o This is an area that I need to learn more about and AmiBroker is great in tackling the issue with In / Out of Sample data by automatically advancing dates as per below setup
View attachment 104747
Backtesting Metrics
1. What metric is important to you and your system ( or combination )
o Trade / System Drawdown
o Annual percentage gain
o Holding period
o Trading frequency
o Exposure
o Expectancy
o Equity smoothness
o Percent winners
o Win to loss ratio
Summary
So as you can see I have only touched on the topic of Backtesting your trade ideas and this is an area that we all need to understand and have a structured approach with so hopefully everyone will add a comment or tip so we can learn and become better system testers which in turn will hopefully make us better trades.
Cheers
Trav
. Now I initialise trading parameters in the AFL code via the SetOption function which takes out the human error ( that’s me again ) by having the incorrect options selected for a particular setting.
o I like to have the following options pre-configured
SetOption ( "CommissionMode", 2 ); // $ per trade
SetOption ( "CommissionAmount", 30 ); // $ Amount per trade
SetOption ( "InitialEquity", 100000 );
SetOption ( "AccountMargin", 100); // 100 means no margin
PositionSize = 10000;
SetPositionSize( PositionSize, spsValue ); // Dollar value of size
MaxPos = 20;
SetOption( "MaxOpenPositions", MaxPos );
SetTradeDelays( 1, 1, 1, 1 ); // Trade following day
SetOption ( "AllowSameBarExit", 0); // Off only allows next bar exit
SetOption ( "SeparateLongShortRank", 1); // Separate list for short system created
2018 - 2020 could be a bit narrow, do you get similar results say 2000 - 2018?
not sure I interpret/misinterpret properly: weekly system, trade delay = 1, price =openFor those testing systems on a weekly periodicity and trade delays set to 1
As per below post from the AmiBroker forum for a trade on Monday (next daily bar) do you run backtest in Daily periodicity and use TimeFrameCompress ??
This is something that I didn't know about in a weekly system. I have used TrimeFrameCompress for bringing in Foreign data for a filter but I would have thought that AmiBroker backtest would have taken in account that most people would have traded on the first opportunity being the Monday (next daily bar). I will need to test and see what this does to the performance ( good or bad ?)
https://forum.amibroker.com/t/periodicity-weekly-cbi/2783
View attachment 104829
I have found a paper from Howard Bandy (2012) who goes into good detail about walk forward testing and many other things
Developing Robust Trading Systems, with Implications for Position Sizing and System Health
For those interested I ran an optimisation on my PositionSize for one for my strategies I am playing with and bellow are the results.
Before Fixed PositionSize is 10k
After is a mixture of 5k to 15k and definitely not what I would have expected
VolatileBear, 15000
QuietBear, 5000
QuietBull, 15000
VolatileBull, 10000
I will check over a few different strategies as I suspect a different style of strategy will produce a different mix of PositionSize
Anyway Optimisation code used
PositionSize = IIf( VolatileBear, Optimize("VolatileBear", 10000, 5000, 15000, 5000), IIf( QuietBear, Optimize("QuietBear", 10000, 5000, 15000, 5000),
IIf( QuietBull, Optimize("QuietBull", 10000, 5000, 15000, 5000), IIf( VolatileBull, Optimize("VolatileBull", 10000, 5000, 15000, 5000), 0))));
Before / After - View attachment 104684
View attachment 104687
Obvious change to profit but some subtle changes overall, which I will need to review.
I am not an expert with all these metrics but tend to be drawn to a couple and even these surprise me (MDD) but will be interested to see how a change in stop parameters impacts this area as well.
Gee the fun never stop, enjoy
Equity( 1 );
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
dist = 1.5*ATR(10);
sellorcovertrigger = "Regular,Stop,Profit,Trail,N-bars,Ruin";
for( i = fvb; i <= lvb; i++ )
{
if( Buy[i] )
PlotText( "Buy\n" + BuyPrice[i], i, BuyPrice[i] - dist[i], colorGreen, -1, 0 );
if( Sell[i] )
PlotText( StrExtract(sellorcovertrigger, Sell[i]-1) + "\n" + SellPrice[i], i, SellPrice[i] + dist[i], colorRed, -1, 0 );
if( Short[i] )
PlotText( "Short\n" + ShortPrice[i], i, ShortPrice[i] + dist[i], colorRed, -1, 0 );
if( Cover[i] )
PlotText( StrExtract(sellorcovertrigger, Cover[i]-1) + "\n" + CoverPrice[i], i, CoverPrice[i] + dist[i], colorGreen, -1, 0 );
}
Hi All,
I am new and have recently started using Amibroker. I have some questions about system backtest and reading the backtest report. My apologies, if this thread is not the right place for the following questions.
Q1 - I am wondering which periods do you guys use in your backtest? Currently I am building my own trading system and I have been backtesting my system twice, firstly from 1/1/2008 to 31/12/2011, and secondly 1/1/2018 to 24/06/2020.
Q2 - If possible can you guys share about which items do you focus on when reading your backtest report (items such as Annual returns, Avg W/L, MDD and etc).
Cheers,
Antiwarclan
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?