Tag: machine learning

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

Trend Following vs. Trend Prediction, Part II

We are finally past the 100-day milestone on our machine-learning trend-following models. Here is how it compares against our other momentum models:

The ML algos out-performed a majority of traditional momentum algorithms. “NN” here stand for Neural Network and “ML” for models that use a SVM under the hood. It will be interesting to see how these models look under the 200-day lens as the short-term “luck-factor” evens out.

You can check out these models here.
The first post in this series is here.

Trend Following vs. Trend Prediction, Part I

Traditional equity momentum strategies are variations of algos that try to figure out “trending” stocks so that they can be ranked to create a long/short portfolio. The key thing to remember is that these algos are following a trend, the prediction that a trending stock will continue to trend is implicit. However, using machine learning techniques, stocks can be ranked based on their predicted returns over a future time frame.

The simplest momentum strategy looks only at a price series. However, it quickly runs into problems when additional factors are overlaid on top of basic momentum. For example, you may want to filter out volatile stocks out the basket. You can do this either by setting a maximum volatility level or by weighing both momentum and volatility to arrive at a combined rank. Either approach leads to ad hoc decisions of cut off levels and the ratio with which to weigh each of those factors. Luckily, typical machine learning algorithms can work with multiple factors and weigh them based on the training set you supply.

The biggest drawback of using machine learning is that the larger the number of factors/features you use, the less explainable the resulting model becomes. As a trader, if you want to use any of these models, you should have a fairly good idea of what is going in, how the model is setup and what exactly is the model getting trained with.

As a first step in taking a crack at this, we have setup four machine learning algos. Two of them use SVRs and the other two use LR to train on data that is either return-series only or a combination of returns and volatility. You can have look at them here.

We will have more of these machine learning models out as we ramp up our understanding of these models. Stay tuned!