Tuesday, June 30, 2015

Back-Testing Systematic Strategies Part 1: A Flow Chart Based Approach

Systematic trading brings on a certain discipline and the advantage in terms of risk management that comes along with it. And with today's cheap computing power, it is available to anyone. A proper back-testing is almost always at the core of a systematic trading strategy. A wisely designed back-test is the litmus test for an investment hypothesis. At the same time, it helps in sizing the trades and risk management given a particular ability and appetite to take on risks.

However, for the individual traders and investors who has developed market insights over the years, but not very familiar or eager or able to get their hands dirty with coding, running a back-test with dependable results can be a huge headache. Here I try to show how we can approach this problem in a structured manner.

The very essence of back-testing is defining some rules of trading (buy or sell signals) and risk management (stop loss or take profit etc.) based on a market price (of the instrument we are trading) and probably some more indicators (which can be as simple as a technical indicator, or a complex function defined by the user). The R package quantstrat handles this problem in a very well defined manner and split the functionalities in different blocks or modules so that designing a back test, running the strategy and analyzing the data all becomes simple and modular. We take a simple example of running a intraday momentum strategy on the National Stock Exchange flagship index NIFTY50 to highlight this point.

The core strategy we want to back-test is simple. Every trading day we wait for a certain amount of time (or price bars) after the market opens to see the initial momentum. If the open is positive (negative) beyond certain threshold, we then go long (short). Before the end of the trading day we square-off the position. Optionally we can also add a stop loss and take profit target. 

Thinking backwards, the back-test will be driven by our buy and sell trading rules and square-off rule. In turn they will be generated based on:

a) if the opening price criterion meets the condition and 
b) if we are at the beginning of the day, and finally 
c) if we are approaching end of day to place square off. 

This in turn means, the signals that need to go in is: 

i) a price move indicator for positive move
ii) a price move indicator for negative move
iii) a start-of-day indicator and 
iv) an end-of-day indicator

We would need i) and iii) both to be true (logical AND) for a buy signal, and ii) and iii) for a sell signal. The indicator iv) is enough to drive square-off. Schematically, the entire scheme looks below


And if we can design this schematic logically, in terms of a simple, easy to understand flow chart as above, it becomes rather straight forward to develop the underlying codes to run the strategies. As an example I ran the strategy for 2-minute bar of intraday data since 19th of May to 26th of June, and here are the results with different combinations (with 100 units for buying or selling for each trade).



For the underlying strategy without any stop-loss and take profit targets, the trade positions and evolution of profit and loss looks as below (click to enlarge).


And once we run the back-test, we can further delve in to the details and analytics, like the chart below which plot the Maximum Adverse Excursion plot for the base strategy
In short, a very simple strategy, quickly designed in to a simple flow charts. The back test shows it really works, and also throws lights on how to size the trades given your investible capital and risk tolerance.

We will further follow up on how to translate any back-testing in to a similar flow chart, which enables quick and reliable back-testing.

(Those who are interested in the underlying code, it is available here.)

Monday, June 29, 2015

European Debt Crisis Redux: The Monday After


Here is how the world market reacted on Monday to the recent development in Greece
 
 
 
It is risk-off but to a moderate degree. As expected, Portugal has been hammered the most.
 
From now on, it is a question of how the politics play out till coming Sunday. Most probably most European institutions and political leaders will frame the referendum question as a in or out options for Greece. If the Greeks vote for a YES, that will probably lead to a topple for the current government, followed by a hasty coalition to pass through the extension deal, and perhaps an election later on. This is the central scenario. If the vote is NO then brace for the real stuff. According to media reports, a considerable portion of the Greek people are yet to reconcile the fact the staying in the Euro Zone and rejecting the current package is mutually exclusive. How the vote will turn out will depend on this starting numbers, and more crucially 1) how the Greek government pose the referendum question to their people and 2) The reaction of the core politics towards this over rest of this week.
 
And as usual, Euro is acting quite opposite to general expectation.

Friday, June 26, 2015

Trade Idea: How To Play the Fed Hike in the Short End

In case you have missed the latest piece from the very useful IMFDirect blog , I suggest you pay a visit.
 
The basic argument is what I have been pointing out. The data driven stance of the FOMC for future rate hikes DOES NOT guarantee a given lift-off date, and more importantly not a steady 25bps per quarter hikes we have seen in past hike cycles. Fed will perhaps hate to reverse hiking once it starts, but I do not think they will hesitate to hold (with proper communication). And that makes the case more important. From the piece above:
The paper finds that—under conditions of still recovering demand, low inflation, and the policy interest rate near zero—the balance of risks favors more patience to start interest rate increases. The consequence of such a policy would still mean gradual, albeit slightly steeper, path of subsequent rate increases and a modest planned overshooting of inflation.

 
See the chart below (from IMF blog)
 
 
 
In case you accept this, that means, we may have some interesting move in the short end of curve once market stop obsessing about the lift-off date and start pricing in the reality. I suggest trading a 3y2y vs. 2y2y steepener in the midcurve space. Buy 1y2y2y payer vs. selling 1y1y2y. This has a fantastic carry (around 6 times the delta risks) mostly coming from the curve roll down. The market prices a large hike in 2y between Dec 16 to Dec17 than between Dec17 to Dec18. If the above theory holds this is going to correct. The trade is mostly flattish on parallel moves.
 
The 3y2y vs. 2y2y slope bottomed out at around 25bps back in Jan and rising since then, currently 40ish. The recent peak was 108 just after the sell-off during 2013 Taper tantrum.

Wednesday, June 24, 2015

European Debt Crisis Redux, (And Other Things)


