Tag: macro

Macro: Using Currencies to Predict NIFTY, Part III

Please read Part I and Part II for an introduction.

In Parts I and II, we saw how a polynomial kernel was probably a good way to tune an SVM. Also, there was no single degree parameter that was necessarily better than the others. In this post, we train three different polynomial kernel SVMs on two other dollar indices (DTWEXB and DTWEXO) and USDINR (DEXINUS) and tabulate their returns over the two different datasets and across different degree parameters.

To recap, The FRED publishes the following indices along with USDINR (DEXINUS):

  1. DTWEXB: Trade Weighted U.S. Dollar Index: Broad
  2. DTWEXM: Trade Weighted U.S. Dollar Index: Major Currencies
  3. DTWEXO: Trade Weighted U.S. Dollar Index: Other Important Trading Partners

We modeled DTWEXM in Parts I and II. Here, we model the rest.

Results

2000-2018

DEXINUS.NIFTY SVM
DTWEXB.NIFTY SVM
DTWEXO.NIFTY SVM

2005-2018

DEXINUS.NIFTY SVM
DTWEXB.NIFTY SVM
DTWEXO.NIFTY SVM

Given the results above, we can ignore DTWEXO going forward. Surprisingly, DEXINUS (USDINR) does not predict the 2018 correction. In fact, the DEXINUS model using the 2005-2018 dataset replicates buy&hold. Hence, we will ignore DEXINUS as well. The SVM modeled on the 2005-2008 dataset using DTWEXB with degrees 5, 6 and 8 seem to have side-stepped the 2016 and 2018 corrections. Furthermore, degree 8 seems to have produced the best cumulative returns on the test set.

DTWEXB.NIFTY SVM

Next steps

Our observation from Part II was that a 2005-2018 dataset is probably a better set than 2000-2018. This is confirmed from the DTWEXB model above. In the next post, we will combine the DTWEXB(8) and DTWEXM(4) SVM models using the 2005-2018 datasets.

Code and charts are on github.

Macro: Using Currencies to Predict NIFTY, Part II

Please read Part I for an introduction.

Earlier, we saw that a 3rd degree polynomial kernel produced the best results on the test set. In this post, we explore if we can we get better results by tuning the degree parameter.

Outline

  1. Use 1-, 2-, 5- and 10-week returns of DTWEXM to train an SVM using a polynomial kernel 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
  3. Divide the dataset into training/validation/test sets in a 60/20/20 ratio
  4. Use the validation test to tabulate out-performing degree parameters
  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

Results

We find that there is no single degree parameter between the two datasets (#2 above) that consistently outperforms.

2000-2018 dataset
DTWEXM.NIFTY SVM
2005-2018 dataset
DTWEXM.NIFTY SVM

Here are the cumulative return charts for the best performing parameter:
2000-2018 dataset (8)
DTWEXM.NIFTY SVM
2005-2018 dataset (4)
DTWEXM.NIFTY SVM

While the first model (using the 2000-2018 dataset, 8th degree polynomial) failed to “predict” the 2018 correction in the NIFTY 50, the second one (2005-2018 dataset, 4th degree polynomial) seems to be able to side-step it. However, an SVM tuned with the 4th degree polynomial on the 2000-2018 dataset again failed to side-step the 2018 correction, indicating that we need to look more closely on how we choose our dataset – sometimes going too far back in time is counter-productive because the world changes.

Next Steps

In the next post, we will train a polynomial SVM with the other dollar indices (DTWEXB and DTWEXO) and USDINR (DEXINUS) and tabulate their predicted returns over different degrees.

Code and charts for this post are on github.

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

Macro: NIFTY vs. INR/OIL Correlation, Part III

This is the last part of the study. Part I, Part II

The reason why a linear model between NIFTY and USDINR built in Part II failed could have been because:

  1. Weekly returns were not appropriate for the relationship. Perhaps INR affects NIFTY at a higher frequency.
  2. There is no linear relationship because a rising/falling INR. Changes are not uniformly good/bad.

One way to visualize it is to plot the NIFTY returns density at different USDINR return thresholds. If there is no obvious difference in the densities between NIFTY returns when USDINR is positive vs. when it is negative, one could conclude that there is no straight forward relationship between the two.

Here is the NIFTY weekly returns density when USDINR is going up (the rupee is depreciating):
density plot NIFTY vs. USDINR
Note the curve when USDINR weekly returns are greater than 0.5% vs. when are greater than 2%. There is a bearish bias.

And, NIFTY weekly returns density when USDINR is going down (the rupee is appreciating):
density plot NIFTY vs. USDINR

If you juxtapose the above densities, it is apparent that when the rupee is appreciating, the densities skew right, And when the rupee is depreciating, there is a left skew. These charts show that there is “a” relationship – just not what can be captured by a linear model.

Code and density plots for NIFTY vs. OIL can be found on github.

Macro: NIFTY vs. INR/OIL Correlation, Part II

This is a continuation of the correlation study of Part I
Our correlation study showed a -0.54 between NIFTY 50 and USDINR whereas a 0.21 with OIL. Here, we will use weekly returns of the NIFTY and USDINR to build a simple linear model.

Building a linear model

A weak correlation doesn’t usually lend itself to a useful linear model. To illustrate this point, have a look at the diagnostics below:
NIFTY~INR linear model
Ideally, the ‘Residuals vs. Fitted’ plot should show residuals evenly distributed around the zero line – it doesn’t. The Q-Q plot should lie on the diagonal – it is marred by heavy tails. Hence, we should scale-down our expectations from the model.

For this post, we will split the time-series that we have into a “training set” that goes from 2010-01-01 to 2015-12-31 and a “test set” that goes from 2016-01-01 to 2018-09-30. We will build the model with the former and test it with the latter.

Results

Predicted vs. actual weekly NIFTY 50 returns:
actual.vs.pred.NIFTY50
To test our model, we will give it the actual NIFTY 50 returns (x-axis) and plot the predict NIFTY 50 returns (y-axis.) The problem here is immediately apparent: it is heavily bullish! It consistently gives a positive prediction.

Long and Long-short cumulative returns:
linear.model.cumulative.NIFTY50
If we use our model to go long-only (L) or long-short (LS), we get the cumulative returns shown above. The model is no better than buy-and-hold (at least it is no worse, so there is that.)

Take-away

A weak correlation between NIFTY 50 and USDINR is not much to work with and a linear model built over that relationship is no better than buy-and-hold. Given the narrative spun by the media, it is tough to wrap ones head around the results above.

We conclude with density charts of weekly NIFTY returns under different USDINR return thresholds in Part III.

Code and charts on github.