Hello,
I have an issue with backtesting: I have an indicator for which I want to optimize the period based on a wide range (1 to 300 bars).
The thing is: Let's say I optimize for three years:
a) If the optimizer checks out the strategy with a period of 1 bar, it calculates the whole three years period.
b) But if the optimizer checks e.g. the strategy with a period of 300 bars, it starts only after the 300th bar. So, the results will cover just a bit more than 2 years.
Because in the end not only the period will be optimized, also an (unwanted) optimization takes places regarding the date range - as higher values cause the optimization to start at a later date.
So, let's say the market went down drastically in the first month of the optimization period: Then runs with a period of more than 30 bars will be preferred cause then this first month will be omitted. But of course that is a form of curve fitting I am not looking for.
My question: Is there an easy and recommended way to deal with that? I know there are ways which cause a lot of additional work.
Thank you for your help!
Werner
I have an issue with backtesting: I have an indicator for which I want to optimize the period based on a wide range (1 to 300 bars).
The thing is: Let's say I optimize for three years:
a) If the optimizer checks out the strategy with a period of 1 bar, it calculates the whole three years period.
b) But if the optimizer checks e.g. the strategy with a period of 300 bars, it starts only after the 300th bar. So, the results will cover just a bit more than 2 years.
Because in the end not only the period will be optimized, also an (unwanted) optimization takes places regarding the date range - as higher values cause the optimization to start at a later date.
So, let's say the market went down drastically in the first month of the optimization period: Then runs with a period of more than 30 bars will be preferred cause then this first month will be omitted. But of course that is a form of curve fitting I am not looking for.
My question: Is there an easy and recommended way to deal with that? I know there are ways which cause a lot of additional work.
Thank you for your help!
Werner
Rename
For blocks the best you can do is add an indicator with the longest period to a "no op" condition — a condition that will always be true so that when ANDed it won't affect the other logic. That way, no trade will start for any permutation of the other variable until the longest period. Compensate with the Start Date to add more data since the first, say 300 bars, will be used only to seed indicators.
Thank you Cone. Actually I used this trick. The problem with it is that it seems that many of the backtesting figures get diluted because of the longer period. And the starting date has to be adapted, which was a bit tiring because a backtested a lot and for different periods.
But if that is the recommended way, I will go for it. One question: If I change the strategy to a code based strategy: Would there then be an easy remedy against this problem or would the situation be the same?
Thank you for your help!
Werner
But if that is the recommended way, I will go for it. One question: If I change the strategy to a code based strategy: Would there then be an easy remedy against this problem or would the situation be the same?
Thank you for your help!
Werner
QUOTE:
If I change the strategy to a code based strategy: ... would the situation be the same?
The "situation" would be the same, but you could use the StartIndex setting in C# to have more control over when to start trading. You certainly don't want to start trading if your longest period indicator has invalid data. You need to get out of this situation entirely.
I would think about shortening the longest period of your offending indicator. Or maybe use some other approach. Perhaps adding market sentiment (try the CNNFearGreed indicator in the PowerPack extension for starters) to your strategy so you're factoring in market behavior might be an alternative solution.
There is a trick involving creating the indicators based on the complete, unsynced daily history of a symbol. We used to do that in WL6 and I think I saw a WL8 implementation floating around. You then have to synchronize that indicator to the BarHistory in the backtest.
Maybe it would make sense to build an extension of the most common indicators that have this treatment, so they could be used immediately in any backtest. The tradeoff is some increased processing time and memory, but it could be worth it. Food for thought!
Maybe it would make sense to build an extension of the most common indicators that have this treatment, so they could be used immediately in any backtest. The tradeoff is some increased processing time and memory, but it could be worth it. Food for thought!
QUOTE:
Maybe it would make sense to build an extension of the most common indicators that have this treatment,...
Build a "generalized method" where one could pass any indicator as a function into it (with the Bars object) to get "extra" seed data outside of the specified Data Range. This method could then pass the Bars-sync'ed indicator back.
It really only makes sense to do this if you have a long-period indicator. And it would increase processing time. (I avoid long-period indicators in my strategies.)
I'm thinking of how to make it work in Building Blocks or drag and drop. A new Transformer Indicator could probably do this.
Many thanks to everybody for your help!
QUOTE:I don't believe this to be the case. When you use a longer period, the backtest — even the Buy and Hold backtest — starts at the bar of the longest period. Just compare your Start Date and the starting date of the Equity curve. If you're using a 250-period indicator, the Equity curve will start 1 year later, assuming Daily.
The problem with it is that it seems that many of the backtesting figures get diluted because of the longer period.
That said, I'm all for grabbing the unsynch'd complete series, creating the indicators on it, and then synchronizing to the chart history — at least for Daily+ by default. (I do this whenever coding my own strategies.) For intraday, however, that could create a problem for some providers, especially IB, in which you could be left waiting for a days for the full history to be downloaded.
Your Response
Post
Edit Post
Login is required