Wednesday, May 7, 2014

Fama French factors in Indian stock markets

Fama French three factor model has been widely used through out the world to identify risk and returns characteristics of various investment strategies. It uses a three factor approach(contrasted against one factor approach of CAPM) to decompose the returns of stocks into the returns of the market as a whole. These three factors are:
  • Market returns(MKT)
  • Returns of High B/M stocks over low B/M stocks(HML)
  • Returns of small market capitalization stocks over large market capitalization stocks(SMB)
Given these three factors the returns of a stock can be mathematically written as:


Why bother with Fama French?
  • It can be used to measure and control portfolio risk in a more holistic manner as it takes into account two more factors apart from market beta.
  • It can be used to identify the investment styles of various fund managers by regressing the returns of their portfolios on factor returns
  • As investors think differently during different times, behavior of HML and SMB can be used for regime identification and classification
  • The time series properties of these factors can be used to create long short trading ideas to generate alpha

Fama French in Indian context:
The analysis is done using the data from Jan 2006 to Apr 2014. Everyday stocks are sorted based on their market capitalization. Top 200 stocks are picked up for further analysis. This step is done to minimize survivorship bias. Within this list, stocks are once again sorted on their B/M. The difference between the returns of top and bottom quartile of this sorted list is the return of HML index for the day. Similarly sorting based on market capitalization is performed on this list of 200 stocks to generate returns of SMB index for the day. These steps are repeated for all the days to generate the HML and SMB indices. CNX Nifty is used as a proxy for MKT. The following are the performance of these three factors since 2006.


As we can see, these three factors are not independent of each other. Extreme movements in one factor typically correspond with the extreme movements in other factors. An example of this would be the rally of 2009 when high B/M stocks outperformed low B/M stocks. Also during the same time small market cap stocks heavily outperformed large market cap stocks. This means that even a market factor neutral portfolio can be very volatile during sharp moves in markets(as other factor exposure might not be zero). 

Correlations matrix(values significant at 95% levels are marked in orange):


MKT
HML
SMB
MKT

0.46
-0.40
HML


-0.01
SMB




Auto-correlation function(values significant at 95% levels are marked in orange):


Lag 1
Lag 2
Lag 3
MKT
0.05
-0.01
-0.03
HML
0.15
0.06
0.03
SMB
0.07
-0.03
-0.06

It is clear that the factors(in particular HML) show significant positive serial correlation and hence, very likely to exhibit momentum characteristics. This means style ignorant short term reversion strategies can suffer during sharp trends in  these factors.

K-means clustering based stock classification

K-means clustering is one of the simplest techniques used for classification. It partitions n observations into k clusters in which each observation belongs to the cluster with nearest center. Mathematically, K-means clustering tries to find the set of μ such that the following expression should be minimized.
Here d(x,y) is the distance function. Typical distance functions used are squared euclidean, sum of absolute differences and correlation. μi is the center(mean/median as per the definition of distance function) of the observations in Si.

In line with my previous post on Factor analysis based stock classification, we will attempt to classify stocks into groups to uncover hidden trends if any exists.

Classification of LIX15 stocks:
LIX15 is an Indian equity market index that consists of 15 highly liquid stocks traded on NSE. The observations matrix consists of normalized daily returns of these 15 stocks sampled from February to November 2013. K-means clustering is applied on the data using squared euclidean distance function. Following is the result of a two cluster classification:

Cluster 1
Cluster 2
AXISBANK
CAIRN
BANKBARODA
MCDOWELL-N
HINDALCO
TATAMOTORS
IDFC

JINDALSTEL

JPASSOCIAT

JSWSTEEL

MARUTI

RCOM

SBIN

TATASTEEL

YESBANK


The result are clusters with disproportionate size and non obvious interpretations. Interestingly enough the stocks in cluster 2 are the stocks which do not show any significant loading on factors during the factor analysis. Hence prima facie k-means has classified LIX15 constituents into two groups, one that moved with the broad market and the other which exhibited heavy idiosyncratic movements during the analysis period. Following is the outcome of a three cluster classification:

