/r/algotrading
A place for redditors to discuss quantitative trading, statistical methods, econometrics, programming, implementation, automated strategies, and bounce ideas off each other for constructive criticism. Feel free to submit papers/links of things you find interesting.
/r/AlgoTrading place for redditors to discuss quantitative trading, statistical methods, econometrics, programming, implementation, automated strategies and to bounce ideas off each other for constructive criticism. Feel free to submit papers/links of things you find interesting.
This sub is not for the promotion of your blog, youtube, channel, or firm.
*THIS DOES NOT CONSTITUTE INVESTMENT ADVICE, USE AT OWN RISK*
*SEARCH THE SUB/GOOGLE/STACK OVERFLOW BEFORE ASKING QUESTIONS FOUND ON THE FRONTPAGE OF THE ABOVE WILL BE REMOVED*
Good places to start with code examples:
STRATEGY
Big-Intro to quantstrat and trading systems
R & quanstrat video tutorial
portfolio optimization
Great blog with more advanced code and ideas from the "systematic investor" note: code here does not follow standard R conventions
Blog here with strategy examples from Ilya Kipnis
quantivity paper feed
How to learn algortihmic trading
Strategy books thread
Quantopian Lecture Series
How to get historical data for free
Daily Bar data for Stocks
Tick level Forex Data
Historical Bar Data for Crypto Currencies - Binance
Historical Bar Data for Crypto Currencies - BitMEX
Charts with live feeds for global exchanges
TradingView HTML5/web based charts
Math/Stats/Machine Learning
Introduction to Statistical Learning with applications in R
Elements of Statistical Learning
Production Systems
aleph-null: open source python ib
quick-fix
node.js to ib api
subreddit thread on systems
Paper Feeds
Quant news feed
Quantocracy blog feed
Live Chat Rooms
Official Discord: Official Discord for /r/AlgoTrading
R Language in Finance Discord: Discord for R Programming for Financial Applications
R Language in Finance Discord IRC Version sync'd to discord irc.libera.chat #r-finance
Book Recommendations List of recommended books on Algo Trading
Do's:
Don'ts:
FAQ's:
A: Read the sidebar, if you have a precise specific question please google it and should you not find the answer then you can ask here.
Q: I am a student and want to know what courses to study to get into algo trading?
A: Algotrading is at the intersection of statistics/computer science/machine learning/mathematics/finance/economics.
Q: Where should I apply for a job?
A: /r/financialcareers for that
Q: I have bug ABC with language XYZ ?
A: http://quant.stackexchange.com/ or http://http://stackoverflow.com/
If you get spam filtered, message the mods and we will review and unblock as required.
/r/algotrading
I’m a 60 year-old trader who is fairly proficient using Excel, but have no working knowledge of Python or how to use API keys to download data. Even though I don’t use algos to implement my trades, all of my trading strategies are systematic, with trading signals provided by algorithms that I have developed, hence I’m not an algo trader in the true sense of the word. That being said, here is my dilemma: up until yesterday, I was able to download historical data (for my needs, both daily & weekly OHLC) straight from Yahoo Finance. As of last night, Yahoo Finance is now charging approximately $500/year to have a Premium membership in order to download historical data. I’m fine doing that if need be, but was wondering if anyone in this community may have alternative methods for me to be able to continue to download the data that I need (preferably straight into a CSV file as opposed to a text file so I don’t have to waste time converting it manually) for either free or cheaper than Yahoo. If I need to learn to become proficient in using an API key to do so, does anyone have any suggestions on where I might be able to learn the necessary skills in order to accomplish this? Thank you in advance for any guidance you may be able to share.
THIS IS NOT A SOLICITATION. Please don't DM
That said. Would there be a market for automating and back/forward testing strategies for traders/investors that aren't quite as technically savvy?
No crazy promises of profits or anything.
Just: You give us the play by play of your strategy. And we will automate it for you?
My gut wants to say there would be. But I guess... my other gut... it says that if someone had a profitable strategy they wanted to automate. They wouldn't just give it to some nerd with every minute detail to their strategy.
Idk. Was taking a poop and the idea popped into my head. Figured I'd throw it out there and see if a legitimate discussion might start.
So... opinions?
Edit: so the collective opinion is that this can be a valuable business proposition.
Some guys are already doing it There some.bug boy companies offer8ng these services. And the AI/algo prop idea isn't all that bad.
The dude that said "Google it" what's your address. I wanna send you the biggest and prettiest, pink, hello Kitty dildo.. hmu.
Everyone else.. thank you! This is why I wanted to communicate rather than search.
I have no intentions of doing this anytime soon(if ever) but now I know it is a possibility and will be given some mental real estate.
I really appreciate the input What some of you are doing is really freaking cool!!
Where can I get the calendar history for the past 2 years using an API?
Given crypto markets are decentralized, it seems like these two options provide data from several different exchanges. Does anyone have experience with either one, or an alternative? I’m looking for order book snapshots, or potentially full order book updates.
Hello guys, i wanted to take your opinion on what topic should i study in my masters degree, a little background about me i am a computer engineering fresh grad and has some experience in ML from my uni courses and my bachelor thesis. also, i dabbled in stock trading, studying technical analysis, trends and company financials.
Me personally i want to research building a ML model which utilizes technical analysis indicators, stock data etc.. to predict whether the stock will go up or down (studying maybe different trading time frames), also there are some suggestions of utilizing NLP, i have no background in it so it would be much harder (which i dont mind ) but, whenever i search on predicting stock market using ML or any predictive way they say its impossible due to its random nature volatility, its like gambling and so on, even with complex ML models.
So, what do you think of a research topic like this, is it worth it or not?
I am also open to your suggestions and experience, Thank You.
So I developed a seemingly reliable options trading algorithm (largely selling mispriced puts). However, it only finds these mispriced options about once every two or three weeks.
While some of the issue is that these mispriced options may exist infrequently like unicorns, I think a bigger problem is that I cannot efficiently search the entire universe of option chains. There doesn't seem to be an API where one can quickly pull every securities' option chain. I have to tell the API which underlying security I want information about, then traverse the resulting chain by strike price and expiry date.
It's very cumbersome, so I'm only selecting about 200 securities each day that I think may have mispriced options. It's all very inefficient, sometimes my script times out, sometimes I hit the API rate limit.
Any suggestions on how I can search more options at once more quickly and without hitting API rate limits?
Is there an API where you can search options (like a finviz for options)?
Thanks!
Does anyone have any recommendations for what hardware to use to run a trading algorithm, as well as what coding language to use to run it? I’m looking to forward test strategies, but I figure I need some hardware to have it run throughout the day rather than keeping my computer on permanently.
I’ve been messing around trying to develop strategies in Python, but I’m not sure if that’s going to work for forward testing or potentially live trading. I’m pretty good with Python, so are there any drawbacks to using it for live trading?
Lastly, do I need to use a specific broker, or do most brokers have an API that allows you to run an algorithm with your accounts?
Overall, any recommendations on how to go from backtesting a strategy to actually implementing it would be greatly appreciated.
I have been limping along with tradestation for about year. SQX initially looked promising, but there have to be better tools available?
Edit: Anybody out there?
I've a swing strategy that holds trades for multiple months. The futures that I'm trading have a expiry of 3 months.
Since my strategy can hold a trade for more than 3 months, it needs to rollover the contract at each expiry.
Rollover usually comes at a cost because the next month contract trades at a higher price than the expiring contract - and the strategy must take this into account to report the correct PnL.
I can find stock futures data at multiple places, but this data is always back adjusted.
Because of the back-adjustment, it seems that the rollover cost is effectively lost from the data.
I looked online, and I am unable to find any place that shows the historical rollover costs for the futures!
Hello, I'm testing another strategy - this time a reversal type of setup with minimal rules, making it easy to automate.
Concept:
Strategy concept is quite simple: If today’s candle has a lower low AND and lower high than yesterday’s candle, then it indicates market weakness. Doesn’t matter if the candle itself is red or green (more on this later). If the next day breaks above this candle, then it may indicate a short or long term reversal.
Setup steps are:
Step 1: After the market has closed, check if today’s candle had a lower low AND a lower high than yesterday.
Step 2: Place BUY order at the high waiting for a reversal
Step 3: If the next day triggers the buy order, then hold until the end of the day and exit at (or as close as possible to) the day’s close.
Analysis
To test this theory I ran a backtest in python over 20 years of S&P500 data, from 2000 to 2020. I also tested a buy and hold strategy to give me a benchmark to compare with. This is the resulting equity chart:
Results
Going by the equity chart, the strategy seemed to perform really well, not only did it outperform buy and hold, it was also quite steady and consistent, but it was when I looked in detail at the metrics that the strategy really stood out - see table below.
Improvements
This gave me a solid start point, so then I tested two variations:
Variation 1: “Down reversal”: Rules same as above, BUT the candle must be red. Reasoning for this is that it indicates even more significant market weakness.
Variation 2: “Momentum”: Instead of looking for a lower low and lower high, I check for a higher low and higher high. Then enter at the break of that high. The reasoning here is to check whether this can be traded as a momentum breakout
The chart below shows the result of the updated test.
Results
At first glance, it looks like not much has changed. The reversal strategy is still the best and the two new variations are good, not great. But again, the equity chart doesn’t show the full picture. The table below shows the same set of metrics as before, but now it includes all 4 tested methods.
Going by the equity chart, the “Down reversal” strategy barely outperformed buy and hold, but the metrics show why. It was only in the market 9% of the time. It also had the lowest drawdown out of all of the tested methods. This strategy generates the fewest trade signals, but the ones that it does generate tend to be higher quality and more profitable. And when looking at the blended metric of “return by exposure/drawdown”, this strategy outperforms the rest.
EDIT: Added "out of sample testing" section below on 04/09:
Out of Sample Testing
All of the results in the sections above were done on the "in-sample" data from 2000 to 2020. I then ran the test from 2020 to today to show the results of the "out-of-sample" test. Equity chart below
The equity chart only shows half the picture though, the metrics below show that the system performance has held on well, especially the drawdown, which has been minimal considering the market shocks over the last 4 years:
Overfitting
When testing on historic data, it is easy to introduce biases and fit the strategy to the data. These are some steps I took to limit this:
Caveats:
The results look really good to me, but there are some things that I did not account for in the backtest:
Code
The code for this backtest can be found on my github: https://github.com/russs123/reversal_strategy
More info
This post is even longer than my previous backtest posts, so for a more detailed explanation I have linked a vide below. In that video I explain the setup steps, show a few examples of trades, and explain my code. So if you want to find out more or learn how to tweak the parameters of the system to test other indices and other markets, then take a look at the video here:
Video: https://youtu.be/-FYu_1e_kIA
What do you all think about these results? Does anyone have experience trading a similar reversal strategy?
Looking forward to some constructive discussions :)
Like the title says, I'm looking for historical consensus revenue and EPS forecasts for US stocks that doesn't cost an arm and a leg. "TrueBeats" on QuantConnect wants $825/year, and Zacks wants $250/year and I'm not sure the EPS info is even available at that tier.
I'm willing to do some programming to scrape and store, or pay maybe $100 for a one-time dump for data from approx. 2021 through 2023.
Any suggestions where to look?
Does anyone know what Schwab bases their historical data off of? I've been doing some testing with the Schwab API and have noticed that some of their historical data doesn't seem in line with other sources (Alpaca, Tradingview) and is sometimes off by several dollars. I know this could potentially be due to the source of data for each system. Trying to narrow down where these discrepencies are coming from
Total noob here. I was trying to compute the NAV of SPY.(I saw the ticker on ToS, but it gets updated only once a day and I wanted to get more updated results). I was thinking of getting the NAV by getting the value of all the holdings that is updated daily and updating the value based on the latest stock price. Is this a reasonable apporach?
This also leads me to the next question: what's the frequency with which the number of shares held by SPY change?
Would like to brainstorm on the optimisation techniques for algo trading.
Disclaimer I run algo trading on technical indicators trading intraday.
Things I hv found
Remove hard stop loss based on % or so, use only indicator to stop.
Use SD(ATR) to filter out non trending days
If you trade non US products, consider not to open a trade in non continuous trading session before US market open
I am testing a strategy in python and finding the optimal parameters for the indicators I will be using and wanted to get an opinion on how far back I need to go to backtest this. I will be trading on a 3 min time frame, and I initially started to backtest with 3 years' worth of data, but do I need to go further back 5 years, 8, 10? Markets change repeatedly and my conclusions was anything past 3 years is worthless.
I am providing my reflections on this industry after several years of study, experimentation, and contemplation. These are personal opinions that may or may not be shared by others.
The dream of being able to dominate the markets is something that many people aspire to, but unfortunately, it is very difficult because price formation is a complex system influenced by a multitude of dynamics. Price formation is a deterministic system, as there is no randomness, and every micro or macro movement can be explained by a multitude of different dynamics. Humans, therefore, believe they can create a trading system or have a systematic approach to dominate the markets precisely because they see determinism rather than randomness.
When conducting many advanced experiments, one realizes that determinism exists and can even discover some "alpha". However, the problem arises when trying to exploit this alpha because moments of randomness will inevitably occur, even within the law of large numbers. But this is not true randomness; it's a system that becomes too complex. The second problem is that it is not possible to dominate certain decisive dynamics that influence price formation. I'm not saying it's impossible, because in simpler systems, such as the price formation of individual stocks or commodity futures, it is still possible to have some margin of predictability if you can understand when certain decisive dynamics will make a difference. However, these are few operations per year, and in this case, you need to be an "outstanding" analyst.
What makes predictions impossible, therefore, is the system being "too" complex. For example, an earthquake can be predicted with 100% accuracy within certain time windows if one has omniscient knowledge and data. Humans do not yet possess this omniscient knowledge, and thus they cannot know which and how certain dynamics influence earthquakes (although many dynamics that may seem esoteric are currently under study). The same goes for data. Having complete data on the subsoil, including millions of drill cores, would be impossible. This is why precursor signals are widely used in earthquakes, but in this case, the problem is false signals. So far, humans have only taken precautions once, in China, because the precursor signals were very extreme, which saved many lives. Unfortunately, most powerful earthquakes have no precursor signals, and even if there were some, they would likely be false alarms.
Thus, earthquakes and weather are easier to predict because the dynamics are fewer, and there is more direct control, which is not possible in the financial sector. Of course, the further ahead you go in time, the more complicated it becomes, just like climatology, which studies the weather months, years, decades, and centuries in advance. But even in this case, predictions become detrimental because, once again, humans do not yet have the necessary knowledge, and a small dynamic of which we are unaware can "influence" and render long-term predictions incorrect. Here we see chaos theory in action, which teaches us the impossibility of long-term predictions.
The companies that profit in this sector are relatively few. Those that earn tens of billions (like rentec, tgs, quadrature) are equally few as those who earn "less" (like tower, jump, tradebot). Those who earn less focus on execution on behalf of clients, latency arbitrage, and high-frequency statistical arbitrage. In recent years, markets have improved, including microstructure and executions, so those who used to profit from latency arbitrage now "earn" much less. Statistical arbitrage exploits the many deterministic patterns that form during price formation due to attractors-repulsors caused by certain dynamics, creating small, predictable windows (difficult to exploit and with few crumbs). Given the competition and general improvement of operators, profit margins are now low, and obviously, this way, one cannot earn tens of billions per year.
What rentec, tgs, quadrature, and a few others do that allows them to earn so much is providing liquidity, and they do this on a probabilistic level, playing heavily at the portfolio level. Their activity creates a deterministic footprint (as much as possible), allowing them to absorb the losses of all participants because, simply, all players are losers. These companies likely observed a "Quant Quake 2" occurring in the second week of September 2023, which, however, was not reported in the financial news, possibly because it was noticed only by certain types of market participants.
Is it said that 90% lose and the rest win? Do you want to delude yourself into being in the 10%? Statistics can be twisted and turned to say whatever you want. These statistics are wrong because if you analyze them thoroughly, you'll see that there are no winners, because those who do a lot of trading lose, while those who make 1-2 trades that happen to be lucky then enter the statistics as winners, and in some cases, the same goes for those who don't trade at all, because they enter the "non-loser" category. These statistics are therefore skewed and don't tell the truth. Years ago, a trade magazine reported that only 1 "trader" out of 200 earns as much as an employee, while 1 in 50,000 becomes a millionaire. It is thus clear that it's better to enter other sectors or find other hobbies.
Let's look at some singularities:
Warren Buffett can be considered a super-manager because the investments he makes bring significant changes to companies, and therefore he will influence price formation.
George Soros can be considered a geopolitical analyst with great reading ability, so he makes few targeted trades if he believes that decisive dynamics will influence prices in his favor.
Ray Dalio with Pure Alpha, being a hedge fund, has greater flexibility, but the strong point of this company is its tentacular connections at high levels, so it can be considered a macro-level insider trading fund. They operate with information not available to others.
Therefore, it is useless to delude oneself; it is a too complex system, and every trade you make is wrong, and the less you move, the better. Even the famous hedges should be avoided because, in the long run, you always lose, and the losses will always go into the pockets of the large liquidity providers. There is no chance without total knowledge, supreme-level data, and direct control of decisive dynamics that influence price formation.
The advice can be to invest long-term by letting professionals manage it, avoiding speculative trades, hedging, and stock picking, and thus moving as little as possible.
In the end, it can be said that there is no chance unless you are an exceptional manager, analyst, mathematician-physicist with supercomputers playing at a probabilistic level, or an IT specialist exploiting latency and statistical arbitrage (where there are now only crumbs left in exchange for significant investments). Everything else is just an illusion. The system is too complex, so it's better to find other hobbies.
Hoping to get some feedback on an approach for processing Text Based Data
I'm pretty new to trading. I've created a Jupyter notebook to test out an idea I had to process the Google Trends newsletter and see if there was any correlation to the movement of the S&P 500 (via SPY ETF).
My idea was:
I've also created a similar model but instead of embeddings, vectorized the words and applied a TfidTransformer to extract the most relevant word/char vectors. To evaluate both models I've created a a daily cron process since I wasn't able to find back dated Google Trends newletters.
With more data the Vectorized model actually ended up performing better (while with less data embedding we’re better). I thought embedding a would’ve done a better job of extracting context as more data was incorporated.
As I'm relatively new to trading, I was curious if the approach for trying to guess the next day's high and low made sense or if there was some kind of more standard indicator that I could be using?
Hello there !
I spent a bit of time building a platform to run backtests and forwardtests (and one day live ones).
But for now, I'm just doing my strategies through a console, which is not ideal when you want to analyse things.
So, it already took a lot of times for doing my own engine (which was much more for the fun part, than for the real utility of it), so I would prefer not to reinvent the wheel on the frontside and use whatever is already available.
What are you using and/or what would you use ?
I have several ideas:
Extract data and display them with a bunch of Python scripts to run analysis
Use an existing front-end (Is it possible to use TradingView with a custom data feed for anything ?)
Any other idea ?
Thanks a lot ! :)
Is there any broker that has API access to a health savings account? Particularly, can one trade options?
If you didn't know, an HSA is triple tax advantaged. (I just learned that part this week)
I am only half kidding:
This will take you an hour on Fridays, and you can larp to be a hedge fund manager.
The implicit assumptions are:
I run a version of this trade, and it's been good.
Shoot holes in this and tear it apart - would love to hear your harshest criticisms.
PS: For the hotheats, algotrading means that the trades are formulated by an algorithm, and the stuff spelled out above is an algorithm coded in English. No need to code in another language, or automate, in order to qualify as algo. just so we are clear and we get that out of the way.
EDIT: For the curious, the randomizer spit out these stocks this week. You can find the full list of weeklys here: https://www.cboe.com/available\_weeklys/. No position yet, but I am sticking to it, small part of the account obviously.
|| || |Ticker|Name| |DBX|DROPBOX INC CL A| |JPM|JPMORGAN CHASE & CO. COM| |PEP|PEPSICO INC COM| |MDLZ|MONDELEZ INTL INC CL A| |TSCO|TRACTOR SUPPLY CO COM| |HRL|HORMEL FOODS CORP COM| |NTAP|NETAPP INC COM| |JBLU|JETBLUE AWYS CORP COM| |PBI|PITNEY BOWES INC COM| |RDFN|REDFIN CORP COM|
EDIT2: I have put verticals on all but PEP which had horrible pricing today and I could not get anywhere close to even. I also have a 560/561 long call spread on SPY.
EDIT3: 231 people saved/shared the link and will be running random stocks against SPY - let's get it ; ) In all seriousness, thanks for the feedback and don't literally do this at home, as you will probably lose money. I run this strategy with a small amount of my trading capital, and with certain refinements, so do your own research, make your own trades, keep your trades small, and trade carefully. Cheers!
Hi all, I currently have a kinetick data feed subscription which gives me 2 years worth of historical bar data for most futures (which is what im trying to backtest on). I want to forward test on samples outside of a 2 year range and also just have a larger sample size.
I’m looking for the best source of data to get around 5-10 years of bar data (I don’t need tick data), was wondering if people are buying data from a source other than kinetick for cheaper? Also if market replay data is available to download in bulk or not
Thanks in advance
tvdatafeed is a python package that links to the trading view websocket and grabs data. it's a neat project. I looked through its github, searched the web, and looked through stack overflow. I couldn't find the answer in my online search. does tvdatafeed return raw or adjusted data? I'm hoping someone with better networking, maybe developer tool skills, or just general sleuthing can figure this out. I'm trying to get my forward-testing straightened out. Happy algo-trading!
Are you working out or a shared codebase source, or working based on your own specs? Doesn’t have to be full on scrum ceremony. Are you the main stakeholders of this codebase? Running your money, or someone else’s? Very curious how the many facets of this business impact the SDLC of a project
I’m dealing with a lot of connection issues from my broker on weekends and it’s disrupting my bracket orders which are sitting on my local PC. Leaving me with a naked position on Sunday night when the futures market opens back up.
I understand ninjatrader allow traders to enable “server side orders” for traders who use their brokerage but it’s only for discretionary traders who use an “ATM Strategy” not for system traders.
Is there a platform and broker combo that’s allows traders to have server side systems running and keep their system functioning? Meaning a trailing stop or any other functionality according to their script would still work and not just keep a stop loss fixed at a certain price?
I need a textbook recommendation.
I'm looking for a textbook that covers the general knowledge you need to handle financial data like:
security id system like CUSIP, ISIN, CIK, TICKER, etc
financial database architecture to handle data like adjusted close price
caveats when handling financial time series data covering topics like point-in-time, filing date, etc
data preprocessing tips like outlier detection, winsorization in the context of finance domain
Handling data pipeline for finance, DB(MS) for this.
Other topics like DMA execution, order book data handling, etc
Is there any good textbook that covers topics like these?
I have seem many quant textbooks on factors and strategies or even system trading but I've never seen a book dedicated solely to the financial data.
Any good book I can look into?
Hi all,
I’ve written up an algo that is doing very well live, trading futures. I’m no quant and am unexperienced with options. I’m just curious whether incorporating options could raise my RR per trade. If so, how might you approach this?
Some potentially relevant information: Trades currently take about 1-5 minutes to hit TP/SL, longer ones taking being between 5-15 minutes. RR is fixed at 1:1. I could de-leverage a bit and get average trade duration up to 15-30 minutes, but would have less trades during the average day.
Thanks! :)
Don't even have words for this
I came across this trading strategy quite a while ago, and decided to revisit it and do some backtesting, with impressive results, so I wanted to share it and see if there's anything I missed or any improvements that can be made to it.
Concept:
Strategy concept is quite simple: If the day's close is near the bottom of the range, the next day is more likely to be an upwards move.
Setup steps are:
Step 1: Calculate the current day's range (Range = High - Low)
Step 2: Calculate the "close distance", i.e. distance between the close and the low (Dist = Close - Low)
Step 3: Convert the "close distance" from step 2 into a percentage ([Dist / Range] * 100)
This close distance percentage number tells you how near the close is to the bottom of the day's range.
Analysis:
To verify the concept, I ran a test in python on 20 years worth of S&P 500 data. I tested a range of distances between the close and the low and measured the probability of the next day being an upwards move.
This is the result. The x axis is the close distance percentage from 5 to 100%. The y axis is the win rate. The horizontal orange line is the benchmark "buy and hold strategy" and the light blue line is the strategy line.
Close distance VS win percentage
What this shows is that as the "close distance percentage" decreases, the win rate increases.
Backtest:
I then took this further into an actual backtest, using the same 20 years of S&P500 data. To keep the backtest simple, I defined a threshold of 20% that the "close distance" has to be below.
EDITED 25/08: In addition to the signal above, the backtest checks that the day's range is greater than 10 points. This filters out the very small days where the close is near the low, but the range is so small that it doesn't constitute a proper "dip". I chose 10 as a quick filter, but going forward with this backtest, it would be more useful to calculate this value from the average range of the previous few days
If both conditions are met, then that's a signal to go long so I buy at the close of that day and exit at the close of the next day. I also backtested a buy and hold strategy to compare against and these are the results:
Balance over time. Cyan is buy and hold, green is buy dips strategy
Benchmark vs strategy metrics.
The results are quite positive. Not only does the strategy beat buy and hold, it also comes out with a lower drawdown, protecting the capital better. It is also only in the market 19% of the time, so the money is available the rest of the time to be used on other strategies.
Overfitting
There is always a risk of overfitting with this kind of backtest, so one additional step I took was to apply this same backtest across a few other indices. In total I ran this on the S&P, Dow Jones, Nasdaq composite, Russel and Nikkei. The results below show the comparison between the buy and hold (Blue) and the strategy (yellow), showing that the strategy outperformed in every test.
Caveats
While the results look promising, there are a few things to consider.
Final thoughts
This definitely seems to have potential so it's a strategy that I would be keen to test on live data with a demo account for a few months. This will give a much better idea of the performance and whether there is indeed an edge.
Does anyone have experience with a strategy like this or with buying dips in general?
More Info
This post is long enough as it is, so for a more detailed explanation I have linked the code and a video below:
Code is here on GitHub: https://github.com/russs123/Buy-The-Dip/tree/main
Video explaining the strategy, code and backtest here: https://youtu.be/rhjf6PCtSWw