Tag: quant

Nifty Gaps

There is always a time alignment problem when working with global data. For example, Nifty closes a day ahead of the S&P for the same closing date. There are two ways to get around this “rolling close” problem:

  1. Shift up the the lagging data to align the times zones.
  2. Instead of using close-to-close, use open-to-close on the data that is ahead.

But how big a problem is this? If the model uses a weekly time-series, how much of a difference would trading on Friday close vs. Monday open make?

Gap Opens

Unfortunately, for the NIFTY, we can only use data from 2011 to analyze opening gaps (Why?) Be that as it may, are Monday opening gaps different from other trading-day gaps?

NIFTY gaps

NIFTY gaps table

MONDAY: gap on a regular Monday after a two-day weekend.
HOLIDAY: gap on a weekday that is not a Monday, but one that opens after a holiday.
DAY_1: gap on a regular day that is not a MONDAY and not a HOLIDAY.

What this tells us is that there is nothing special about a Monday open. On, average, it is just like any other day.

Close-to-Close vs. Open-to-Close returns

The next question is how much of a difference would it make if we traded at the close and held our position over the weekend vs. buying at the open on Monday?

Comparing Close-to-Close (c2c) vs. Open-to-Close (o2c) is tricky because the holding period of the latter is considerably shorter than the former. Nevertheless, here are cumulative returns of buying on Friday close and selling on Monday close vs. buying on Monday open and selling on Monday close:
Buying NIFTY on Friday close and selling on Monday close vs. buying on Monday open and selling on Monday close

What about holding over a holiday?
holding NIFTY over a holiday

And, lastly, holding overnight vs. over a single trading day:
holding NIFTY overnight vs. over a single trading day

The above charts indicate that there is a big difference in holding positions overnight vs. buying at the open.

Volatility at Open vs. Close

The opening and closing prices are computed prices. Actual traded prices could vary based on market conditions. The last question that needs to be answered before choosing between trading at the open vs. the close is how different is the market at the open vs. the close?

To answer this question, lets take the on-the-run NIFTY futures and plot the summary metrics of its returns over the first half-hour and the last half-hour of trading:
NIFTY first 30 minutes
NIFTY last 30 minutes

There seems to be no glaring difference. The drift between traded prices and the published open/close should be about the same whether you trade at the open or at the close.

Take-away

All things considered, there is a net benefit in not carrying over positions over the weekend. So, in theory, a global macro model using weekly time-series could be run over the weekend – positions opened on Monday at the open and closed on Friday at the close – and the “rolling close” problem can be ignored when trading the NIFTY.

Related: Trading turnover throughout the day
Code is on github.

USDINR and Dollar Indices, Part IV

Please read Part I for the introduction, Part II for a study of the spread between USDINR and the dollar indices and Part III for a spread-trading back-test on daily returns.

Weekly vs. Daily

In our previous posts, we used daily returns to setup the analysis. However, analyzing daily series on currencies and commodities is problematic. They trade 24/7 in a global marketplace and “closing” prices for commodities and currencies are hard to pin down at a granular level across markets. One way to ameliorate this issue is to use a weekly or a monthly series instead.

Here are the plots of the spreads and p-values from the adf-tests applied to weekly returns:
USDINR.DTWEXB weekly spread
USDINR.DTWEXM weekly spread
USDINR.DTWEXO weekly spread

The back-test results mirror that of the daily series, with bets on momentum carrying through on the USDINR and DTWEXM pairs:
USDINR weekly spread trading backtest

This gives us more confidence in our back-tests. We end our series with the following caveats:

  1. Trading the spread involves trading both legs (as discussed in Part III.)
  2. One can only buy a currency by selling another. i.e., buying USDINR implies going long USD and short INR.
  3. Using the above analysis, if a trade involves buying USDINR in one of the legs, it does not inform anything on relative valuation of USD or INR.

Code and charts on github.

USDINR and Dollar Indices, Part III

Please read Part I for the introduction and Part II for a study of the spread between USDINR and the dollar indices.

Trading the spread

In Part II, we defined spread = A – βB. When we say “trade the spread” we literally mean going long or short the spread as defined. To actually implement the trade, one would have to create two legs: one that is long USDINR (A) and the other that is short β times one of the dollar indices (B). Since the dollar indices are not something that can be actually traded, the following back-tests are purely a theoretical exercise.

Back-test