Cluster 1
Cluster 2
Cluster 3
CAIRN
AXISBANK
MCDOWELL-N
HINDALCO
BANKBARODA
TATAMOTORS
JINDALSTEL
IDFC

JPASSOCIAT
MARUTI

JSWSTEEL
SBIN

RCOM
YESBANK

TATASTEEL



The clusters roughly corresponds with sectorial themes. 


Fundamental theme
Cluster 1
Metal stocks
Cluster 2
Financial services stocks
Cluster 3
Erratic/heavily idiosyncratic stocks

Classification of BANKNIFTY stocks:
As with the LIX15 analysis, a two cluster based classification is performed on the BANKNIFTY constituents.Following are the resulting clusters:

Cluster 1
Cluster 2
AXISBANK
BANKBARODA
HDFCBANK
BANKINDIA
ICICIBANK
CANBK
INDUSINDBK
PNB
KOTAKBANK
SBIN
YESBANK
UNIONBANK

The fundamental interpretation of the resulting clusters is quite clear. 


Fundamental theme
Cluster 1
Private sector banks
Cluster 2
Public sector banks

Conclusion:
Using clustering techniques, we have been able to group stocks. These grouping tend to convey a particular fundamental meaning. Among the LIX15 constituents the major classification is on the sectorial line. Among the BANKNIFTY constituents the classification lies along the public vs private ownership lines. These conclusions are in line with the one obtained from factor analysis based classification of stocks..

HFT and algorithmic trading in India

Algorithmic trading was introduced in India in 2009 and within a span of 5 years it has gained a considerable share in market. Some random facts and developments in the algorithmic trading scenario in India:
  • Order percentage: Orders received from co-location in cash market segment are around 70% of the total cash orders. In derivatives segment the number is even higher, around 95%. For the currency derivative segment the number is of the order of 25%. 
  • Volume percentage: In India, algorithmic trading comprises of about 20-30% of the total trading volume, which is much lower when compared to US(60-70%) and Europe(40-50%).
  • Latency: Round trip latency is the time taken from initiation of a order to receipt of its conformation. Round trip latency for co-location based connections is around 2 ms. This number should be contrasted against latency for leased line which is around 30 ms and that of VSAT connection which is around 700 ms. 
  • Strategies: In the initial days algorithmic trading was used to exploit arbitrage opportunities. Subsequently algotraders ventured into speculative trading (like market making, statistical arbitrage etc.). Lately, institutional investors have started using algorithmic trading platforms for efficient trade execution (buying/selling large quantities of stocks with minimal impact costs).
  • Regulations: SEBI has taken many proactive measures to regulate algorithmic trading. These measures include risk control checks at exchange and trader's end, half yearly audits of trading systems, pre-approval of strategies from exchanges, penalties on high daily order/trade ratio etc.

Friday, December 20, 2013

Factor analysis based stock classification

Factor analysis is a multivariate statistical method aimed at data reduction and summarization. It can be used to describe the covariance relationships among many variables in terms of a few hidden underlying factors.

Suppose we have a number of correlated variables. Using the correlation matrix, we can group these variables such that the variables within a particular group are highly correlated among themselves, but have relatively small correlations with variables in other groups. This means that each group of variables represents a single underlying construct or factor. These factors can have a fundamental meaning attached to them.

Use of Factor Analysis in trading
Factor analysis are used in trading and portfolio management for various reasons:
  • It is used to identify hidden factors/trends which drive the asset returns. These factors will typically have a fundamental meaning(like sector/style) attached to them. 
  • It is used to classify assets into groups based on their returns. There is a gamut of trading strategies(like basket long short) that can be implemented within each of these groups.
  • It gives a clear picture of the major source of the portfolio risk. These risks can be either systematic (common variance) or unsystematic (specific variance) and hence handled accordingly.
Classification of LIX15 stocks
LIX15 is an Indian equity market index that consists of 15 highly liquid stocks traded on National stock exchange. Factor analysis is performed on the returns of these 15 stocks to identify any hidden trends. The observations matrix consists of normalized daily returns of these 15 stocks sampled from February to November 2013. A two factor model is chosen to decompose the data. The factor loadings are determined using maximum likelihood estimation method. It is seen that these factors accounts for about 60 % of the total variance. Now VARIMAX rotation is performed to group stocks based on their loadings. The aim of this rotation is to achieve simple structures which will possibly have a fundamental reasoning behind them. The following is the table of top 6 stocks with highest loading on each factor:


