Monday, August 24, 2015

Equity Sell-Off : Looking Back

Histogram of S&P 500 one-month (20 days) move following a 3% or more sell-off, since 1960s. This shows historical probabilities of a recovery or a worsening sell-off during the next month, conditional on a 3% or worse sell-off today. Index is scaled to start at 100 after the first down move on day 1.

The worst 5 recoveries are all in 2008 Sep to Oct, except once in 1987 flash crash. The best 5 recoveries are mixed across time.
The cumulative probability of continued sell-off is 37.5%, Cumulative probability of 5% or more recovery is approx 40%. Median move is 1.9% rally. On cases we had further sell-off, the median sell-off is 6.6%, The median for rally case is 5.6% (so the distribution is skewed, as obvious from above). However, this skew disappear if you take out the tumultuous period of 2008 following the Lehman Brother failure. In that case the moves are slightly positively skewed, 4.6% sell-off vs. 5.4% rally. Also the cumulative sell-off probability drop is around 30%

But with all hard numbers, it is hard to keep calm when everyone else is in panic mode. 

Saturday, August 22, 2015

Macro: The Total Perspective Vortex

What is driving the risk markets? Minimum Spanning Trees for risk assets below.

For global equities (based on correlation since Jan 2015)
And for global FX (based on correlation since May 2015)

Yes. A rather rhetorical question.

Friday, August 21, 2015

Trading Places: The Eagle and the Dragon

The question is: if China becomes US in 2008, can US play the role of China in 2008?

What are the bazookas the Fed left with that would really impress the market in such an event? Buying risky assets (i.e. equities) is a potential candidate. What else?

Wednesday, August 19, 2015

Further on China

As usual, a very good piece from Michael Pettis on China. Must read if you have not already.

Somewhat in line with my previous posts on this (esp the motivation behind the devaluation, the risks of capital flight and the re-distributive nature of different choices, see here and here). He does not talk much about risk assets though.

Monday, August 17, 2015

Note to Self: China M-Policy Choices

Which one is better?

Maintaining a dollar peg, while easing policy rates to counter peg-induced tightening? And promising Yuan will perhaps appreciate from here? In short, ask the savers to suffer, the conscientious borrowers to pay down the debts, the risk takers to continue their carry trades and corporate sectors to go fend for themselves.

Or let the currency adjust, and support with policy easing. Market mayhem and overshoot for a while. In the end it dies down. Effectively take money from importers/ foreign currency borrower and would-be tourists and give it all to exporters and foreign currency lenders. Kill the carry trade (and traders). The downside is huge vol now, and a very hard time convincing the markets if you need the peg ever in future (fool me once etc.). The outcome hinges on credibility and strength of FX reserves entirely.

Lastly, let the devaluation drag on a little at a time. Highly credible. Less volatility, and that too most of it elsewhere (EM). Pernicious if "no further devaluation" not credible, as expectation of further devaluation put pressure on capital outflow. The entire thing gets leverage out of the Impossible Trinity, potentially ending similar to above, but with PBOC looking like a fool.

Most agree CNY is overvalued. If PBOC does a full devaluation at one go closer to the fair value and promise no further action, most will be willing to believe. The question is can they? With Fed yet to decide, and other central bankers yet to see the market response, it is hard to see what is full devaluation.

There is a chance of a further devaluation in CNY once the Fed is done with their move. This present one was perhaps an unwanted and ineffective decision. Or PBOC's way of testing market reaction/ warning market participants. Or PBOC trying to fore-warn the Fed. Or whatever.

Take your pick.

Sunday, August 16, 2015

Systematic Strategies: HIgh Probability Trading Under Uncertainities

Stop-loss and take profit orders are powerful tools to manage an underlying trading view. And there are some misconceptions about them. Many people believe take-profit and stop-loss limits define the risk-reward ratio of a strategy. Far from it.

If a strategy has 100 on the upside as take-profit and 50 on the downside as stop-loss it is preposterous to estimate the risk-reward as 2:1. The most important input missing here are the probabilities of hitting the take-profit and stop-loss limits. For example if the probability of hitting the take profit in the trading horizon is 20% and hitting the stop-loss is 50% (i.e. the underlying can be within the range with a probability of 100% - 20% - 50% = 30%), then expected upside is 20%*100 = 20 and downside is 25. And the real risk-reward is 20:25 i.e. 4:5, far from the 2:1 before.

