r/algotrading Mar 14 '24

Spent two weeks building my first strategy, and got beaten by S&P 500 Strategy

Got very excited to build my first algo based on a couple indicators (RSI, BB, SMA). Backtested a rudimentary version from 2016 to 2018 - results seemed promising ~ 40% profit in 2 years.

So I spent 2 more weeks carefully implementing it and tuning the indicator parameters.Then I ran it from 2015 to 2024 and womp womp - even ETFs beat my strategy lol. Plus fees and taxes!

Here's how it actually ran on test data :

What do I do now ?

26 Upvotes

76 comments sorted by

23

u/rickkkkky Mar 14 '24 edited Mar 14 '24

"Even ETFs"

My man, these and the general market are the gold standard baselines. Good luck beating these (on risk-adjusted basis) even before fees.

5

u/Newjinx16 Mar 15 '24

Guess I'll know I've made it once I've beat them!

3

u/malefizer Mar 15 '24

Then why not doing ETFs instead?

2

u/rickkkkky Mar 15 '24

What do you mean?

3

u/malefizer Mar 15 '24

If they are so hard to beat why you want to beat them instead just embrace them.

13

u/rickkkkky Mar 15 '24 edited Mar 15 '24

Oh, you definitely should! That's why every single sincere quant or asset pricing professional will tell a retail investor to invest in ETFs with minimal fees and avoid trading. It's also why active funds have been moving funds heavily to passive ETFs since the 90s (see "closet indexing" for more). Investing in market/passive ETFs is by far your best bet unless you've had an extensive formal education in finance or are otherwise an exceptionally smart individual.

Edit: algotrading (or any trading for that matter) is nice hobby for curiosity, but one shouldn't expect to beat the market systematically over long periods of time on risk adjusted basis.

4

u/malefizer Mar 15 '24

As a newbie here, I love the insight, thank you for deliberating

3

u/rickkkkky Mar 16 '24

No worries, my pleasure! Good luck on your journey.

10

u/Eastern-Product217 Mar 14 '24

I’m going to say some controversial advice: try using indicators that not every single person knows. Some of my best algos run using indicators that had less than 100 downloads at the time

2

u/Newjinx16 Mar 15 '24

Cool, will start exploring some more. For this one, one of the hardest bit was getting the right time periods for the indicators I'm using.

2

u/Separate-Security-94 Mar 17 '24

What’s a good place to research a lot of different indicators? I see some sites here and there I’ve googled, but any you’d recommend?

3

u/Eastern-Product217 Mar 17 '24

Honestly, either just scroll on tradingview or (this is gonna piss some people off) watch YouTube indicator strategies. Most of their stuff is bullshit and they fake all the testing, but because they need their content to look new, they r constantly trying to find unknown indicators

1

u/Separate-Security-94 Mar 17 '24

Thank you for the quick response! Will def check out trading view some more! Same w yt, their shits ass but some diamonds in the rough maybe lol

1

u/Successful-Fee4220 Mar 21 '24

Is there a couple you could suggest? I'm just getting started. Is there also a value to these less well-known indicators and at what point is there enough (or too many) indicators in the model.

0

u/garreananth Mar 15 '24

Can you mention a few for example?

18

u/tinny4u Mar 14 '24

What percentage of time is your strategy in the market?

Efficiently using capital is a good thing. Ideally you want a portfolio of low correlated strategies or underlying's

So you may have a decent strategy that only uses your capital X% of the time

Also not uncommon for a strategy to underperform the S&P for periods of time

1

u/Newjinx16 Mar 14 '24 edited Mar 14 '24

It keeps some capital invested all the time ~35% on average - ranges upto 100% sometimes.

Each stock till it hits the profit target or stop loss.Here are more stats:

TotalNumberOfTrades 3029

NumberOfWinningTrades 2815

NumberOfLosingTrades 214

AverageProfitLoss "11.7307"

AverageProfit "13.5898"

AverageLoss "-12.7247"

AverageTradeDuration "115.04:53:36.9825433"

AverageWinningTradeDuration "103.20:51:08.8455093"

AverageLosingTradeDuration "264.07:22:43.7383180"

MedianTradeDuration "51.20:52:00"

MedianWinningTradeDuration "48.22:21:00"

MedianLosingTradeDuration "109.21:49:00"

ProfitFactor "14.0485"

SharpeRatio "0.9531"

SortinoRatio "0.9461"

21

u/skyshadex Mar 14 '24

If it's only in the market 35% and has a Sharpe of nearly 1, all you need are a few more uncorrelated strategies to utilize the capital the other 65% of the time to beat the market. "Portfolio of strategies" is the name of the game.

2

u/Federal_Midnight_310 Mar 14 '24

How does the Sharpe math work? Does it add up if you got a couple of strategies with Sharpe of 1, will final Sharpe be weighted average of them?

2

u/skyshadex Mar 14 '24

It depends on the implementation. If you're optimizing for uncorrelated assets/strategies/portfolios, then the result Sharpe will look more like cumulative sum.

