RSI Indicator with Martingale Position Sizing

The following article is a guest post from Jared Broad, CEO and Founder of QuantConnect. QuantConnect is an online browser-based back-testing platform for C# that allows you to test custom strategies over 15 years of historical intraday data. This article will be part of a new bi-monthly post by Jared with strategy examples for algorithmic trading.

Martingale is a bet sizing technique for increasing odds of winning at the expense of increased risk. The classic example is a coin flipping game where the gambler doubles his bet if he loses, in the hopes of making back any losses to break even. He will continue doubling his bet through subsequent losses until the bet breaks even. Once he returns to whole he continues betting with a unit bet. In theory with infinite capital and exactly 50-50 probability martingale can ensure the gambler will always return a profit.

Martingale portfolios typically display near perfect equity curves with dramatic, short term drawdowns.
Martingale portfolios typically display near perfect equity curves with dramatic, short term drawdowns.

Martingale position sizing is sometimes used in trading strategies without knowing its true risks. When implemented in reality traders have limited leverage, and the market win-loss probability fluctuates as losses can when the market is range-bound. It is a certainty that with a sufficient sample size eventually catastrophic loss does occur, it’s just a matter of when.

To demonstrate this we built a martingale position management algorithm, and backtest it on 15 years of data in QuantConnect to highlight the crashes.

To decide entry points we chose a the popular Relative Strength Index (RSI) indicator and shorted when it was over 70, signalling it was overbought. Conversely we entered the market long when it was less than 30, signalling oversold. Our entry and exit conditions were fairly arbitrary because we wanted to explore martingale position sizing more than RSI.

Once the algorithm was vested we monitor for a minimum profit gain, and on achieving the minimum profit-gain we exit the strategy locking in the profit.

In the event the algorithm reaches our maximum loss, we record the trade loss and double-invert the position as per martingale rules. The trade’s loss is now attached to a “loss-chain” parameter which serves as memory of this doubling-sequence. The minimum profit gain must also recoup the loss-chain before resetting to start again.

Our backtest result shows our implementation beating the absolute return of the SPY over a 15 year period, but it has greater volatility resulting in a lower Sharpe Ratio (0.4 vs 1.1 S&P). Interestingly it demonstrates the characteristic crashes of a martingale strategy, but since we have fixed leverage the crashes never rebound to form the perfect straight line.

There are many areas for experimentation to improve the strategy performance, such as using more intelligent entry and exit techniques, anti-martingale position sizing and adjusting our entry and loss targets based on market volatility. But I’ll leave that for you to explore!

Originally posted by Jared Broad on QuantConnect.

The Importance of Benchmarking – Measuring the Sell in May Strategy

The following article is a guest post from Jared Broad, CEO and Founder of QuantConnect. QuantConnect is an online browser-based back-testing platform for C# that allows you to test custom strategies over 15 years of historical intraday data. This article will be part of a new bi-monthly post by Jared on algorithmic trading for retail investors.

There are two different techniques for measuring your strategy performance; relative and absolute performance. Before you design your strategy its important to define your metrics for success. As you iterate through strategy ideas this will help you know where you need to improve.

An absolute return strategy aims to make a consistent steady return independent of market conditions. It might rely on assets which are not affected by the market volatility such as bonds. Strategies which trade long and short are easier to be designed for an absolute return.

The alternative method is to compare or “benchmark” your strategy a market index. The precise index or market representation you choose can vary but often funds choose the S&P500. With a relative return strategy reducing holdings to cash is a net gain relative to a downward market.

We’ve integrated this directly into the QuantConnect results panel so you can load a custom benchmark into your charts, to know how your strategy is performing relative to the major indices. To access it, click on the “Select Benchmark” menu in the Chart Options on the right hand side:
bench

To demonstrate the benchmarking functionality we’ve written the next video in the QuantConnect University series – Sell in May and Go Away. It is a demonstration for how to code up the sell in may strategy, and then we benchmark it to the S&P500 over the same period.

With this particular implementation we achieved the same returns with lower volatility, resulting in and overall better than market strategy.

This article was written by Jared Broad and originally appeared on QuantConnect.