Factor I
Factor II
AXISBANK
TATASTEEL
YESBANK
HINDALCO
SBIN
JSWSTEEL
IDFC
JPASSOCIAT
BANKBARODA
RCOM
MARUTI
JINDALSTEL

Looking at the above stock list we can say that these factors approximately represent different sectorial themes. The first factor is populated with financial services stocks. The second factor has a large number of metal stocks.


Fundamental theme
Factor 1
Financial services stocks
Factor 2
Metal stocks

There are some stocks in each factor that do not concur with the corresponding fundamental interpretation. This would primarily be sample bias. Another reason could be that these fundamental factors indirectly affect the returns of the corresponding stocks. Also there are some stocks which do not have significant loading on any of the factors. MCDOWELL-N, TATAMOTORS and CAIRN are some of these stocks. These stocks do not fall in either of the sector and hence have remained unclassified.

Classification of BANKNIFTY stocks
BANKNIFTY is the primary banking sector index of India. Similar to the LIX15 analysis, a two factor decomposition of the twelve BANKNIFTY constituents is performed. About 75% of the total variance is explained by these two factors. Following is the table of top 6 stocks with the highest loading each factor.

Factor I
Factor II
AXISBANK
CANBK
ICICIBANK
BANKINDIA
HDFCBANK
UNIONBANK
INDUSINDBK
BANKBARODA
YESBANK
PNB
KOTAKBANK
SBIN

It is clear that the Factor 1 corresponds to private sector banks and Factor 2 corresponds to public sector banks. Hence within the banking sector the most dominant segregation is along the public verses private lines.


Fundamental theme
Factor 1
Private sector banks
Factor 2
Public sector banks

Conclusion:
The prices of stocks are typically correlated. Using factor analysis, we can group the variability in the stock market into categories. We can now view fluctuations in the stock market based on groups rather than the individual stocks. Using factor analysis we have been able to conclude that among the LIX15 constituents the major classification is on the sectorial lines. Also among the BANKNIFTY constituents the classification lies along the public vs private ownership lines.


Monday, December 16, 2013

PCA on NIFTY stocks

Principal component analysis can help to reduce a complex data set to a lower dimension to highlight a hidden structure. It is used to convert a set of observations of correlated variables to a set of values of uncorrelated variables called principal components. These principal components are linear combinations of the actual variables. The linear combinations are chosen in such a manner that the first principal component has the largest possible variance. The successive principal components have the largest amount of variance given that they are orthogonal to the preceding principal components. Hence the variance explained by the first few components tells us about the strength of the underlying trend. An implicit assumption here is that large variance represents important dynamics of the variables.

PCA on NIFTY stocks
NIFTY is one of the most widely tracked index for Indian equity market. It consists of 50 major Indian companies. PCA is used to analyze the correlated returns of these 50 stocks. The observations matrix consists of normalized daily returns of Nifty 50 stocks sampled from February to November 2013. Below is the Scree plot of the resulting principal components:


The first principal component is typically assumed to represent the broad market. The next few are assumed to be the sector/style related factors. The remaining components represent the idiosyncratic properties of stocks. For the given set of NIFTY stocks we can conclude that about 35% of all the variance is because of the broad market factor (systematic risk). Also about 15% of the variance can be explained by the sector/style related factors. The remaining 50% corresponds to the stock specific factors (unsystematic risk).  Below is the factor correlation plot:


While performing PCA, an important thing to look for is the variation of variance explained by the principal components over time.


Looking at the above plots, we can say that barring extreme rises in the broad market, stocks tend to fall together and rise independently of each other. This means that the component of market risks is higher on the downside. Also over the last couple of years, the sector/style factors have gotten stronger. It seems that the investing paradigm has shifted from timing markets to taking stock/sector level calls.

Thursday, September 26, 2013

Market Impact Cost

