Tag: support vector machine

Macro: Using Currencies to Predict NIFTY, Part I

This series of posts pulls together two things we observed in our previous posts:

  1. There is a non-linear relationship between USDINR and the NIFTY (NIFTY vs. INR/OIL Correlation)
  2. There is a stable spread between USDINR and currency indices published by the FRED (USDINR and Dollar Indices)

Here, we use a Support Vector Machine (SVM) to train a model on the returns between the DTWEXM index (Trade Weighted U.S. Dollar Index: Major Currencies) and the NIFTY 50.

Outline

  1. Use 1-, 2-, 5- and 10-week returns of DTWEXM to train an SVM on subsequent 1-week returns of the NIFTY 50
  2. Consider two datasets: one between the years 2000 and 2018 and the other between 2005 and 2018 to include/exclude the 2008 market dislocation
  3. Divide the dataset into training/validation/test sets in a 60/20/20 ratio
  4. Use the validation test to figure out which SVM kernel to use
  5. Plot the cumulative return of a long-only, long-short and buy&hold NIFTY 50 strategy based on SVM predictions on the test set
  6. Use the common kernel between the #2 datasets for future experiments

Results

We find that an SVM using a 3rd degree (the default) polynomial kernel gives the “best” results. We use the SVM thus trained to predict next week NIFTY returns and construct long-only and long-short portfolios.

Here are the cumulative returns when the dataset considered is the one between 2000 and 2018. The test set runs from 2015 through 2018:
DTWEXM.NIFTY.polynomial svm

There are some points of concern. For one, the model is heavily long-biased. Even when the actual returns were negative, the predicted values was mostly positive:
DTWEXM.NIFTY.polynomial.actual.vs.predicted svm

Second, the model has tracked the buy&hold NIFTY since the beginning of 2018. The narrative has been that the rise in oil prices caused the CAD to blow out that caused investors to pull out investments that caused the rupee and NIFTY to fall (whew!) Either USDINR moved independently of DTWEXM or the relationship between DTWEXM and NIFTY 50 broke down. It looks like its the former:

Third, the cumulative returns seem to have been majorly influenced by small set of predictions that cut a drawdown that occurred in July-2015 by half. We notice a similar effect on the smaller dataset (2005 through 2018):
DTWEXM.NIFTY.polynomial svm
See how a small branch in Nov-2016 lead to the superior returns of the model predicted portfolios.

Next steps

In the next part, we will fiddle around with the degree of the polynomial used in the kernel to see if it leads to better returns. Subsequent posts will cover the use of the other dollar indices (DTWEXB and DTWEXO) and finally USDINR (DEXINUS) itself.

Code and charts for this post are on github

Machine Learning Long-Short Trend Following

Introduction

Our previous post discussed how a simple SMA On/Off Switch based tactical algo can be enhanced by a volatility metric. We generated significant alpha by following a simple rule:

Go short if either or the volatility signal or the 50-DMA indicates a negative bias and long otherwise.

But what if we trained a machine on the same data and allowed it to decide when to go long and short?

Support Vector Machines

We fed an SVM our volatility metric and the percentage distance from 50-day SMA. A 5-year training set was used to predict the next year daily long/short. We will not delve into the details of how SVMs work, Wikipedia does a decent job introducing the concept.

Performance

To make it easier to compare, we plot the wealth-charts for the NIFTY and BANKNIFTY indices side-by-side.

The black line is the Machine Learning Long-Short Model and the blue line is buy-and-hold. NIFTY and BANKNIFTY since 2011:

nifty.machine.learning.2011

banknifty.machine.learning.2011

NIFTY and BANKNIFTY since 2013:

nifty.machine.learning.2013

banknifty.machine.learning.2013

Cumulative Returns

Buy-and-hold has two big advantages over a trading strategy: transaction costs and tax treatment. Here is how the different strategies compare with buy and hold:

NIFTY SVM

BANKNIFTY SVM

It appears that the ML(V + 50-DMA) Long Short strategy works better on the BankNifty than on the Nifty. The out-performance of the ML model on the BankNifty more than compensates for transaction costs and taxation.

Conclusion

The ML model outperformed the NIFTY by an average of 12% in the last 4-years and the BANKNIFTY by 94% in the same period. The out-performance on the BANKNIFTY is considerable enough to warrant further exploration.