As others have said, "Average return is just one statistic". When trading, losses hit harder than wins. Go up 50% then down 50% and you're not even, you're down 25%. The degree of overestimation from this mean return -> "annualized return" calculation depends on what the returns distribution looks like.<p>Here's the calculation used in main.js line 77 applied to a very extreme unrealistic example. I simulated 253 days of return percentages from a uniform distribution between -5.5% and 5.6%, and then the actual total return percent, calculated in R<p><pre><code> set.seed(2020)
n <- 253
daily_gain <- runif(n, -.055, .056)
total_gain <- sum(daily_gain)
avg <- total_gain/n
annualizedReturn <- (1 + avg)^n -1
annualizedReturn
# [1] 0.2933685
prod(1 + daily_gain) - 1
# [1] 0.1324846
</code></pre>
Edit:<p>In reality the actual numbers are likely to be not nearly as different as this example. I chose uniformly distributed returns with a wide range to make the reason against this calculation very obvious. Here's an example return distribution where there's hardly any difference. Normal returns with average of 0.085% and standard deviation of .05 i.e. daily_gain <- rnorm(n, .085/100, .05/100) gives<p><pre><code> annualizedReturn
# 1] 0.2414539
prod(1 + daily_gain) - 1
# [1] 0.2414051
</code></pre>
For good measure here's one in the middle where your returns are normally distributed with an average of 0.35% and a sd of .2%, but then you have on average 10 bad days a year where returns are 5 percentage points lower than that distribution i.e. daily_gain <- rnorm(n, .35/100, .2/100) - rbinom(n, 1, 10/n)*.05 gives<p><pre><code> annualizedReturn
# [1] 0.2712024
prod(1 + daily_gain) - 1
# [1] 0.2490317</code></pre>
There are so many misconceptions on this thread about what makes a good quant trading strategy.<p>First of all, if you're shorting US equities and making 25% annually, that would be awesome. Heck, even being flat would be great because a strategy that is long SP500 could also short your equities and be delta-neutral and likely have a much lower volatility for the same return.<p>Second, so many people are mentioning commissions, trading fees, taxes and so on. Commissions and trading fees are much less than 1 basis point per trade if you use reputable brokerages. That would, at most, amount to a 1-2% in fees per year. Market impact matters but opening and closing auctions are very liquid and represent respectively more than 1% and 5% of the daily volume, probably even more for these kind of ETFs. Shorting fees are also quite small, in the range of 0-2% for liquid ETFs. If you don't hold positions overnight which is your case, you also don't pay to short!<p>Finally, here's what really matters. Returns by themselves don't matter. If you want a very high return strategy, you can short a long VIX ETF like VXX but every once in a while, you will be down more than a 100% ; it will bankrupt you if your available capital is less than the value of your short. You also need to look at your Sharpe ratio and maximum drawdown. Anyone somewhat experienced could tell you if the strategy is valid by having a look at plot of returns. If it's not too volatile, it could be a good strat.<p>Edit: addressing shorting fees
There's kind of a lot of missing pieces here:<p>* This is a simple strategy, which is fine, but also means you are not the only person who has noticed this. Why do you think this makes money? Is there some risk you are being compensated for, or is there some forced trading you're picking up the other side of, or something else?<p>* Which of the common equity factors (<a href="https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html" rel="nofollow">https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data...</a>) is your strategy exposed to, and by how much?<p>* What are the basic return statistics of the strategy, like Sharpe and drawdown?<p>* How sensitive is the strategy to parameter variations? What if you sell the second best ETF instead of the best? What if you sell on day n+2 instead of n+1? What if you buy the worst ETF?<p>And about a dozen other things that you should look into before you actually try trading.
Congrats. While it can be exciting to come up with a profitable algorithm, publicizing a mean reversion algorithm is counterproductive if you intended to make any money with it. The returns here are low enough that it could stay under the radar for a while, but all the same.<p>Some other metrics to measure your performance are drawdown, best month/worst month (to see if a small number of events account for the majority of returns), and Sharpe ratio. As other commenters said, try backtesting with fees/slippage. Even if there aren't fees now, you should include fees at points in history when there were higher fees. HFT's have been forced to tighten their spreads as retail traders have become more liquid with lower/nonexistent fees, so that will affect any mean reversion strategy being tested across fee change periods.<p>I do like the idea of spot mean reverting on large indices. Takes a lot of risk out of it (while a company can tank overnight, any decently weighted index will lack that volatility).
This is a simple trading algorithm I discovered that operates on the Vanguard sector ETFs. This backdating algorithm provides on average a return of ~0.0878% for each trading day, or ~24.85% annualized return assuming 253 trading days per year.<p>## The Algorithm<p>This algorithm is really simple.<p>1. On day `n`, determine which ETF gave the highest return<p>2. On day `n+1`, short sell the previous day's highest performing ETF at market open and close your short position at market close.<p>Because this algorithm operates on Vanguard's 11 Sector ETFs, it is resilient against the volatility of individual stocks.<p>### Caution<p>Hindsight is 20/20 and because this is a backdating algorithm, similar results are not guaranteed in the future. Use at your own risk.
Pretty smart. Tempt the reader with a 'killer' but incomplete statrgy and make us do all the work to test it and find the flaws so you don't have to. I am sure this is way too good to be true.
Average return is just one statistic. You can earn an arbitrarily high daily average return by taking an ordinary strategy (e.g. buy and hold the S&P 500) and applying large amounts of leverage. Returns will be great until the strategy blows up.<p>What was the volatility of this strategy? When backtested on the historical data, what was the maximum drawdown? What happens when trading costs or slippage (buying at the ask, selling at the bid) are modeled additionally?<p>252 trading days times two trades per day (short sell at open, buy to close at close) is a lot of trades, and execution quality will be very important.<p>Does this strategy hold up with week-long holding times?
This is mean reversion, right? Essentially fading market volatility. I recall an article on Bloomberg about a quant fund using VIX ETNs to implement something similar. Gradually adding short positions as volatility rises. Knowing it will dissipate once turmoil subsides. My recommendation: try entering a trading contest on Alpaca ;)<p><a href="https://alpaca.markets/data" rel="nofollow">https://alpaca.markets/data</a>
“In theory, there is no difference between theory and practice. In practice, there is. “<p>–Richard P. Feynman<p>Wise words for anyone wishing to try out an algorithm on Wall Street.
Many moons ago I ran a site called ETF Timing that automated technical analysis against ETFs.<p>There is so much wrong with this I don't know where to start. But this seems common these days, I think it's due to the influx of inexperienced traders who have no proper statistical background.<p>I'll let ryanmonroe point out the first glaring problem with these types of simple "algorithms":<p><a href="https://news.ycombinator.com/item?id=27415821" rel="nofollow">https://news.ycombinator.com/item?id=27415821</a>
As previously said, this is probably just mean reversion. It’s a commonly used signal that appears to print money all the time, until you take transaction costs into account. If you want to have even more fun, try back testing this same idea on intraday data. Your performance should look phenomenal, and your Sharpe ratio should be well above 10.
Unrelated, but it's surprisingly hard to get backtesting right.<p>I found a bug[1] in a popular (4000 star) stock forecasting model on github where future knowledge subtly leaks into the training data. People seem to keep using the project though!<p>[1] <a href="https://github.com/huseinzol05/Stock-Prediction-Models/issues/61" rel="nofollow">https://github.com/huseinzol05/Stock-Prediction-Models/issue...</a>
I’m amused that a node app was used to do this rather than a Google sheet. The =GOOGLEFINANCE function is super handy for building backdated simulations.
It is great to see a trading strategy that actually make gains while short-selling, during mostly bull markets. "Everybody looks like a genius during a bull market". Short-selling is something else...
What software do you use to implement algorithms like this? Do you have to write your own python/other scripts and interact with trading API's for whatever service you use, or are there nice pre-written open source trading algorithms that make building stuff like this easier.
This is a good time to note that it is incredibly easy to overestimate your ability to determine a trend based on historical data and also incredibly easy to underestimate the likelihood of a never-before-seen occurrence. “The turkey that gets fed well every day relies on that trend continuing and never sees the week before Thanksgiving coming.”
This doesn't take into account taxes. If you are consistently profitable on a yearly basis you're expected to pay 100% of last year's capital gains split into Estimated Taxes every quarter going forward. That eats into your return if you're reinvesting profits.
Last year I had a bunch of cash right as Covid hit so I bought into a few indexes as well as some Energy and Tech stocks. My annual return on these assets was 48%. I don't expect anywhere near that next year though. I just so happened to have bought at the bottom of the market. I probably could have done a return on the order of 100% or more had I researched a bit deeper. I took a gamble on healthcare stocks that just didn't pan out. All that was was just that- speculation and gambling.
I like those naive way to test trading bot, you can check my attempt here, but mine doesn't work :)
<a href="https://github.com/dezmou/CryptoGPU" rel="nofollow">https://github.com/dezmou/CryptoGPU</a>
My impression is that the idea that the market average beats most strategies in the long term hides the fact that some strategies perform horribly, and some perform great in the long term, but many of the strategies that perform horribly look good in the short term, and distinguishing between the strategies that are attractive in the short term but horrible in the longer term, and those strategies that perform well in the longer term is a very hard problem.<p>Of course, this might be a rationalization of me not wanting to spend the time and effort to construct an effective trading strategy.
var total = 0;<p><pre><code> for (var i = 0; i < performance.length; i++) {
total += performance[i];
}
var avg = total / performance.length;
var tradingDays = performance.length;
var annualizedReturn = (1 + avg) \* 253 - 1;
</code></pre>
}<p>I think this math is wrong. You cant just add the daily performances up to get the total return. unless im missing something.<p>Though seems like your "cash" variable is correctly calculated.
Clearly the author does not have real world experience with this algorithm.<p>If so, it would be clear that buying anything at the opening price is not easy.
My golf betting algorithm averages just over 20% BUT It's so consistent that by steadily increasing the stakes to take advantage of compound interest it hits ROIs of over 1000%<p>Check it out: <a href="https://www.golfforecast.co.uk/profitgraphs" rel="nofollow">https://www.golfforecast.co.uk/profitgraphs</a>
So let’s assume the trick works and everyone catches on. Surely we can’t <i>all</i> get 25%<p>And that’s the problem with any successful algorithm except buy and hold value investing. The latter being hard because it requires doing little, and nobody believes that which requires the least effort to be the best.
Most mean reversion systems have a high win rate. But the profits from wins are usually small and a losses are large. You have a hard time avoiding losses because you have to let mean reversion trades run and you can't have small stop loss settings.
Over what time period was the 24.85% measured? This seems like it would do better during time periods where stock prices are volatile and/or not increasing, so if the returns were measured over the last year, then results could be misleading.
Sounds promising if true, and it's cool that you're working on this. What happens when you paper trade with it? Test it going forward and see if it still works, please make another post if you do!
"Caution
Hindsight is 20/20 and because this is a backdating algorithm, similar results are not guaranteed in the future. Use at your own risk."<p>You don't say...
You did not discover a trading algorithm that returns ~24.85% annually.<p>You massaged an algorithm until it produced a 24.85% annual return training on historical data.<p>Come back when you are ready to claim you have made ~24.85% per year with an algorithm you created 5-10 years ago.<p>Deny it, Downvote it: Destiny still arrives.