We can use this powerful tools and this concept of probabilities to devise profitable strategies under uncertainties. For example, suppose the underlying view is long an asset. Let's assume the asset follows a (geometric) Brownian motion (in real world) as below

dS/S = drift*dt + vol*dW

Where dt is differential of time, and dW is the standard Brownian Motion. So according to our view, here the drift is a positive value (the underlying view is long). One way to position for this is to go long and unwind at the end of the trading time horizon (let's say 1 day). The probability of our position being in profit can simply be calculated from a Black-Scholes like digital call option price.

However, another way is to put a take-profit order. This order gets executed whenever the underlying breaches the target from below. The probability of this execution is the probability of the underlying Brownian motion breaching the barrier any time up to our trading horizon. There are standard approximate solutions to this problem. For example, see here (opens PDF). As an example I have plotted the ratio of this probability to the original Digital probability (i.e. being in the money at the end of trading horizon, irrespective of what happens in between) for a range of volatility and Sharpe ratios (ratio of the drift term above to volatility) in the chart below.
As you can see, the probabilities of hitting our profit target intraday is much higher than being in the money end of the day. Additionally, higher the uncertainties about the underlying trend (lower the Sharpe) this ratio works better in out favor. This shows clearly that if your view is not with high conviction, it is better to use a take-profit target than a buy-and-hold approach.

This gives rise to an interesting way to implement a short-dated view using options. The strategy is to buy an option (say a ATM call option to implement a long view on the underlying) and put a close take-profit target, and a wide stop-loss. The worst-case loss is the option premium. And we will hit out target with 1.2x to 2x more frequently, depending on the strength of the trend. By design it may appear we have a skewed risk to reward ratio here. But given the concept of probabilities (than just the width of the stops and targets) and the convexity of a long option position this is much less risky than it appears. None-the-less it is a skewed strategy, with high probabilities of hitting our profit targets regularly, and occasional large losses.
The chart above shows the expected profit ranges for such a strategy on the NIFTY index (the flagship index of National Stock Exchange, India). The Spot level assumed to be 8500. The profit-target is 1x the daily vol move and the stops are 2x of that. (Note this is approximated, i.e. I ignored the order of stop-loss and target hitting, which is valid for large enough stops). As you can see if you are somewhat certain about the direction of the underlying trend, this is quite profitable (the break-even here is daily trend is 40% or more of the daily vol) under high vol. The profit distribution as below (click to enlarge)
This ignores two realities -1) the convexity of the option position, which goes in our favor and 2) the jumps in stock moves (price moves are rarely Brownian), which goes against us (the probabilities should get affected symmetrically, but the size of loss makes it asymmetric).

Those interested in the underlying codes (in R) can find it here.

Tuesday, August 11, 2015

Note to self: The "Surprise" Part of Yuan Devaluation

A little yuan devaluation created a strong reaction in markets around the globe. A less than 2% devaluation in CNY is not probably going to make Chinese companies overnight super-competitive in exports - they already are reportedly, and CNY is still way below recovering its appreciation against USD for last two years. Nor the foreign investors will worry about a 2% hit in their portfolio. The swings in Chinese equities demand their undivided attention. And no way this is going to spiral in to a currency crisis in a typical EM style with large external debt. This has a mere ~USD 20 Billion impact on Chinese external debt, even if you assume the entire pot is dollar denominated. That pales in comparison to recent capital outflows from China.

The surprise move is rather across global equities - which according to Bloomberg are selling off because of these Chinese incident.

Seriously? Germany has a large CA surplus against China, so yes, DAX should get a hit, UK has a large deficit, so FTSE should go up? Oh wait, what about less Chinese tourists, of course. Rhymes and reasons.

This is China trying to get more market in FX fixings, perhaps with an eye for SDR node from IMF. This has nothing to do with export competitiveness, or currency wars or anything.

What will be more worrying, indeed, if this has got anything to do with recent large capital outflows. If there is a large capital inflow in a country, the local currency should shoot up against dollars. To maintain a peg, the central bank must buy the foreign currencies (and invest in treasuries) and thus inundate the economy with liquidity in local currency. Quintessential Chinese story until very recently. The thing is: this machine runs in reverse for capital outflows. Now in this context, if today's devaluation, recent capital outflows and selling of treasuries by China (presumably the central bank and the sovereign wealth fund) are all related, then there is a little to worry there. In China you never know. But I would still not lose sleep over it.

