Category: Strategy Examples

Rotating Inversely Correlated Assets – NIFTY and USDINR

Over the last 15 years the economy of India has boomed and it has been reflected in the NIFTY index. The NIFTY has grown 7x since 1998 as the country has grown its exports. According to the UN the one of the primary exports of India are high value services which contributes 30% to their GDP.

We developed a hypothesis that as the strength of the NIFTY grew, the strength of the currency would follow as it is a primarily export economy. As the INR strengthens the ratio to USD falls making it an almost ideally inversely correlated asset.

We first tested this hypothesis treating the USDINR FX pair as a hedge against the NIFTY, but found there were periods where they were positively correlated and the hedge did not work.

Pivoting slightly we experimented with rotating the holdings of the portfolio to focus on the peak performing asset. We used a fixed rolling window to determine the peak performance and then swapped our holdings to focus on that asset.

We used the QuantConnect LEAN 2.0 backtesting engine which allowed us to import financial data from any source to run our analysis. The backtests were conducted over a 16 year period and were completed in 5-10 seconds. We saw phenomenal performance due to the strongly trending nature of the NIFTY and USDINR, achieving a Sharpe Ratio achieving 1.3 vs the NIFTY 0.7, and 42x returns vs 7x of the NIFTY.

To test the resilience of the strategy we experimented with the rolling window period to determine if this was critical to the success of the strategy. We used a rotating window from 3 days up to a 30 day window to optimize the variable for the best performance:

The resulting Sharpe Ratio is fairly robust regardless of the precise value of the rotating window period.

We believe there are many potential future improvements to the strategy to be explored; such as using a dynamically determined rolling window to avoid curve fitting. You could also experiment with different portfolios of inversely correlated assets to pick the best basket of assets.

RSI Indicator with Martingale Position Sizing

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. Continue reading

The Importance of Benchmarking

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. Continue reading

Three Common Implementation Mistakes

In our work at QuantConnect we have helped with thousands of budding quants over the years. Our algorithm development terminal is a powerful backtesting platform that allows members to design strategies on 15 years of past equities data.

We see several very common mistakes in even the most basic strategies. For our latest free video tutorial – Coding the Exponential Moving Average Strategy – we wanted to start by helping users avoid these common mistakes and show how they could avoid them. These common mistakes are… Continue reading

7 Tips For Fixing Your Strategy Backtesting a Q&A With Top Quants

Strategy backtesting is a mix of art and science. Quants who rely too much on science will fall victim to the infamous Curve Fitting phenomenon. While some quants who overcompensate on their artistic balance will create disillusioned theories that back their models. We created this post to compile leading quants’ perspectives on strategy backtesting covering tools, tips and how to avoid common mistakes made while strategy backtesting.

1. Have A Common Sense Idea of Your Model

“If you can’t come up with a pretty common sense explanation that you can describe to your 12-year-old niece or nephew. Then chances are, you’re simply data mining. Coming up with something that won’t exist in the future.”said Mebane Faber (@mebfaber), Portfolio Manager at Cambria Investments.

When Mebane first started in quant trading he thought he had found the “holy grail” model by analyzing its historical returns. Mebane says extrapolating historical returns to the present is a common mistake made by new quants which can be fixed if you know why your model works. “Most traders that are older have a lot of battle scars either from real money or paper trading portfolios that performed differently than the historical model showed.” says the experienced Mr. Faber.

So what is Mebane’s advice to new quants looking to perfect their backtesting strategy: “come up with a system, or multiple systems (which I think is more important) that fits your personality but is also robust over time“. Wise words from a King of quantitative trading.

2. Use Blind Data to Improve Your Strategy

Optimizing a strategy is for some a process that is ongoing and for some a process that produces such low results that it is abandoned. Deepak Shenoy(@deepakshenoy), Co-Founder of Capital Mind a big data analysis company, says it is a combination of both groups “I don’t like curve fitting so I tend to avoid over-optimization“. Instead he adds unrelated factors “like volume, open interest or options price sensitivity (vega) – or simply by using the knowledge of near term events to augment a system“.

Additionally, an important step for Deepak after he’s optimized, is to test on a blind data set for validation. “I test an optimized strategy on either different sets of stock data or different timeframe data… or both. To see how the system does in other timeframes.” This is before he moves the system to a lengthy paper trading schedule to further validate the model. Deepak’s perspective seems to be a focus on perfection, validation from multiple sources and comprehensive market regime testing. A worthy lesson for quants, be a perfectionist!

3. Decide Your Most Important Metrics Before

When you get to the performance evaluation segment of your strategy backtesting process, historical data is plentiful. “While it is pretty standard to look at popular performance statistics like the Calmar Ratio, Sharpe Ratio, CAGR, or MaxDD, they only reveal a small picture of how the model performed” says Michael Guan, an Associate with Macquarie Group. Michael says he focuses on additional measures like Positive Rolling 12 month periods, average drawdown, Annual Returns, average profit per trade which all provide a “more multi-dimensional view through time“.

Michael is a true believer in a multi-dimensional backtesting process. He explained his viewpoint eloquently: “backtesting is an integral part of trading model development. Making as few assumptions as possible and testing on a wide variety of assets ensures statistical robustness“. Many quants run a backtest with no preconceived notion of the data they want and this creates an issue in determining what data is valuable. Follow Michael’s tip and make a list of the variables that matter to you. And data has more value to you, is the Sharpe Ratio worth more to you than the P:L ratio? You should know this before you start backtesting.

4. Make Sure You Are Looking At The Right Data

Continue reading

© 2017 QuantConnect Blog

Democratizing algorithmic investments Up ↑