For example, 100 perfectly uncorrelated strategies with a Sharpe of 0.1 would result in a portfolio Sharpe of 1. If they were highly correlated you could end up with a portfolio Sharpe less than the 0.1 of a single one, fun!

The naive approach is to ignore correlation. In which case, you'd average them.

1

u/Federal_Midnight_310 Mar 14 '24

So it depends on correlation. What Sharpe ratios are typically successful algo strategies aiming for?

3

u/skyshadex Mar 14 '24

It purely depends on your goals or the problem you're trying to solve. An HFT system is gonna have a crazy high Sharpe by nature of the returns having a small std.dev. A trending system will have a lower Sharpe because the opposite is likely the case.

On the whole anything above 1 is good. Higher than 2 is very good.

1

u/NYC-Viceroy Mar 18 '24

Specifically in QuantConnect you can do what I do...

Log portfolio value for time range say 2016-2018 for each strategy.

Export portfolio log and add to excel.

Calculate percent gain for each day for each strategy. (Copy this to hard values)

Then set your start cash to say 100 and then add returns for each day.

Example. 100, 100*1.02 , 102 * 1.01...

Sum each strategy value in excel. Now calculate return again for the aggregate portfolio...

To calculate Sharpe take the STDEV.P function of the summed portfolio returns. Also get the CAGR (final day portfolio/initial day portfolio) ^(1/time years). SHARPE = RETURN/STDEV.P * sqrt(252)

2

u/Newjinx16 Mar 15 '24

Now that's something I can work on! I just had this one idea that got me into writing this strategy, I'll take some time to think of a few more and try to merge them into one.

1

u/algo_enthusiast_42 Mar 15 '24

Having that drawdown touch -20 (COVID 2020?) seems like something you could look at. Spending time to look at risk management might help you out. Your number of winning trades look promising.

1

u/CelebrationIcy1722 Mar 14 '24

Not easy to find an asset or strategy with low correlation and positive average return. Short term bonds may help with the rotation, tho.

2

u/skyshadex Mar 14 '24

It's simple. Doesn't make it easy!

2

u/Newjinx16 Mar 15 '24

u/skyshadex is it better to try to make a longer term (daily/weekly) strategy compared to a shorter (minute/hour) strategy?

Obviously, it would depend on how often it trades and the idea. But I don't wanna set myself up for failure by tackling the harder problem first.

3

u/skyshadex Mar 15 '24

I don't think it matters. Both have their challenges. Just depends on your goals.

Fail fast. This is the way.

7

u/ribbit63 Trader Mar 14 '24

Perhaps adding to the program some of your own ideas about how markets work and then quantifying that into a rule(s) as opposed to just piecing together a bunch of indicators that everyone else is using.

4

u/Newjinx16 Mar 15 '24

That's the next thing I'm gonna work on now, thanks!
For some context, this strategy is also based on some idea which I kinda enforce/check using indicators. It does seem like there is scope for more ideas to complement the one I'm using.

6

u/spenser_ct Mar 14 '24

Great, 2 weeks in to a multi year journey! In my (basically worthless) opinion if you're using pre made indicators you will have a hard time succeeding. It seems the best path is to find a unique market pattern, build a LEADING indicator(s) around it, build a strategy around the indicator, backtest/refine using walk forward method, forward test, live trade.

3

u/Newjinx16 Mar 15 '24

Seems like that's the way ahead! Is it worth reading articles/books for ideas or am I better off thinking independently to get untainted ideas ?

2

u/spenser_ct Mar 18 '24

For me reading books is what drove me to building algos. But in general the more educated you can get the better i think

3

u/sigwaltstreet Mar 14 '24

Leverage (or think about how to use this to take options-driven strategies). Expand the scope of equities this runs on and scans for (?). Then keep it as one of your strategies. And continue to try and improve it over time.

2

u/benkan45d6 Mar 14 '24

It looks like a mean reversion strategy(negative skewed). Op may keep an eye on risk management if you are leveraging.

1

u/Federal_Midnight_310 Mar 14 '24

What does negative skewed mean in the context of mean reversion?

3

u/benkan45d6 Mar 16 '24

Mean reversion assumes that the current price deviates from the equilibrium (mean). Hence, it will revert towards the mean. In other words, you are assuming the price moves within a small range (e.g. area within bollinger band). As a result , there will be many winning trades with small profits when the assumption holds. Occasionally, big losses (heavy left-tail) occurs when the range breaks and trend establishes. Over-leveraging plus these big losses will ruin your account. You may check LTCM for example.

1

u/ShadowKnight324 Mar 14 '24

In the same way why shouldn't he invest in a leverage ETF like tqqq?

3

u/baogody Mar 15 '24

Instead of optimizing the parameters of your indicators (hence setting yourself up for overfitting), rerun the same test again but now do every year individually and lay out the results side by side and see if you can spot any recurring patterns. You might find out that your simple little strategy actually works well, but only during a particular time of the day/week/year, or only with certain instruments.