Sunday, August 2, 2015

Systematic Strategies: A Simple Statistical Pattern Matching Algorithm

Time series pattern matching in finance is an area which borrows from statistical techniques and mathematical tools from various other disciplines to make an educated guess about near term price movement.

The basic idea is simple: Suppose we have data of price evolution for last n periods, and want to know which way it statistically biased to move for the next m period. Given a set of past data, a pattern matching algorithm searches for best-fit n-period samples (matches) from the data sets and analyze statistical properties of next m period. From these information we can make some probabilistic statements about the likely evolution of the price series we are interested in. For most pattern matching algorithms the basic operation is more or less as above. The area they differ is how they define "best-fit" (a measure of fit - i.e. likeliness, or more generally, a measure of difference, i.e. distance) and also how they find the matches (clustering techniques).

One way to define distance is the conventional crow-flight distance (also know as Euclidean distance). To see how this applies to a price time series, assume we have daily data for last 20 days we are interested in. To define the distance from another 20-day sample, we compute the square of differences for each day between the two series (i.e. difference of the first day of first series and first day of the second series) and then sum them up and take a square root. There is a host of ways in which we can measure distance. See here for a list for example.

For picking up the top matches, there are many ways. One popular, and easy to implement, is a method known as k-mean clustering.

Once we have decided a measure suitable for our purpose and way to choose top matches, the rest is easy. We need to define what statistical properties of the matches we are going to assess and how to interpret that and generate a buy or sell signals.

I have here taken an example with NIFTY futures (the flagship index of National Stock Exchange in India) with 1 minute bar data. To illustrate, see the figure below (click to enlarge). Imagine for a given date (1st July here), we see the price movement (the black line) up to a certain time in the day. We need to match this with history (the orange lines) and predict the move today. Finally the green line shows the actual move that realized. Below I describe the scheme of this strategy.

For the statistical parts: I have chosen a distance measure known as Markov Operator distance (see here, opens PDF). This is a bit more suitable for our purpose, as Euclidean distances are sensitive to jagged movements typical in stock price evolution. Also before measuring the distance, I have smoothed the data to filter noises. We can, again, choose from a host of options (any low pass filter will do). I have used a simple kernel regression smoothing. Note, since we are smoothing the data, Euclidean distance measure should not perform particularly bad for us. Lastly for choosing the top matches I stick to k-mean clustering as mentioned above. 

With this scheme, our strategy is simple. We look at the price evolution each day for a given n period. Then match this for daily 1 minute bar data since April 2015 and generate a trading signal based on the statistics of the top matches. Here I have chosen a set of very simple parameters - we buy (sell) if 1) the subsequent returns from the matches are positive (negative), 2) Sharpe ratio is above a certain threshold and 3) the skew (as define by ratio of 90 and 10 percentile move) is above a certain threshold in our favor. The results are as below (click to enlarge).

The graphs shows the performance of the strategy during the late June/ entire July 2015 (total 23 days). The right chart shows performance (profitable move captured) for different n (the period till which we sample each day). For example, since NIFTY starts trading from 9:15 AM, and we have 1 min data, n=100 means we wait 100 mins or till 10:55 AM before taking a decision. As can be seen performance degrades the more we wait. The left chart shows the profit (the round dots) vs max draw-downs and max upside (either end of the sticks) for each trades for n=100.

For a simple strategy, the performance is impressive. Further scope for improvement is 1) to extend scope of pattern search to any n-period time of the day instead of matching only relevant time periods. 2) improving on the distance function or the smoothing techniques. For example Dynamic Time Warp is a candidate here, especially if we extend the scope as in 1. 3) improve optimization in terms of n, the thresholds in Sharpe and skew etc. 4) improve execution in terms of take profit/ stop loss

[Edit 1: for those interested in the code and implementation, you can find it here, pick up the two files on k-nearest neighbor strategy]

[Edit 2: this extends my previous post on intraday momentum back-testing. Technically they are similar, except in the first case we take a simple snapshot to decide a signal, and here we take a certain length of sample to generate a signal]