Trade cost is a tricky subject. It has significant impact on the strategy performance and yet it is one of the least understood subjects. It is typically assumed away in literature. Both underestimation and overestimation of trade cost has detrimental effects. Underestimation of cost can lead to higher churning and thus hurt us in multiple ways. Over estimation of trade cost can force one to trade too slowly and hence can lead to significant market risk.

Components of trade cost:
  • Direct costs such as brokerage, taxes etc. This component is easy to measure.
  • Indirect costs such as market impact and opportunity cost. Market impact is the cost incurred from the market in order to enter or exit a position. This component is hard to measure
Why bother with an accurate trade cost models?
  • Trading cost can have a very significant impact on returns of strategies with high churning ratio. This mean a trading cost model is imperative if you play in the domain of statistical arbitrage or HFT. 
  • An accurate impact cost model can help one alter the trading strategy to achieve higher returns. Given a generic trading idea, should I trade on large cap or on small cap stock universe? The answer to this question would not only depend on gross returns in both these universes but also on the incurred impact cost (for a given trade size).
  •  It also helps one determine the maximum capacity of a particular fund. Beyond a certain size, the fund returns might fall down to less than acceptable levels
  • It can help us design and evaluate order execution algorithms.



Forces at play:
Market impact cost is the difference between the pre trade paper price (LTP or mid price as the modeling may be) and the realized trade price. The characteristics of the underlying asset (liquidity, volatility, resiliency etc) and our order (size, execution strategy etc) both determine the impact cost. The following observable variables play a major role in determining the impact cost: 
  • Relative order size (ROS): It is the ratio of our order size to the total traded quantity in the period. As it is hard to figure out how much quantity is going to be traded in the future, average of last n day trade volume can be used as a proxy.  Impact increases with trade size either linearly or at a decreasing rate.
  • Bid/Ask spread (S): It is the normalized spread of the order book. Impact increases linearly with the spread.
  • Volatility (V): More volatile assets tend to have higher impact cost (because of price chase and premature order fills). Impact increases with volatility at a decreasing rate.
  • Trading rate: If trades follow one another in quick succession, there will be an increased market impact (as each trade will move the price from where the previous trade left it). This happens because the order book has no time to recover from the impact of previous trades.
  • Trend cost: Selling a falling stock will have much higher impact cost than buying it. This implies that the delay between trade signal generation and trade execution will affect short term momentum strategies a lot more than their counterpart.

A calibrated impact cost model would look something like this:

Best way to get an accurate picture of impact cost is to collect the impact data on a trade by trade basis. And then use this data to calibrate the chosen model. There is an easier way to get a rough estimate of the incurred impact cost. By comparing the live trade returns with the back test returns (rerun the back test model during the live period) approximate values can be arrived at. Here one would be assuming that the real live effects not taken into account while back testing (stock alterations, inability to trade on closing price etc) average out to zero.
A word of caution, these impact cost estimates will work only in usual circumstances. For very big orders or extreme level of market volatility these models can give unrealistic estimates of market impact.  So with the calibrated model one must also specify the boundary conditions.

Sector Dispersion

Sector dispersion is the variation of returns between sector indices over time. It is a quick measure of industry level dislocations. Mathematically, it’s cross sectional variance of sector returns. A look back of around 10 to 40 trading days is typically used for calculating sector dispersion.

Indicators like index returns, implied volatility, stock dispersion etc have been widely used to classify market into different regimes. Use of sector dispersion as a regime indicator is largely unheard of. Sector dispersion measures the industry level deviations and can be high even in tranquil markets. Large values primarily indicate a fundamental shift in the outlook of market participants. It is a subtle yet powerful indicator of changing market dynamics.


Effect on strategy performance:
Sector ignorant trading strategies are stock trading strategies which do not take sector level information into account while generating trading signals. Jegadeesh and Titman’s medium term momentum strategy will fall into this category. These strategies unknowingly end up with large sectorial exposures when sector dispersion is high. On days following the high sector dispersion times, they can show very erratic returns. This is because the unmodeled sector level dynamics would play a significant role in determining the future stock returns. Hence sector dispersion can be used to dynamically alter the exposure of such strategies. 


Sector dispersion is also a good predictor of future market volatility. High sector dispersion typically precedes high market volatility.