francoasdev / SPY-trading-model-

Trading model for SPY with Python using Multilinear regression without ML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SPY-trading-model-

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).

  1. make sure to set the index to "Date" otherwise you won't be able to get precise data

image cf SPY DF

  1. 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

  1. Get rid of the NaN values to be able to make predictions otherwise we can't compute much

image

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()

  1. 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

image image image

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

  1. Predictions on the train dataset

image

  1. Evaluate the strategy with statistical standard

Here we use the module funcmod that we created image

The closer the R2 and the RMSE from both the more consistent the results

  1. Compute the profit generated by the Signal Based strategy compared to "Buy and Hold"

Total profit made in Train: 214.340095

image

Total profit made in Test: 241.030088

image

  1. 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

About

Trading model for SPY with Python using Multilinear regression without ML


Languages

Language:Python 100.0%