Very recent news flows has not been very positive from the Greek Bailout negotiations.
 
In this context, it is interesting to re-run the kind of analysis every one had tattooed on their forehead back in 2010 and again in 2012. Sovereign debt ownership, focusing on the southern block.
 
Portuguese bonds market ownership is quite dominated by foreign players. According to Bloomberg, banks and insurance companies own around 16% of total outstanding, of which around 13% is foreign owned. Another approx 7.5% belongs to the asset managers, which is mostly foreign. So total approximately 20% owned by foreign players, who can become jittery in case of an unexpected outcome in Greece. For Italy, total banks and insurance own 25% of outstanding, but only 7% foreign owned. Another 6% spread among asset managers without much concentration. Similar figures for Spain is around 8% for banks and insurance, and another 2% from asset managers, so around 10%.
Portugal GDP is not in the momentum we see in Spain (not even Italy). On the other hand, unemployment is far better and both have elections coming up this year. Incidentally we have seen a lot of spread tightening in Portugal bonds compared to both Italy and Spain since middle of this month.
 
Definitely something to watch out for.
 
Separately, the data flows from UK on the other hand has been solid lately. An august hike? Not likely, but BoE cannot trail the Fed for long. We have a slight re-pricing of Fed hike towards Mar 16, and BoE is priced in around Jun 16. Fair, possible. But what is surprising is the spread of the real rates. Historically the US and UK inflation spread has been on an average 0bps since 90s till before the Crisis, and 120bps for last few years. Sure Euro area can be a drag, but while US real rate is now around zero, UK is still firmly negative, around -65bps in 10y (taking differences of the nominal swap rates and the breakeven inflation swap rates). Markets prices US inflation much higher than UK. Although both shows strong labor market (perhaps UK with a stronger momentum). Expect a correction. Especially if you believe in the Euro area turning corner.

Tuesday, June 16, 2015

Euro: the New Yen?

In terms of carry trade it already is. We are not talking about that.

We are talking about a currency that rallies in risk off and sells off in a risk on mode. It has shown some strange correlation.

And it is not one off in this year itself, if I remember correctly. I discussed it some time back here.

More or this later. But it might well be the case.


Sunday, June 14, 2015

Week Ahead: June 15 to 19

Front running for the week

Euro area - Wednesday CPI reports, followed by ECB bulletin on Thursday and Euro group meeting where Greece will be a hot topic.

US - Empire state on Monday, and capacity utilization, followed by FOMC 16-17. Thursday CPI from BLS as well as Philly Fed. 

UK - PPI and RPI on Tuesday, followed by MoM of BoE and labor data on Wednesday and retail sales on Thursday. 

Japan - BOJ on 17

Overall, there is enough data points to keep the vol machine churning. UK core CPI has been running below survey expectation for a full year now. So upside will be something to watch out for. Also, in EU the core CPI is much more volatile than US and UK. Last print was spectacular, and looks like we may be in for some corrections downwards. And Fed is expected to reiterate the data driven policy. 

Technically, Euro rates, esp 10y does look oversold, and so is SEK rates. A bad CPI print of euro zone will lead to a correction. However, not to the levels seen in April perhaps. And seems overall the GBP rates are trading rich compared to Euro and USD, which not in complete sync with USD/GBP. So is the case for vols, where EUR looks a tad too pricey compared to sterling (and even dollar). Although recent data has not been particularly strong from the Queen's land.

On the equities side, last week has been soft. VIX remains around 3 points above the 5 year low. The recent vols in FX and rates has failed to budge any excitement in Equities.

Friday, June 12, 2015

EUR/USD vs Bunds: Broken Lock-Step?

strange correlation in the market today. Ever since Draghi's "get used to volatility" speech, EUR/USD and bunds on Eurex tracked each other in the usual direction, EUR/USD rallying with Bunds sell-off.

 
 
 
Some thing is different today, with the correlation flipped. The Euro selloff matched with Bunds selloff and after US PPI data, the correlation stayed positive. It is not obvious what caused this sign change. Euro rallied in general along with most other currencies, so probably Bunds not leading Euro.
 
 

Whichever way it is, it makes sense to stay short Euro overnight. It is hard to see we will have some great news on the Greece negotiations over the week end with everyone pushing the deadline to 18th Euro Finance Ministers meetings. But we can always have further bad news. The day to watch, however, will be the inflation prints for UK and Eurozone early next week. Any great print, we will see a firm rally in Euro and Bunds will be back in steps with the usual correlation.

Tuesday, June 9, 2015

Rates Sell-Off | The Skew That Was

As expected (see here), since last month we have seen a spectacular return of vols in rates. Definitely helped by ECB's Draghi's comment. From lowly 40s in April, 3m10y straddle in EUR now trading @ 81 normal bps vol, with half of it coming off in last two weeks. And in spite of that, on realized basis, you can hardly call any part of gamma surface rich to buy, convincingly. This will of course retrace from here to some level down, but this increased vols are here to stay for rates for a while.
 
What is interesting, how this sell off has played out in the skew space. The skew exploded across tenors in the gamma space. However, the pattern that emerges across the surface on closer look is more nuanced. On 5y and 10y tails, the realized skew is steeper on the payer side as well as has a parallel shift to a higher vol at the money. Whereas on the longer end it is more about getting the slope wrong, i.e. receivers are cheaper and payers are richer in realization. And as we walk across the maturities, the realized skew simply fail to live up to the expectation priced in implieds (click to enlarge)
 
 
 
This means receivers on the 30y is rich, payers on intermediate and Vega rich, and these are true more for USD than EUR.