Trading model for SPY with Python using Multilinear regression without ML
WARNING: I can't share the datasets used here due to licence matter. One can fetch part of the data on Yahoo Finance for free (except for some like S&P 500, FTSE, AORD,...) Moreover this is static model, if you want to make a financial use of it make sure you have dynamic data (which might be costly), try to expand the number of predictors and note that the Bid-Ask effect isn't considered here as well as the broker fees (even though they're often low of SPY).
- make sure to set the index to "Date" otherwise you won't be able to get precise data
- We assume we are US traders, thus we'll fetch the data from other markets when our session begins
cf #3 in Main.ipynb
-SPY: our response variable --> SPY tomorrow's opening price - today's opening price
-spy_lag/sp500/nasdaq/dji -->yesterday's opening minus today's
-cac40/daxi= --> yesterday's opening minus todays
-aord/hsi/nikkei -->"Today's" close minus opening
- Get rid of the NaN values to be able to make predictions otherwise we can't compute much
df.fillna(method=fill"ffill") will fill the NaN value with the previous one and then we'll drop the first line with: df.dropna()
- Splitting the DF
We have 2679 rows we'll make two split them into two dataset to test the consitency of the results by taking in the test one the last 1000 rows and for the train one the 1000 before
5)Perform the OLS regression
The Adjusted R-Square is 5.2% which is not that bad for noisy assets like stocks We can also notice from the p-value that aord seems to significantly explain our reponse variable variations at a 95% confidence level
- Predictions on the train dataset
- Evaluate the strategy with statistical standard
Here we use the module funcmod that we created
The closer the R2 and the RMSE from both the more consistent the results
- Compute the profit generated by the Signal Based strategy compared to "Buy and Hold"
Total profit made in Train: 214.340095
Total profit made in Test: 241.030088
- Sharpe Ratio and Maximu Drawdown TRAIN
Daily Sharpe Ratio is 0.179650763033
Yearly Sharpe Ratio is 2.85186745096
Maximum Drawdown in Train is 0.0606901644364
TEST
Daily Sharpe Ratio is 0.130351262086
Yearly Sharpe Ratio is 2.06926213537
Maximum Drawdown in Test is 0.117198995246