Based on the theory of long/short equity strategy that I demonstrated in the previous article, I will share an experiment that I did few days ago in which I will go through the steps that I have learned before. From this experiment, I found that all of the preparation from choosing to testing the model is super useful for backtesting. This is just the first step though I am very excited about testing and testing more strategies with the knowledge I have learnt in the near future.
Basically, this article is about explaining the algorithm developed and posted already(link) plus some adjustments that I made. You can check the code and the outcome of this experimental long/short equity strategy that I have uploaded and shared. In terms of the adjustments, I will explain them thoroughly in the article for you.
Here is a secret recipe for building your own portfolio that I have to share with you which is to start with choosing and modifying the model, the factors, or the ranking system that have been proved effective and commonly used. You can modify it slightly to gain back an edge, especially for the factors they use. Even though those factors are already popular and they probably will have no signal left as they have been completely arbitraged out of the market, they can point out a right direction for you to work on in order to suit your purposes well.
The common strategy is to use the value-based factors such as fundamental factors or combine them with that which I introduced before. Because they contain the information which is tied to real world facts about a company, they can be more robust than price-based factors in some extent.
You can also choose price-based factors since they take information about the historical price of each equity and use them to generate the factor value such as momentum or volatility measures which are also proved to be effective to rank the equities.
In the end, you need to realize the fact that we develop predictive factors in order to stay one step ahead of the market. Factors can be arbitraged out and have a specific lifespan. It is important to keep in mind to constantly update the factors or rebalance the portfolio in order to keep the predictive power of your algorithm.
Same as I have done for the Fundamental Factor Long/short equity strategy, I will implement and explain the whole process of developing this type of algorithm starting from choosing the factors, generating the prices series based on the factors, calculating forward returns, running the correlation between each factor and the forward returns, conducting the test based on the baskets(which come from the ranking the equities based on certain factor with the specific order) you are setting, and finally conducting the out of sample backtest on the factors you are choosing.
The testing processes are shown as below. If you have any questions you can open this link and check each step with this one with all of the details.
First of all, I have to make it clear about why and how did I choose these factors and included them in my model. Actually, I have done a lot of research on the effective fundamental factors for stock ranking and I have tried some of them and end up with these 3 factors. First I tried to keep balance about the categories that I choose from such as the EPS growth which is under earning ratio class, D/E ratio which is an under operation ratios class and EBIT/EV is a valuation ratios class. Also, I gave up on plenty of other factors because they failed the statistical tests that I conducted on them(such as they are proved to have a correlation with each other). These three left are the ones relatively qualified and you can see the test outcomes that I will explain later.
One of the apparent differences here is that I choose 3 different factors and conducted a series of tests on these 3 factors instead of 2 factors explained in the previous article. It is not very difficult to understand, but the work actually becomes much more complicated by adding just one more factor such as I used to run the correlation between two factors just once, but now I have to perform three different correlation tests on three factors(3 factors can construct 3 different combinations).
You can see from the graph below, the testing period I choose here is from 2014–01–01 to 2015–01–01. I intended to use EBIT/EV though the ‘fundamentals’ does not include this factor. I extract the fundamental factor ‘EBIT’ and ‘Enterprise Value(EV)’ separately.
From the step shown below, I construct the factor ‘EBIT/EV’ by myself(achieved by letting ebit_data set divided by ev_data set) for the next testing step.
From the step below, I begin testing the correlation between each factor and the 30-day forward returns. The graph shows the correlation coefficient of each month(12 months in total).
The graph below shows the correlation coefficient between Earning per share(EPS) growth rate(one of the factors) and the forward monthly returns of each month(12 months in total). We can actually identify the correlation between these two variables as positive for most months of total 12 months in general. The average the correlation coefficient is shown as the green line in the graph which is around 0.2. The conclusion here is the EPS growth rate and the monthly forward returns tend to increase together. I will demonstrate this in my backtest by giving this factor relatively high weight because of the relationship of them.
From the graph below, we can tell that the relationship between D/E ratio and the forward returns is not very clear. It is hard for us to judge if D/E ratio has the positive or negative correlation with the forward returns since the bar is kind of randomly distributed above and below the x-axis. As for the average monthly correlation between D/E ratio and forward returns over 12 months is around 0.1 which is not significant. Based on the analysis, I will only give small percentage weight to D/E ratio.
As for the reason why do I have to keep this ratio, D/E ratio measures a company’s finance leverage situation which calculated by Debt — Equity Ratio = Total Liabilities / Shareholders’ Equity. High D/E ratio implies that a company has been aggressively financing itself with growing debt. Aggressive leveraging practises are often associated with high levels of risk. I have already included the growth rate from earning ratio category and ebit from I/S as well as EV from valuation. But none of them are measuring the risk of the company.
Similar to the former two graphs, this graph shows that the correlation between EBIT/EV and the monthly forward returns. We can see more bars are above zero(0) even though the average correlation coefficient is still very small. Therefore, I will assign a weight to EBIT/EV which is slightly lower than EPS growth rate in my backtest.
From this step, I started to show you the correlation between two factors that I chose. There are 3 factors in total which mean I can combine them in 3 different ways based on the combination theory. I need to conduct 3 different correlation tests here. As I explained before all the time, the correlation coefficient can only provide limited information. You may be able to tell if there is a positive or negative correlation between two variables, but it is hard to say if this test is valid or not.
I choose to post p-value of the Spearman Rank Correlation here. You can see from the graph below, almost all the bars are higher than the cutoff value .05(if p-value > 0.05, we should not reject the null hypothesis which implies that they actually do not have any correlation). The same mechanism for the rest two pictures. Basically, I can make a judgement that those factors may not have any correlation with each other based on the test result if there are only a few occasions that the bar is lower than 0.05, we could assume those occasional situations may just happen on a random chance.
The two methods that I show below are actually not difficult to interpret. I manually add the weight into my ranking system to distinguish the importance of each factor regarding the test results showing above. Since the higher the D/E ratio represents the higher risk within the stock, I give the negative weight to D/E ratio in turn.
You can see that I have changed the filter and added certain layers(criteria) by conducting research and the test that I have explained before.
First I would like to explain the first criteria that I added: PEG(P/E to growth rate ratio: usually the lower the PEG means the more likely the stock is undervalued given its earning performance):
PEG = P/E ratio ÷ Annual EPS Growth
Also, PEG is supposed to provide a more overall picture than P/E ratio. Still, the PEG ratio will vary from one industry to another. But here is a broad rule of thumb (heuristic) which is that a PEG ratio below one is desirable and that is why I take this ratio into my filter system. I tried to filter down the stocks that I believe are undervalued through this heuristic.
Another ratio I need to explain specifically is ROIC(Return on Invested Capital) which represents how well a company is using its money to generate returns.ROIC
Though we usually compare the ROIC with the WACC(Weighted Average cost of capital) of the company. If ROIC > WACC, the value is being created by the company(often the ROIC calculated on a yearly basis); If not, value if being destroyed. Here I don’t have the benchmark for WACC. I just want to make sure that the ROIC is positive which can, at least, help me to verify that companies are consistently generating positive rates of return on invested capital probably deserve to trade at a premium to other stocks.
I also would like to point out one thing here, I use the filter to filter down the stocks with the Market Cap which is higher than 30,000,000(my intention is to choose the stocks which have the relatively high Market cap). Moreover, you can see the ‘order by’ function in the end which takes ‘Market Cap’ as the variable to order the filtered dataset based on their Cap following by descending order.
You can see a long formula within the filter function:
(Market Cap * 1 )/(Shares Outstanding *1) > 1 which actually take off the stocks whose value/price lower than $1.
From the graph below, I changed the lookback period from 500 days into 400 days since I would like to use 200 days as my Exponentially-weighted moving average(EWMA)span shown in this step(pd.stas.moments.ewmvar()). Usually, we use EWMA to measure the market volatility (by using the exponentially weighted moving average (EWMA), in which more recent returns have greater weight on the variance.).
I did not modify the leverage part. But I would like to dig a little bit deep about the leverage by doing some research and share the results with you. Based on my research, leverage of the funds(leverage can be defined as the financial risk relative to the invested capital (or equity), in this context, leverage is the aggregate level of risk an investor should anticipate relative to the capital invested) can be calculated as your total positions divided by your total capital. For a given capital base, leverage allows investors to build up a larger investment position and thus a higher exposure to specific risks. Buying riskier assets or increasing the leverage ratio applied to a given set of assets increases the risk of the overall investment, and hence the capital base. Therefore, if a portfolio has a very low market risk (e.g., arbitrage/relative value hedge fund strategies often have very low market exposure), then higher leverage may be acceptable for these strategies than for strategies that have greater market exposure, such as long/short equity or global macro.
Here is the picture that I changed the leverage into 2.5 which means using more leverage, the outcome seems better but the risk is actually much here(You can identify it from the higher Max Drawdown).
As for the final backtest outcome(this is the out of sample backtest which starts from 2015–01–01 to 2015–12–18), you can see the video at the beginning. I will keep uploading and explaining more tests and backtests using the knowledge and strategies I have learned thus far for you guys in the future.
Again, this article may have plenty of flaws and please feel free to leave your comment on anything inefficient or worth optimizing here. I would love to hear from you. Hope you enjoy the content!
- Quantopian: long/short equity