We consider three scenarios:

  1. C1: if the spread diverges beyond 1-sigma, bet on mean-reversion.
  2. C2: if the spread diverges beyond 1-sigma, bet on it getting bigger.
  3. D1: if the spread is between the average and 1-sigma, bet on it blowing out.

The first one is pure convergence and the last one is pure divergence. The second one is sort of like momentum – if the spread is already beyond 1-sigma, bet on it further blowing out.

USDINR spread-trading backtest

It appears the second scenario, the one that bets on momentum carrying through, is the most profitable. Also, the most profitable pair seems to be USDINR and DTWEXM (Trade Weighted U.S. Dollar Index: Major Currencies).

In the last part in this series, we will run through this analysis for a weekly time-series of these indices.

Code and charts are on github.

USDINR and Dollar Indices, Part II

Please read Part I for the introduction.

In Part I, we saw that if we force the intercept to be zero during linear regression between two series A and B, we end up with A = βB. In this post, we go one step further and define spread = A – βB

Pair trading

Readers of our posts on pair trading will immediately recognize the above relationships. The idea here is that if we assume USDINR to be dependent on DTWEXB, DTWEXM and DTWEXO indices, then we:

  1. calculate the spread between USDINR and each of the indices in turn,
  2. check if the spread is ‘stable’ by conducting an adf test on the residuals of the linear fit and checking if the p-value is less than a threshold,
  3. if the p-values confirm stability, then we can go long/short the spread whenever it deviates from the mean.

Spreads

When we plot the spreads and p-values, we see that a 50-day period is probably the most suitable time-frame over which to calculate the spread. And, we also observe considerable mean-reversion suggesting that a trading model can be built over it.
spread between USDINR.DTWEXO
spread between USDINR.DTWEXM
spread between USDINR.DTWEXB

In Part III, we will back-test a couple of trading models based on these spreads.

Code and charts are on github.

USDINR and Dollar Indices, Part I

The St. Louis Fed publishes a number of economic and financial series on its Federal Reserve Economic Data (FRED) database. It is a treasure trove of information for quants. There are a number of currency related time-series in the database. In this post, we will plot the USDINR exchange rate with the trade-weighted indices available on FRED to explore any relationships that there might be between them.

Trade-weighted indices

A trade-weighted dollar index is simply the weighted average of the foreign exchange value of the U.S. dollar against the currencies of a group of U.S. trading partners. The FRED publishes the following such indices:

  1. DTWEXB: Includes the Euro Area, Canada, Japan, Mexico, China, United Kingdom, Taiwan, Korea, Singapore, Hong Kong, Malaysia, Brazil, Switzerland, Thailand, Philippines, Australia, Indonesia, India, Israel, Saudi Arabia, Russia, Sweden, Argentina, Venezuela, Chile and Colombia.
  2. DTWEXM: Includes the Euro Area, Canada, Japan, United Kingdom, Switzerland, Australia, and Sweden.
  3. DTWEXO: Includes Mexico, China, Taiwan, Korea, Singapore, Hong Kong, Malaysia, Brazil, Thailand, Philippines, Indonesia, India, Israel, Saudi Arabia, Russia, Argentina, Venezuela, Chile and Colombia.

Additionally, they also publish the DEXINUS series that is the USDINR exchange rate.

These series go back to the mid-70’s and mid-90’s. However, India was a closed economy with a managed currency for the most parts. So for the rest of this post, we will consider data only from 2005 onward.

Here is how the time-series looks:
FRED DEXINUS-DTWEXB-DTWEXM-DTWEXO indices

Beta between USDINR and the rest

What we are interested in is the relationship between USDINR and the rest of the trade-weighted averages. DTWEXB and DTWEXO have India exposure with the latter made up predominantly of emerging markets. So we should expect a high beta between USDINR and those.

To calculate the beta, we will fit a linear model through USDINR and each of the trade-weighted indices in turn. Also, we will force the intercept to be zero to force the fit.

Here are the betas with a 20-day look-back:
20-day beta between USDINR and trade-weighted indices

Here are the betas with a 50-day look-back:
50-day beta between USDINR and trade-weighted indices

The 20-day chart shows that the beta oscillates within a tight band for the most part. This insight can be used to build a mean-reversion model for USDINR.

In Part II, we will explore the spread between USDINR and all three of the indices. Stay tuned!

Code and charts are on github.