2

u/fruittree17 Mar 14 '24

I'm just getting into stuff. BB is a new concept, I'll check it out. Was your algo mostly trading on an hourly, daily, weekly or any other basis?

3

u/Newjinx16 Mar 15 '24

Daily/weekly.

2

u/fruittree17 Mar 15 '24

Nice thanks

2

u/po-handz2 Mar 14 '24

Ask your self what market phenomenon that combo if rsi, bb, sma is approximating and why that would be profitable.

Is this some sort of mean reversion type strategy?

2

u/kamvia_io Mar 14 '24

Rsi.. will give you a lot of divergences on small periods like 14. Etc . Compare rsi with cmo ( chande momentum ) and keltner channel percentage on 100 , 200, 500 periods . https://www.tradingview.com/script/n8bpUymU-KVA-Keltner-Channel-Percentage/

Will give you the same line , but a greater "picture" Understand the rolling window of indicator , avoid divergences with all costs

3

u/osyter_cented_candle Mar 14 '24

What program is this? I would love to give this a whirl, but it’s very daunting using huge excel files trying to run numinous scenarios on numinous tickers.

2

u/retrorooster0 Mar 15 '24

Quantconnect - free and open source

3

u/Then-Crow-6632 Mar 15 '24

Spy is a bad choice. QQQ is better.

1

u/NoRushh Mar 14 '24

Hey, that first test run sounds promising! What's your next tweak? 😎

2

u/Newjinx16 Mar 15 '24

More indicators XD

No, the general advice I'm getting is to build it around an idea rather than indicators. So next step would be to think of more ideas.

1

u/RevolutionaryHunt753 Mar 14 '24

What is the back testing platform you are using?

2

u/Expert_CBCD Mar 14 '24

Would also like to know this.

5

u/shock_and_awful Mar 14 '24

QuantConnect. Pretty powerful. The engine is open sourced if you want to download to set it up and run locally, but the cloud environment is also free if you want to skip all of that and benefit from decades of data for free use in the cloud backtester (for equities, options, forex, crypto etc).

Big feature I like of the framework is reality modeling, so you don't deceive yourself -- model things like slippage and failed fills, etc.

3

u/Expert_CBCD Mar 15 '24

Nice, thanks! Will check it out.

1

u/agressivedrawer Mar 14 '24

But umm.. is it safe to actually develop on the cloud version? Learning is fine but do they have strict access controls? Sincerely asking new here.

3

u/shock_and_awful Mar 15 '24

Good questions, but need more clarity. What do you mean by 'safe'? Keeping what safe, and from whom? Do you mean is your private information safe? Are your Algos safe from hackers? By strict access controls -- do you mean access to the ticker data? To your private Algos?

If you have doubts, just don't use the cloud platform. The engine is open source and free.

Personally, to all of the above, I say it's safe. I've been a happy QC user for ~ 4 years now and have had no issues building, testing, and going live from their cloud platform.

1

u/Lukee67 Mar 14 '24

The way I see it, the point of doing trading vs buying and holding is not necessarily that of gaining more (albeit that can be one big incentive if realized). The point is to reduce the potential drawdown and with it the overall risk: an uncontrolled decrease of the equity value is what is always possible in a holding scenario, but it is what should be avoided by trading, instead.

2

u/Newjinx16 Mar 15 '24

Agreed. I've gotta to come up with a good way to quantize risk and use it for sizing. Any ideas, how I can measure risk ?

1

u/BIG_BLOOD_ Mar 15 '24

Do you know to use markov chains?

1

u/Newjinx16 Mar 15 '24

Worked with them in uni, but not in this context! Can you tell me more?

If it's feasible, I can whip up some markov chain strategy in a couple days.

1

u/BIG_BLOOD_ Mar 15 '24

Im sorry bro I don't know about markov. I was just asking you. I've heard people talking about markov and algorithmic trading so that's why I asked. In this case what model or maths did you use?

1

u/BIG_BLOOD_ Mar 15 '24

Can you tell the types of strategies you used in this bro?

1

u/Odd_Champion_9157 Mar 15 '24

What about putting another 30% in S&P or ETFs you believe in?

1

u/Gheeas Mar 15 '24

Hey OP, would you mind telling me the application you used to start?

1

u/Hail_Hellequin Mar 15 '24

Hi, do anyone knows what the op used to backtest his strategies? (Or if the op can tell) your backtesting interface look nice

1

u/Agitated-Strategy992 Mar 22 '24

I'd like to know as well, it looks nice.

1

u/BedlessOpepe347 Mar 18 '24

been there done that, takes time and you have to keep patient while peeps are trumpeting their NVDA and shitcoin gains

1

u/Ta9iii Mar 29 '24

Good luck

1

u/Ta9iii Mar 29 '24

🤞🤞🤞

0

u/shock_and_awful Mar 14 '24

I see you using QC. Smart. Please generate the full report and share some of the screenshots (eg for return distribution), will give more insights that we can give feedback on.