New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion Robust Montecarlo backtesting #2821
Comments
I think the idea of monte carlo simulations is clear to me - Example workflow (?)I think it should be pretty easy to introduce a
In the end, once the "data generation" process is in place, applying this to edge / hyperopt / whatever should be pretty straightforward. data generationNow i'm not certain about the data generation you propose. Even if you limit the scope of the shuffling (say 2 days) - with crypto pairs, we could have a major jump if the alst candle is used first (assuming a strong trend in one direction over that period of time). isn't a random walk (randomly generated series) also accomplishing the same thing? I mean, generating randomized timeseries is ~5-10 lines - you randomize returns, add a offset (so it's real prices, not a 0-centered timeseries) - add a random value as
Regarding this, i'd be especially interrested in how monte-carlo simulations are usually applied to backtesting ... but quickly searching, i've mainly found cases where the order of trades have been randomized - to identify potential huge drawdown risks and such... |
hi @xmatthias What I am referring to is a little more complex. Both methods are interesting, perhaps that of recombining the trades is a little more truthful and interesting for the crypto world. However, I found some theoretical books from where I studied money management, the robustness of a system, its repeatability, etc., where the montecarlo method applied to randomizing trades is also explained. in your opinion can it be an interesting addition to freqtrade? |
I clicked something wrong and closed the issue, sorry I'm not very practical with github for now |
I think shuffling will simply break the trends. Assume we have a currency pair with small volatility and smooth trend from 6000 to 8000 during the backtesting period. Shuffling will create strange data with no trend at all, with medium price of 7000 and very high variance of the data -- near candles will vary from 6000 to 8000. Why should we perform backtesting on these artificial data? The result of almost any strategy will be completely different comparing to backtesting on actual historical data and on the actual data on the near real timeranges... Do you have any paper, written by mathematicians/statisticians, describing this approach (shuffling) applied on time series of data? |
this is definitely a wrong assumption. Looking at binance (or kraken) charts this is happening very frequently. Very recent example (today):
That'll happen to everyone every now and then - nothing to do with being used to github or not, so don't worry!
I think so too. that's why i'm very doubtful that shuffling will work. Random seriesBy using a random series - not shuffled, but rebuild from the ground up - using some metrics from the original series (return mean, std, ... ) you can make sure that the strategy will also work in slightly different environments. Yes, trade results will be different - but that's the whole point - markets change all the time - so a good strategy (based on a good indicator) should ideally also work in different scenarios - or at least it should not fail completely (account blown). This can be accomplished by using good guards / stoplosses - and i think this is where MCS will be able to help. On the other hand - the Monte Carlo Simulation should also work be using the original candles - and reducing / increasing changes between candles - so instead of a 4% raise, it'll only be a 2% raise (obviously the same would apply in the other direction). To me big questionsNow the very big question is - what should be randomized / changed for the Monte Carlo Simulations.
|
Thinking about your considerations, I agree with you on the lack of consistency of new artificial data sets. For the moment I would think more about the part of randomizing the order of trades to understand the maximum drawdown (on this topic there are several documents also on the internet). forgive me if you wasted time looking for information on my first idea. |
Do not think so, it's a nice discussion issue... I just would like to see some math (science) behind Monte-Carlo approach and avoid inventing the wheels... |
well no, you didn't - we're discussing - and to me personally, using a (totally randomized) timeseries seems appealing. yes, it should show similar properties, but i think that can be accomplished by carefully designing the candle generator
we wouldn't - it's all virtual - no cars, or other wheel-driven vehicles will be harmed in the process 😆 |
btw, that's completely same reason why I personally left #2255 hanging... I have not read (recalled, I have had this in the university long time ago) the math. statistics stuff enough to make my conclusion on that yet... |
I guess we should invite @gaugau3000 to this discussion as well... 😉 |
I haven't read the entire topic but what i have implemented in my repo (hope provide more detailed answer after work) is Hope this help have a nice day. |
This time i have read all the thread :-) |
Is it possible to do walk forward analysis with freqtrade? https://youtu.be/WF03yaWq_PU?t=4555 ( The video is in Turkish, but there are subtitles.) |
It will depend on your definition of "walk forward" analysis. Now it's unclear what you'd "monte carlo simulate" - is it trade sequence? candle patterns? |
There is a way to do Montecarlo simulation that would completely avoid the issue of [shuffle vs. random gen candles]. It does necessitate the 2 following assumptions:
But if one were to get a "proper" R-distribution by running a backtest that would include all the main 6 market types: EDIT: EDIT2: |
Robust Montecarlo backtesting
Hi,
I noticed that a script to verify the robustness of a strategy through Montecarlo methods is not yet present in freqtrade.
The idea of stressing the trading system through a different market situation is a very useful tool to verify the effective efficiency of the strategy used.
What is Montecarlo simulation?
To get a little more into the technician and explain what Montecalro methods are, I'll give you a simple explanation.
The MonteCarlo Method is part of the family of nonparametric statistical methods. It is useful to overcome the computational problems related to exact tests (for example methods based on binomial distribution or calculation, which for large samples generate an excessive number of permutations). The method is used to make estimates through simulations. It is based on an algorithm that generates a series of uncorrelated numbers, which follow the probability distribution that is supposed to have the phenomenon to be investigated. The correlation between numbers is ensured by a chi-square test. " In practice it is possible through the Montecarlo method to generate pseudo-causal values that can be used as series of prices to test the trading system created (or take the prices already analyzed and recombine them in different order).
The results of the trading system applied to the generated series will indicate the robustness of the system. Also in this case we are considering strong hypotheses, we are in fact considering that the average and the variance of future prices is the same as that observed in the past (we have in fact spoken of pseudo-causal values). It is therefore understood that even when a trading system has passed the various robustness tests, you will never be sure that in the future the equity line is in line with that recorded with the historical data in the backtest.
The IDEA
The idea is to create a script that can recombine the candles of a specific period (2 days, 1 month, 1 year; this depends on the timeframe of the strategy) to create create new patterns and verify the behavior of the strategy.
If the strategy is good, the results should not vary as much, if instead the strategy has been hyper-optimized only for a particular market situation then the results will have a high variance.
It is important to verify the variance of the profit, but even more important is to verify the maximum drawdown obtained in the various scenarios.
Conclusion
I hope I have been clear enough and that I have done everything right, I hardly ever use github, if there are questions or curiosities ask me as well.
I should have some documents or links in reference to all this. I will try to find them in the next period.
thank you :)
The text was updated successfully, but these errors were encountered: