Category: Your Money

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.

Basis Trades using Futures

Introduction

When we discussed cash-futures basis, it was pointed out that the fair value of a futures contract is a function of the underlying price, interest rates, dividends and time to expiration. The same logic applies to the fair value of contracts across expiration dates. For example, as of close on April 30, 2015, NIFTY futures contracts had the following values: 8177.35 (April), 8244.05 (May), 8275.30 (June).

Some of our clients wanted us to check if this basis can be traded. Is it possible to profit from going long the near contract and short the far contract on a consistent basis? Before we look at profitability, lets chart the basis.

The basis

Here is how the basis between different contracts look (2000 through now):

NIFTY.futures.basis

Here is the summary statistic of the basis:

summary statistics

Here is the same data with futures expiry dates removed:

summary statistics

With the extreme values removed, we can now check if we can trade the nearest expiry contract with the farthest.

50-day Average Basis Trade Back-Test

Lets take a look at the Near vs. Farthest basis and draw a 50-dma through it:

NIFTY.futures.basis.50dma

The basis is not stable and what’s worse, it appears to be trending. Lets try our simple trading rule: go long the basis if it is above 50-dma and short if otherwise.

Here’s how the back-test works out (2005 through now):

NIFTY.futures.basis.50dma.trade.2005

Lets check the back-test on a smaller subset (2010 through now):

NIFTY.futures.basis.50dma.trade.2010

A ~20% profit in a 10 year time-frame is barely enough to cover transaction costs. Besides, it looks like the strategy hit a wall in 2010.

Conclusion

It appears that the basis trade described above is not profitable enough after considering transaction costs and taxes. Also, whatever meager profits were there seem to have been arbitraged away lately.

Is there a correlation between USDINR and Tech stocks?

tl;dr

No.

The Myth

Regular viewers of CNBC might have heard the refrain that “IT stocks went up because the rupee went down.” But it turns out that it is the classic case of the journalist/reporter/anchor going in search of a reason to explain a random market event. If there is such a correlation, then a scatter plot of USDINR returns vs. CNX IT index returns should unearth it.

Scatter Plots of Returns

Weekly:
CNX IT.USDINR.scatter.weekly

Daily:
CNX IT.USDINR.scatter.daily

As you can see, there is no obvious link between USDINR and technology stocks. But what if the effect manifests after a lag?

Cross-Correlation Plots of Returns with Lag

Weekly:
CNX IT.USDINR.ccf.weekly

Daily:
CNX IT.USDINR.ccf.daily

Conclusion

Currency moves alone cannot be your go-to explanation for fluctuations in tech stocks.

Monthly Recap: Good investing hurts

world.2015-03-31.2015-04-30

Equities

Major
DAX(DEU) -4.28%
CAC(FRA) +0.26%
UKX(GBR) +3.14%
NKY(JPN) +1.69%
SPX(USA) +1.41%
MINTs
JCI(IDN) -7.83%
INMEX(MEX) +1.82%
NGSEINDX(NGA) +9.31%
XU030(TUR) +3.34%
BRICS
IBOV(BRA) +9.54%
SHCOMP(CHN) +18.51%
NIFTY(IND) -3.65%
INDEXCF(RUS) +3.82%
TOP40(ZAF) +4.73%

Commodities

Energy
WTI Crude Oil +23.33%
Ethanol +7.84%
Heating Oil +15.86%
RBOB Gasoline +14.75%
Brent Crude Oil +19.90%
Natural Gas +4.57%
Metals
Copper +6.91%
Palladium +5.40%
Gold 100oz -0.37%
Silver 5000oz -3.01%
Platinum -0.82%

Currencies

USDEUR:-4.08% USDJPY:+0.18%

MINTs
USDIDR(IDN) -0.96%
USDMXN(MEX) +1.88%
USDNGN(NGA) -0.62%
USDTRY(TUR) +4.23%
BRICS
USDBRL(BRA) -6.36%
USDCNY(CHN) +0.06%
USDINR(IND) +1.48%
USDRUB(RUS) -10.79%
USDZAR(ZAF) -0.61%
Agricultural
Cocoa +4.00%
Coffee (Arabica) -0.94%
Coffee (Robusta) +1.94%
Cotton +4.63%
Soybean Meal -3.44%
Corn -4.25%
Lean Hogs +22.47%
Lumber -8.52%
Orange Juice -8.61%
Soybeans -0.44%
Sugar #11 +7.58%
Feeder Cattle -2.02%
Wheat -8.19%
Cattle -7.48%
White Sugar +4.89%

Credit Indices

Index Change
Markit CDX EM +3.58%
Markit CDX NA HY -0.55%
Markit CDX NA IG -2.44%
Markit iTraxx Asia ex-Japan IG +7.09%
Markit iTraxx Australia +6.74%
Markit iTraxx Europe +9.57%
Markit iTraxx Europe Crossover +1.39%
Markit iTraxx Japan -3.23%
Markit iTraxx SovX Western Europe +2.17%
Markit LCDX (Loan CDS) -0.11%
Markit MCDX (Municipal CDS) +1.70%
Both the NIFTY and the rupee put in performances that they sooner forget. Stretched evaluations met a tepid earnings season and retroactive tax demands on FIIs. May will see more firms coming out earnings and we expect the markets to remain choppy.

Nifty Heatmap

CNX NIFTY.2015-03-31.2015-04-30

Index Returns

For a deeper dive into indices, check out our weekly Index Update.
index performance.2015-03-31.2015-04-30

Market Cap Decile Performance

Decile Mkt. Cap. Adv/Decl
1 (micro) +3.97% 82/50
2 +10.85% 82/49
3 +7.66% 78/53
4 +6.24% 68/64
5 +4.32% 72/59
6 +2.89% 68/63
7 +2.84% 71/61
8 -2.06% 66/65
9 -3.55% 64/67
10 (mega) -2.64% 58/74
This doesn’t make any sense…

Top Winners and Losers

UPL +10.97%
GLENMARK +13.25%
TATASTEEL +13.76%
APOLLOHOSP -16.95%
WIPRO -14.35%
SRTRANSFIN -12.97%
A smorgasbord of performance…

ETF Performance

GOLDBEES +3.56%
PSUBNKBEES +2.07%
BANKBEES +1.54%
JUNIORBEES -0.62%
CPSEETF -2.15%
NIFTYBEES -3.29%
INFRABEES -5.49%
Infrastructure got whipped…

Yield Curve

yield Curve.2015-03-31.2015-04-30

Bond Indices

Sub Index Change in YTM Total Return(%)
GSEC TB -0.09 +0.66%
GSEC SUB 1-3 -0.60 +0.25%
GSEC SUB 3-8 +0.04 +0.20%
GSEC SUB 8 +0.16 -0.07%
Listless…

Investment Theme Performance

Equity Mutual Funds

Bond Mutual Funds

Thought to sum up the month

Good investing hurts. Investors pay a high price for comfort and get paid a high price for doing what few others will. That will always be the case.

Source: This Was Never Easy

Weekly Recap: May Day

world.2015-04-24.2015-05-01

Equities

Major
DAX(DEU) -3.02%
CAC(FRA) -2.98%
UKX(GBR) -1.20%
NKY(JPN) -2.44%
SPX(USA) -0.49%
MINTs
JCI(IDN) -6.42%
INMEX(MEX) -1.97%
NGSEINDX(NGA) +0.64%
XU030(TUR) -1.90%
BRICS
IBOV(BRA) -0.74%
SHCOMP(CHN) +1.09%
NIFTY(IND) -1.49%
INDEXCF(RUS) +0.34%
TOP40(ZAF) -1.57%

Commodities

Energy
Heating Oil +3.51%
Ethanol -0.06%
Brent Crude Oil +2.61%
Natural Gas +9.66%
RBOB Gasoline +2.36%
WTI Crude Oil +3.93%
Metals
Gold 100oz +0.07%
Palladium +0.62%
Copper +6.91%
Platinum +0.85%
Silver 5000oz +1.90%

Currencies

