TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: I discovered a trading algorithm that returns ~24.85% annually

249 pointsby Kibaealmost 4 years ago

36 comments

ryanmonroealmost 4 years ago
As others have said, &quot;Average return is just one statistic&quot;. When trading, losses hit harder than wins. Go up 50% then down 50% and you&#x27;re not even, you&#x27;re down 25%. The degree of overestimation from this mean return -&gt; &quot;annualized return&quot; calculation depends on what the returns distribution looks like.<p>Here&#x27;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 &lt;- 253 daily_gain &lt;- runif(n, -.055, .056) total_gain &lt;- sum(daily_gain) avg &lt;- total_gain&#x2F;n annualizedReturn &lt;- (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&#x27;s an example return distribution where there&#x27;s hardly any difference. Normal returns with average of 0.085% and standard deviation of .05 i.e. daily_gain &lt;- rnorm(n, .085&#x2F;100, .05&#x2F;100) gives<p><pre><code> annualizedReturn # 1] 0.2414539 prod(1 + daily_gain) - 1 # [1] 0.2414051 </code></pre> For good measure here&#x27;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 &lt;- rnorm(n, .35&#x2F;100, .2&#x2F;100) - rbinom(n, 1, 10&#x2F;n)*.05 gives<p><pre><code> annualizedReturn # [1] 0.2712024 prod(1 + daily_gain) - 1 # [1] 0.2490317</code></pre>
评论 #27417799 未加载
评论 #27415978 未加载
评论 #27416879 未加载
评论 #27424345 未加载
评论 #27416016 未加载
uchaalmost 4 years ago
There are so many misconceptions on this thread about what makes a good quant trading strategy.<p>First of all, if you&#x27;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&#x27;t hold positions overnight which is your case, you also don&#x27;t pay to short!<p>Finally, here&#x27;s what really matters. Returns by themselves don&#x27;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&#x27;s not too volatile, it could be a good strat.<p>Edit: addressing shorting fees
评论 #27415792 未加载
评论 #27415904 未加载
hazardalmost 4 years ago
There&#x27;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&#x27;re picking up the other side of, or something else?<p>* Which of the common equity factors (<a href="https:&#x2F;&#x2F;mba.tuck.dartmouth.edu&#x2F;pages&#x2F;faculty&#x2F;ken.french&#x2F;data_library.html" rel="nofollow">https:&#x2F;&#x2F;mba.tuck.dartmouth.edu&#x2F;pages&#x2F;faculty&#x2F;ken.french&#x2F;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.
lend000almost 4 years ago
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&#x2F;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&#x2F;slippage. Even if there aren&#x27;t fees now, you should include fees at points in history when there were higher fees. HFT&#x27;s have been forced to tighten their spreads as retail traders have become more liquid with lower&#x2F;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).
Kibaealmost 4 years ago
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&#x27;s highest performing ETF at market open and close your short position at market close.<p>Because this algorithm operates on Vanguard&#x27;s 11 Sector ETFs, it is resilient against the volatility of individual stocks.<p>### Caution<p>Hindsight is 20&#x2F;20 and because this is a backdating algorithm, similar results are not guaranteed in the future. Use at your own risk.
评论 #27415809 未加载
评论 #27417534 未加载
paulpauperalmost 4 years ago
Pretty smart. Tempt the reader with a &#x27;killer&#x27; but incomplete statrgy and make us do all the work to test it and find the flaws so you don&#x27;t have to. I am sure this is way too good to be true.
Majromaxalmost 4 years ago
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&amp;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?
评论 #27415795 未加载
ArtWombalmost 4 years ago
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:&#x2F;&#x2F;alpaca.markets&#x2F;data" rel="nofollow">https:&#x2F;&#x2F;alpaca.markets&#x2F;data</a>
评论 #27415085 未加载
MR4Dalmost 4 years ago
“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.
EMM_386almost 4 years ago
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&#x27;t know where to start. But this seems common these days, I think it&#x27;s due to the influx of inexperienced traders who have no proper statistical background.<p>I&#x27;ll let ryanmonroe point out the first glaring problem with these types of simple &quot;algorithms&quot;:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27415821" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27415821</a>
评论 #27417434 未加载
happytraderalmost 4 years ago
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.
nlalmost 4 years ago
Unrelated, but it&#x27;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:&#x2F;&#x2F;github.com&#x2F;huseinzol05&#x2F;Stock-Prediction-Models&#x2F;issues&#x2F;61" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;huseinzol05&#x2F;Stock-Prediction-Models&#x2F;issue...</a>
jonehollandalmost 4 years ago
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.
TacticalCoderalmost 4 years ago
It is great to see a trading strategy that actually make gains while short-selling, during mostly bull markets. &quot;Everybody looks like a genius during a bull market&quot;. Short-selling is something else...
Exumaalmost 4 years ago
What software do you use to implement algorithms like this? Do you have to write your own python&#x2F;other scripts and interact with trading API&#x27;s for whatever service you use, or are there nice pre-written open source trading algorithms that make building stuff like this easier.
评论 #27415147 未加载
评论 #27416326 未加载
throwaway4goodalmost 4 years ago
The algorithm of just selling the best performing etf of yesterday???
评论 #27415238 未加载
lightbendoveralmost 4 years ago
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.”
herpderperatoralmost 4 years ago
This doesn&#x27;t take into account taxes. If you are consistently profitable on a yearly basis you&#x27;re expected to pay 100% of last year&#x27;s capital gains split into Estimated Taxes every quarter going forward. That eats into your return if you&#x27;re reinvesting profits.
评论 #27570540 未加载
frakkingcylonsalmost 4 years ago
Hook it up to interactive brokers for a year and update us!
S_A_Palmost 4 years ago
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&#x27;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&#x27;t pan out. All that was was just that- speculation and gambling.
hmate9almost 4 years ago
Now Backtest it from 2015 onwards. 4% yearly return. All your returns come from the first 2-3 years.
dezmoualmost 4 years ago
I like those naive way to test trading bot, you can check my attempt here, but mine doesn&#x27;t work :) <a href="https:&#x2F;&#x2F;github.com&#x2F;dezmou&#x2F;CryptoGPU" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dezmou&#x2F;CryptoGPU</a>
InfiniteRandalmost 4 years ago
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.
ffggvvalmost 4 years ago
what time period did you backdate over?<p>i’m curious what the backdated return would be for different time periods
评论 #27415302 未加载
ffggvvalmost 4 years ago
var total = 0;<p><pre><code> for (var i = 0; i &lt; performance.length; i++) { total += performance[i]; } var avg = total &#x2F; 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 &quot;cash&quot; variable is correctly calculated.
MR4Dalmost 4 years ago
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.
insaideralmost 4 years ago
My golf betting algorithm averages just over 20% BUT It&#x27;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:&#x2F;&#x2F;www.golfforecast.co.uk&#x2F;profitgraphs" rel="nofollow">https:&#x2F;&#x2F;www.golfforecast.co.uk&#x2F;profitgraphs</a>
johnwheeleralmost 4 years ago
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.
mgamachealmost 4 years ago
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&#x27;t have small stop loss settings.
zucker42almost 4 years ago
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&#x2F;or not increasing, so if the returns were measured over the last year, then results could be misleading.
belteralmost 4 years ago
Now add trading commissions :-)
评论 #27415102 未加载
bionhowardalmost 4 years ago
Sounds promising if true, and it&#x27;s cool that you&#x27;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!
htrpalmost 4 years ago
It&#x27;s times like this I wish HN had a downvote button.
wernercdalmost 4 years ago
&quot;Caution Hindsight is 20&#x2F;20 and because this is a backdating algorithm, similar results are not guaranteed in the future. Use at your own risk.&quot;<p>You don&#x27;t say...
slava_kiosealmost 4 years ago
What platforms does the algorithm work on?
xwdvalmost 4 years ago
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.
评论 #27415181 未加载
评论 #27415861 未加载
评论 #27415208 未加载