The factor models I used before are mostly fundamental factors which may not be very handy when we would like to add more elements into our model. Here I will explain an algorithm which uses Multi-Factor model to resolve this problem simply. Now, we can actually define our own customized factors and use them as filters or ranking system to allocate stocks into either long or short basket as well as to narrow down the stocks included in your universe.
The ‘CustomFactors’ that I used here are calculated using pricing, volume, and fundamentals data. By utilizing this method, we allow ourselves to have more freedom to choose whatever factors we want to add into our model so that we can define the inputs and the looking back window length based upon our intuition or research when we are creating the factors and then set them as default for the next step.
The 3 customized factors I defined here are:
- Momentum, which computed over last 200 days sans the most recent 50 days(they are just absolute closing prices instead of moving averages);
- Volatility or annualized volatility is the standard deviation of an instrument’s yearly logarithmic returns. You can check the formula of annualized volatility here:
- Value, defined by a composite score combining EPS growth rate, cash flow yield and earning yield. In order to allow these factors to be easily compared with each other across different industries, I calculated the<a href = http://www.investopedia.com/terms/z/zscore.asp target="_blank"> z-score of last two yield factors(normalize our factors). At last, we rank the results. ( All the data here is from Morningstar fundamentals database and we only use the factor data from the previous day to calculate the score.)
I have explained momentum and fundamentals before. Volatility is a relatively new factor here. Based on the concept of volatility, it refers to the amount of uncertainty or risk about the size of changes in a security’s value. A higher volatility means that a security’s value can potentially be spread out over a larger range of values. This means that the price of the security can change dramatically over a short time period in either direction. Although, the higher the volatility the higher the option price to some point, we are trying to protect our portfolio from high volatility here(high volatility implies high risk). Therefore, we actually keep the volatility in the denominator part, that is to say, the higher the volatility the lower the factor output. We did this is because we want to let all the score of factor follow uniform descending order and we will pick the high-ranking stocks to long. By doing so, we can achieve the lower the volatility(ideal result) the higher the Volatility factor score.
As for the first CustomFactor ‘AvgDailyDollarVolumeTraded’ which is generated by computing the 20 days average product of close price and trading volume, I will use this factor to set up a security pool from which I can choose the securities to long and short later.
After setting up all of those factors, we will move into the next step. In this step, I add each factor into our pipeline. Following the normal procedures, we will also set up the commission and leverage here.
The filter I am using here is based on the factor that I defined at the beginning which is the security’s average daily trading dollar volume. I will only keep the top 5000 based on the ranking and apply this filter for each of the factor(3 in total) I defined.
I also set up the stop loss percentage here which is 98%(or you can interpret as if the loss exceeds 2% we will exit the position; A stop-loss order is designed to limit an investor’s loss on a position in a security and we use it as a normal way to limit the maximum drawdown).
Another filter here set up by ‘set_screen’ through which we will only keep the stocks whose daily dollar trading volume is higher than 10⁷ and their 200 day’s simple moving average exceeds 5(as the remark above the sma_200, by filtering the stock with the criteria we can screen out penny stocks and low liquidity securities).
We rank the 3 customized factors following default descending order and added them into my pipeline afterward. In order to combine 3 factors, we create a ‘combo_raw’ which is the weighted average of 3 factors as a ranking system for my strategy. I will rank the securities included in my pipeline based on the combo_raw scores of them.
Based on the principle of long/short equity strategy, we will only long top 100 stocks and short bottom 100 stocks in terms of their combo_raw scores.
In the end, we will add the union of these two lists(long and short lists) of their indexes together to update my universe.
The screenshot below shows the backtesting outcome from 2013–12–31 to 2015–12–31. You can also check it out from the video that I uploaded.
The total returns within these 2 years are 65.1% compared to the benchmark returns 14.6% and we can tell that our strategy beats the market to some extent. As for the β which is -0.08 in the end, which is good and it also implies that our strategy is hardly influenced by the market. The Sharpe Ratio is 1.68 which means for every unit risk that you are taking you can get 1.68 unit returns back. The only measure that may not be very ideal is MaxDD which is 14.09% and kind of high compared to the total returns.
As I mentioned in my<a href = http://hellohaohan.com/backtest/developing-and-testing-strategy/ target="_blank"> last article, we can obtain more information about our backtest by the following analysis.
The information here is very clearly. You can get a more comprehensive picture about your strategy when you go through these tables and graphs such as I am concerned about the Maximum Drawdown (Maximum Drawdown (MDD) is an indicator of downside risk over a specified time period. It can be used both as a stand-alone measure or as an input into other metrics such as “Return over Maximum Drawdown” and Calmar Ratio)of my strategy. We can see from the analysis below, the worst drawdown happened on 2015–10–01 which is 14.15% along with the rest 4 worst drawdowns.
From the rolling portfolio beta of equity graph, we can tell that our portfolio β is around 0 and the average number is 0 or around 0 too. In terms of the rolling Sharpe Ratio, the average Sharpe ratios are around 2 and we can see that the Sharpe Ratio is above 0 through this period.
The average daily turnover is around 0.1and the average daily trading volume is around 10000. The annual returns of 2015 are significantly higher than ones in 2014.
One interesting graph here is Rolling Fama-French (you can check my previous article to know more about Fama-French Factor Model)Single Factor-Betas which contains 3 factors: SMB, HML, and UMD(UMD (up-minus-down) is the momentum-factor-mimicking portfolio’s return). We can see that our portfolio has higher momentum exposure and the other exposures are going down over time. In other words, the portfolio’s periodic returns are most contributed by momentum factor and its effect is growing over time.(A common way to figure out an asset’s factor exposures is to perform a multiple linear regression of an asset’s periodic returns (usually monthly) against the returns of long-short factor-mimicking portfolios. Doing so creates a regression-based benchmark that tries to explain the returns of the asset. Unexplainable excess return, or alpha, is often interpreted as evidence of skill or some kind of additional risk not captured by the factor model.)
Hope you enjoy the content. Please feel free to share your ideas or comments here with me here. Thank you!