The In and Out Strategy
Are you In with risk-on or Out with risk-off ETFs? Let the In and Out algorithm trading signals guide you or your robo-advisor.
Note: This is joint work with my brother Jeff Coppola (email@example.com)
Get onboard with learning algorithmic trading and robo-advising , either as a user or a creator!
- User: Subscribe to In-And-Out robo-advisor on Collective2, or use the signal on the HCA telegram bot to drive your trades.
- Creator: Run and live-trade your own python version of In-And-Out using an open-source zipline platform(e.g. zipline-broker, zipline-trader, zipline-reloaded), and hook it up to a broker(IB, Alpaca) to create your own robo-advisor platform.
An Original Quantopian In-And-Out Discussion thread outlined an algorithmic traded stock strategy and risk management that is simple, elegant, and crowd-sourced in conception and execution. Quantopian closed shop in October, 2020, yet we still want to deploy this strategy!
S&P 500 benchmark beating returns are achieved for simple risk-on/risk-off signals based on an algorithmically traded strategy using small portfolios of index funds for the risk-on and risk-off portfolios.
There is also an open source version of In-And-Out. available for your perusal, which would allow you to run your own version on any broker you wish, along with using a zipline platform (e.g. zipline-broker)
There is also cautionary information referenced that indicates some overfitting of the backtests, based on more complex market conditions than the trading signals capture which is discussed. So, again…do not take this as trading advice, and there is a real risk that you can lose money when using this strategy.
The In-And-Out strategy is a daily traded strategy, daily so that you don’t miss any In or Out calls, that we are using is based on generating two signals, one which is a ratio of the returns of a silver fund(SLV) divided by the returns of a gold fund(GLD), and the other is a ratio of returns from a broad industrials fund(XLI) divided by returns from a broad utilities fund(XLU).
The intent of the signals is to capture when a mini-bull run(In) is going to turn to a mini-bear run(Out).
Quoting from the Quantopian Forum:
Yet, what is the mechanism that translates this dynamic into what will be going on in the equity market?
The algorithm does not predict what will happen on the stock market,
rather, it determines what stage of the market cycle we are at.
It is well known that gold is considered a safe-haven asset and many investors turn to it when the economy starts to struggle.
Gold value usually increases when the market goes down.
Whether it is futures, bullions, coins etc., gold is the go-to asset in times of economic stress. Gold daily moves has slightly negative correlation to equity market daily moves especially in bear market.
Silver daily moves has more than 80% correlation to Gold as they are in the same asset class.
But silver daily moves has positive correlation to equity market daily moves.
When gold goes up and silver goes down their price relative ratio changing faster and may signal regime change earlier than momentum of any of them…
@DanWhitnable 1 week ago
Everyone, again great work and truly appreciate the collaboration and sharing of ideas. Peter, you deserve a big thank you and ‘well done’ getting it all started.
Here is another iteration which incorporates Tentor Testivis’s market volatility to determine when to get back into the market. It also builds on Vladimir and Thomas Chang’s ideas of ratio’s to eliminate some of the constants. However,
I made a simplification, and rather than ratios, I use a basic comparison. In the end it reduces to three simple rules:
`bear_signal = (
(gold_returns > silver_returns) and
(utility_sector_returns > industrial_sector_returns) and
(industrial_metals_returns < dollar_returns))`
I think this is close to Peter’s original intent just more distilled. It also aligns closely with conventional wisdom and
includes both ‘sentiment’ and ‘economic’ indicators. Traders sentiment favors gold and utilities if the market isn’t
looking good. Industrial metal prices tend to go down with less demand which points to lower markets.
The signals tell you when to get In and Out, and, there is a volatility adaptive calculation that tells you a minimum amount of time to stay out before you can get back in,
This methodology outlines a way to trade most equity strategies, with this risk-management algo pipelined in at the beginning to act as a risk-on/risk-off signal controlled by shorter term regimes controlled by larger market forces.
In the case of this algo, In-And-Out, there is no greater algo to control…just…are you In[index funds] or are you Out[bonds/alternatives] ?
Research, Back-test & Overfitting
The end results of the research for this strategy are intertwined with discussion board threads and backtests, which is a unique, yet effective way of getting to an investible strategy.
The research for this strategy is included in the discussions pointed to in the list: (Note: to get at the Quantconnect forum, you may have to signup for a free account)
- Original Quantopian In-And-Out Discussion
- Quantopian In-And-Out Live Trading Discussion
- Quantconnect In-And-Out Discussion
- Quantconnect In-And-Out Overfitting Discussion
The backtest results, for a two year run, are in the file:
In-And-Out backtest pyfolio analysis.
the trading frequency is daily, to reduce the risk of getting Out too late.
Overfitting is defined as poor matching of behavior when this algo is executed on out-of-sample data. Our analysis is for a two year backtest, with a 90-day forward-walk on most recent data.
The algo parameters have been tuned by discussion and experimentation. As the article about overfitting above indicates, if you go to the past traumatic stock market events(2000, 2008), this algo doesn’t hold up, due to regime changes, so has some backward-overfitting.
We acknowledge that, which means that we will monitor regime changes by hand, and get out of our postitions if we detect anomalies. We accept the forward-looking risk and warn you to either not use this algo or accept that risk also. We take no responsibility for anything you do involving trading this algo.
There isn’t much to talk about here, just the technical details of how you may execute the computed signals for this algo.
- We schedule zipline(zipline-broker) and Interactive Broker’s TWS to fire off each day, ingest the daily prices for the portfolios, and to execute the algorithm, using the latest current-state.csv file, which records the state of the last run. For more details, see our HCA YouTube video.
- Use the telegram bot
and issue the command /sig to find today’s signal (/s 22 gives the last 22 days of signals), and trade that signal anyway you wish…Robinhood, IB, Alpaca, etc. While you are at it, the command /plot in the bot will give you the cumulative returns trace for a back-test spanning the last 2 years.
- Connect to our Collective2 strategy “In and Out” to follow and/or trade this algorithmic strategy live.
Tapping into the algorithmic trading revolution is easier and easier. We’ve shown a simple yet effective strategy, valid for IRA funds, and its deployment that you could trade by hand just using Excel and Yahoo data, yet would require lots of work to do so.
Algorithmic trading not only automates what you can do by hand, but allows deeper and more timely computations.
Stick with this series to dive deeper down the rabbit hole of algorithmic trading. Next up is using fundamentals to choose top stocks to invest in, dynamically…stay tuned!