USDEUR:-2.96% USDJPY:+1.06%

MINTs
USDIDR(IDN) +0.20%
USDMXN(MEX) +1.01%
USDNGN(NGA) -0.26%
USDTRY(TUR) -0.40%
BRICS
USDBRL(BRA) +1.68%
USDCNY(CHN) +0.14%
USDINR(IND) -0.22%
USDRUB(RUS) +1.76%
USDZAR(ZAF) -0.36%
Agricultural
Cocoa +0.61%
Coffee (Arabica) -7.30%
Coffee (Robusta) -3.84%
Cotton +1.74%
Cattle -7.32%
Lean Hogs +6.12%
Lumber -1.59%
Orange Juice -0.83%
Soybeans -0.05%
Sugar #11 -1.75%
Feeder Cattle -0.68%
Wheat -3.04%
White Sugar -0.35%
Corn -1.17%
Soybean Meal +0.13%

Credit Indices

Index Change
Markit CDX EM -0.13%
Markit CDX NA HY -0.15%
Markit CDX NA IG +1.38%
Markit iTraxx Asia ex-Japan IG -0.23%
Markit iTraxx Australia +0.03%
Markit iTraxx Europe +0.76%
Markit iTraxx Europe Crossover +7.53%
Markit iTraxx Japan +0.72%
Markit iTraxx SovX Western Europe -0.02%
Markit LCDX (Loan CDS) +0.00%
Markit MCDX (Municipal CDS) -0.41%
Are world markets prepping for “sell in May and go away?”

Nifty Heatmap

CNX NIFTY.2015-04-24.2015-04-30

Index Returns

For a deeper dive into indices, check out our weekly Index Update.
index performance.2015-04-24.2015-04-30

Sector Performance

sector performance.2015-04-24.2015-04-30

Advance Decline

advance.decline.line2.2015-04-24.2015-04-30

Market Cap Decile Performance

Decile Mkt. Cap. Adv/Decl
1 -8.22% 64/68
2 -5.11% 56/75
3 -5.87% 50/81
4 -3.93% 57/74
5 -4.40% 62/69
6 -3.90% 61/70
7 -3.51% 56/75
8 -4.70% 64/67
9 -4.26% 59/72
10 -1.21% 70/62
An ocean of red, nary a green in sight…

Top Winners and Losers

MOTHERSUMI +7.93%
SIEMENS +10.80%
UPL +12.87%
UBL -12.70%
APOLLOHOSP -12.21%
ITC -7.36%
What’s next for ITC?

ETF Performance

BANKBEES +2.20%
GOLDBEES +1.00%
JUNIORBEES -0.71%
NIFTYBEES -1.19%
PSUBNKBEES -1.47%
CPSEETF -2.27%
INFRABEES -3.91%
Have banks found a bottom?

Yield Curve

yield Curve.2015-04-24.2015-04-30

Bond Indices

Sub Index Change in YTM Total Return(%)
GSEC TB -0.18 +0.18%
GSEC SUB 1-3 -0.04 +0.34%
GSEC SUB 3-8 -0.00 +0.26%
GSEC SUB 8 +0.02 +0.12%
Rates went down a smidgen…

Investment Theme Performance

Magic Formula turned into Tragic Formula thanks to the cliff dive in KPIT stock. But the specks of green may be indicating that the current correction is on its last legs…

Equity Mutual Funds

Bond Mutual Funds

Thought for the weekend

The issue of inequality has never been about the fairness of the results, but should focus on the equality of opportunity.

The neo-classical solutions that the markets will take care of everything risks the kind of social instability seen in places like Ferguson, Baltimore, or worse.

You can use comparative advantages, such as low labor costs and convenient geographic proximity to markets, to spur development. But the Porter-Jacobs framework doesn’t explain why India and China succeeded and Kenya and Egypt didn’t.

You are left with culture: both the Jews and the Romani (Gypsies) have historically been outcasts in Europe. How did one group succeed and acquire power (e.g., the Rothchilds) and the other remains shunned throughout the region?

Source: May Day thoughts on inequality (and development)