Removes, inverts, or randomizes trend in historic price data. Can be set up for removing bias from the parameters, the trades, the indicators, or the whole price curve.
Backtesting with detrended, inverted, or randomizied price curves is also a quick method to verify the robustness of a strategy. For removing trend, the curve or parts of it are "tilted" until the start and end prices have the same value.
The following flags can be set or combined with '+' or '|':
||Detrend trade results. This removes trend bias from a backtest while keeping the properties of the price curve.
||Detrend trade results and price functions; for detrending indicators and signals based on series generated with price() calls.
||Detrend the historical price data on loading. This also affects the displayed price curve in the chart.
||Invert the price curve by replacing prices with their reciprocal values. This reverses all trends in the curve, and can be used for a reality check of a system that is symmetric in long and short positions.
||Randomize the price curve by shuffling the price ticks. Keeps its overall trend and price range, but removes any short-term trends and correlations between the prices. Used for reality checks.
||Do not subscribe the asset and do not detect gaps or fix outliers on loading; for data files that contain no prices, but other types of data.
- If a trade strategy has a trend bias - f.i. when it buys more long than short positions - or vice versa, it is recommended to remove the trend from the price curve for generating strategy parameters. Otherwise, the simulation will be too optimistic when the price curve has an overall upwards trend, or too pessimistic when it has a downwards trend. For symmetric strategies that buy long and short positions under similar conditions and with the same strategy parameters, detrending is normally not necessary.
- Setting Detrend at TRADES or PRICES detrends the prices from the end of the lookback period until the end of the simulation resp. WFO training cycle. This has the effect that all WFO cycles are separately detrended in [Train] mode. Detrend = CURVE however detrends the price data file, but keeps the shorter-term trends of the WFO cycles.
- For detrending only strategy parameters or rules, but not the test results, set Detrend only in [Train] mode: if(Train) Detrend = CURVE;.
- For detrending only the prices of certain assets, set Detrend = CURVE before calling asset(), and set it to 0 afterwards.
- For detrending particular trades only, set Detrend = TRADES before entering the trade, and set Detrend = 0 afterwards. This is useful for portfolio systems that use both trend following and non-trend algorithms.
- For determining if a system's profit is caused by artifacts, temporarily set Detrend = SHUFFLE+CURVE and test. If the profit is caused by a real edge, it should then disappear.
- For determining if a system's profit is caused by randomness, temporarily set Detrend = INVERT and test. On symmetric assets such as currencies, the system should then still achieve profits.
- Detrended, inverted, or randomized price curves can be exported to a CSV file for further tests with R or similar statistical software.
- Reality checks using inverted or randomized price curves are mentioned on Financial Hacker | Development Process | Step 7: Reality Check.
if(Train) Detrend = CURVE; // detrend the whole price curve for training
mode, WFO, DataSlope, randomize
► latest version online