
Stanford University MS&E 448 Big Financial Data and Algorithmic Trading Trend Following: A Machine Learning Approach Authors: Art Paspanthong, Divya Saini, Joe Taglic, Raghav Tibrewala, Will Vithayapalert June 10, 2019 Trend Following Strategy Contents Introduction and Strategy 3 Data 3 Investment Universe Selection . .3 Data Exploration . .3 Feature Generation 3 Continuous Variables . .4 Categorical Variables . .4 Models 4 Linear Model . .4 Results . .4 RNN Model . .6 Results . .7 Neural Net Model . .8 Comparison with Linear Regression . .9 Results . 10 Summary and Comparison . 11 Portfolio Construction 11 Portfolio Optimizer . 11 Stop Loss . 12 Risk Management Philosophy 13 Portfolio Results 13 Baseline Strategy . 13 Comparison of Results from Different Models . 13 Execution Discussion 14 Retrospective Discussion 14 Page 1 of 15 Trend Following Strategy List of Figures 1 Correlation of Returns of 36 Different Assets . .3 2 Predicted versus actual values of unregularized linear regression model. .4 3 Histogram of error values of unregularized linear regression model . .5 4 Beta values of unregularized linear model and their significance values. .5 5 Portfolio over 2017-2018 using unregularized linear model predictions. .5 6 Predicted vs actual values of the lasso regression model. .5 7 Lasso regression model histogram of errors. .6 8 Portfolio over 2017-2018 using lasso model predictions. .6 9 Portfolio over 2017-2018 using 5-day linear regression return predictions. .6 10 The architecture of 3-layer LSTM . .7 11 Correlation of actual next day's returns and predicted next day's returns . .7 12 Correlation of actual next 5-day's returns and predicted next 5-day's returns . .7 13 Histogram of errors for prediction on next day's returns . .8 14 Histogram of errors for prediction on next 5-day's returns . .8 15 Portfolio value over 2017-18 using LSTM model prediction on next day's returns . .8 16 Portfolio value over 2017-18 using LSTM model prediction on next 5-day's returns .8 17 Different Results given by Neural Net Model due to Stochastic Nature of Neural Nets9 18 Loss as a function of epochs . .9 19 Comparison of Linear Regression and Neural Network without Activation . 10 20 Correlation: predicted and actual returns . 10 21 Histogram of Errors from Neural Net Model . 10 22 Final Saved Portfolio from the Neural Net Model compared to the Naive Strategy . 11 23 Plots of Portfolio Value over Time for Linear Regression Portfolio with Stop Loss (No SL, 15%, 10%, 5%) . 12 24 Comparison of the portfolio over time for different models . 13 Page 2 of 15 Trend Following Strategy Introduction and Strategy In addition to that, we also filter out commodi- ties futures with low volume out as well. In the Trend following is one of the most clas- end, we have in total of 36 different contracts sic investment styles used by investors for over from 7 commodities. decades. The concept of trend following is rela- tively simple: When there is a trend, follow it; when things move against you or when the trend Data Exploration isnt really there, cut your losses. Since the data set we selected are relatively However, due to its simplicity, our team be- complete, we did not encounter any challenging lieves that trend following strategy itself might problems. However, the original features in the not be able to capture the nuance and the com- dataset is somewhat limited, so we decided to plexity of the financial market. Consequently, add approximately 50 new "trend-following" fea- with increased availability of data, we believe tures into the data set. Details of these features machine learning techniques could play an im- will be discussed in the next section. portant role in constructing a better trend fol- In addition to that, we also explore the corre- lowing portfolio. That's why our task for this lation between different assets. The correlation project is to replicate and improve on the basic plot is shown in the figure below. ideas of trend following. Data Investment Universe Selection As per the project proposal, we narrowed down our universe of assets to futures markets. Using data sets from Quandl, we have access to multiple different futures contracts. However, we first select 9 different commodities to start off Figure 1: Correlation of Returns of 36 Different Assets with, including Crude Oil, Natural Gas, Gaso- line, Gold, Silver, Copper, Agriculture, Corn, In the plot above, there are quite a few no- Wheat, and Soybean. We consider 6 different ticeable clusters of assets with high positive cor- contracts for each commodity (1 to 6 months ex- relation. Such clusters are the same commodity piration). The primary reason for looking into with different expiration period. It's also notable a diverse set of assets is to diversify the port- that among all assets we selected, there is no pair folio. In addition to that, the volume of fu- of futures contracts that have high negative cor- tures contracts for specific commodities could be relation. a lot smaller than equity markets. Large buy or sell orders could potentially move the market. That's why we want to invest in many different Feature Generation contracts. After inspecting and considering each data Features selected for the modeling were based set, we ended up selecting 7 different commodi- on traditional trend following indicators. These ties, dropping Natural Gas and Gasoline from were used in the prediction of the final response our study due to incompleteness of the data set. variable, next day return, or (Pt+1 − Pt)=Pt. Page 3 of 15 Trend Following Strategy Continuous Variables Models 1. Simple Moving Average (SMA) Linear Model 2. Exponential Moving Average (EMA) First, a linear regression model was trained 3. Moving Average Convergence Divergence on 2014-2017 data and tested on 2017-2018 data. (MACD) The technique provided fairly stable predictable patterns and in the unregularized version, all 4. Momentum Indicator parameters mentioned in the feature generation 5. Day Since Cross section of this paper were used. A separate re- gression was run on each asset available in the 6. Number of days up - down training data in order to allow the models more The simple moving average, momentum indica- expressiveness in their understanding. The ad- tor, and number of days of price upward move- vantages of using a linear model on this problem ment minus number of days of price downward are that it is simple and easy to understand, and movement were calculated over several lookback it fits decently well to the data. Second, a reg- windows. Specifically over the time-frames of 5, ularized lasso regression model was trained on 10, 15, 20, 50, and 100 days back. EMA variables the same training data and tested on the same were included over lookback windows of 10, 12, test data. Finally, a linear regression model was 20, 26, 50, and 100 days. And, MACD was calcu- trained to predict returns over a longer time lated as 12-day EMA - 26-day EMA. Days since frame. Specifically, on 5-day returns. We at- cross indicates the number of days since the last tempted this model because in a non-ideal trad- crossover between an asset price and its EMA. ing system there are frictions. Namely, that one-day returns are small and may be erased by Categorical Variables transaction costs and we might not enter the po- sition until the next day. So, the question be- 1. SMA Crossover indicator variables came whether we could reliably predict 5-day 2. EMA Crossover indicator variables returns and whether that would improve the ef- ficacy of our trading algorithm. 3. MACD Crossover indicator variables The categorical variables were labeled at each Results timestep as +1 to indicate a crossover with buy The figures below showcase the plots of the signal, 0 to indicate no crossover, and -1 to predicted versus actual values as well as a his- indicate a crossover with a sell signal. They togram of the linear regression errors. were calculated as asset price crossovers with all the SMA, EMA, and MACD indicator variables mentioned in the continuous variables section. In traditional trend following strategies, these crossover variables are important indicators of detecting upward or downward trends that can be ridden for profit. Our reasoning for feeding all of them into our models was to allow the algo- rithm to determine which ones are more accurate predictors of next day returns. Figure 2: Predicted versus actual values of unregular- ized linear regression model. Page 4 of 15 Trend Following Strategy ear regression model price predictions performed quite well. Below is a chart of the portfolio growth based on the linear regression model com- pared to a naive strategy. Over the course of 2017-2018, the portfolio grew to 1.3x using the linear regression model return predictions. Figure 3: Histogram of error values of unregularized lin- ear regression model The overall train mse was 2.187 E-04. The test mse was 1.47 E-04. In analyzing the beta values of the linear regression, we noticed that exponential Moving Averages are generally bet- ter predictors than simple moving averages in terms of higher absolute values of betas. One of a 5 day, 10 day, 12 day, and 100 day indicators were statistically significant at the five percent level. Thus we also noticed that recent trends Figure 5: Portfolio over 2017-2018 using unregularized linear model predictions. are most significant, though longer term trends are not irrelevant. Finally, we noticed that be- Next, for the lasso model, we decided that it cause of the change of sign between EMA 10, may be interesting to train in order to get rid 12, 20 indicator variable beta values, there is an of some of the overfitting of a linear regression.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-