Skip to content

Commit

Permalink
Started adding linear regression plot
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLKaplan committed Sep 16, 2022
1 parent 245377a commit 9b43a13
Show file tree
Hide file tree
Showing 504 changed files with 514 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pairs_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from statsmodels.tsa.stattools import adfuller
from tabulate import tabulate

# Import seaborn
import seaborn as sns

# Apply the default theme
sns.set_theme()

s_and_p_file = 's_and_p_sector_components/sp_stocks.csv'
s_and_p_data = 's_and_p_data'
start_date_str = '2007-01-03'
Expand Down Expand Up @@ -464,4 +470,9 @@ def compute_halflife(prices: pd.Series, lookback_window: int) -> float:
# standard deviation above and below the middle line. A trade is entered when price spread hits either the
# top or bottom Bollinger range and exited when cutting cross the middle of the range.

first_pair_df = close_prices_df[['AAPL', 'MPWR']]

# https://seaborn.pydata.org/tutorial/regression.html
sns.regplot(x="total_bill", y="tip", data=tips);

pass
1 change: 1 addition & 0 deletions s_and_p_data/A.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,139.87
2022-09-13,133.54
2022-09-14,133.25
2022-09-15,133.16
1 change: 1 addition & 0 deletions s_and_p_data/AAL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,14.47
2022-09-13,13.68
2022-09-14,14.03
2022-09-15,14.27
1 change: 1 addition & 0 deletions s_and_p_data/AAP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,181.49
2022-09-13,172.83
2022-09-14,170.04
2022-09-15,167.62
1 change: 1 addition & 0 deletions s_and_p_data/AAPL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,163.43
2022-09-13,153.84
2022-09-14,155.31
2022-09-15,152.37
1 change: 1 addition & 0 deletions s_and_p_data/ABBV.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2442,3 +2442,4 @@ Date,Close
2022-09-12,142.24
2022-09-13,138.53
2022-09-14,139.55
2022-09-15,142.51
1 change: 1 addition & 0 deletions s_and_p_data/ABC.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,147.71
2022-09-13,140.98
2022-09-14,140.11
2022-09-15,139.81
1 change: 1 addition & 0 deletions s_and_p_data/ABMD.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,279.16
2022-09-13,266.39
2022-09-14,264.33
2022-09-15,263.72
1 change: 1 addition & 0 deletions s_and_p_data/ABT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,109.29
2022-09-13,105.84
2022-09-14,105.78
2022-09-15,105.06
1 change: 1 addition & 0 deletions s_and_p_data/ACN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,295.26
2022-09-13,281.52
2022-09-14,278.53
2022-09-15,273.86
1 change: 1 addition & 0 deletions s_and_p_data/ADBE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,396.36
2022-09-13,368.39
2022-09-14,371.52
2022-09-15,309.13
1 change: 1 addition & 0 deletions s_and_p_data/ADI.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,155.65
2022-09-13,148.25
2022-09-14,150.25
2022-09-15,147.87
1 change: 1 addition & 0 deletions s_and_p_data/ADM.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,88.21
2022-09-13,86.35
2022-09-14,86.17
2022-09-15,85.26
1 change: 1 addition & 0 deletions s_and_p_data/ADP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,243.95
2022-09-13,235.06
2022-09-14,234.48
2022-09-15,230.71
1 change: 1 addition & 0 deletions s_and_p_data/ADSK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,215.16
2022-09-13,208.34
2022-09-14,208.52
2022-09-15,201.3
1 change: 1 addition & 0 deletions s_and_p_data/AEE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,95.93
2022-09-13,93.08
2022-09-14,93.73
2022-09-15,91.18
1 change: 1 addition & 0 deletions s_and_p_data/AEP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,105.18
2022-09-13,102.2
2022-09-14,103.32
2022-09-15,100.19
1 change: 1 addition & 0 deletions s_and_p_data/AES.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,27.59
2022-09-13,26.83
2022-09-14,27.03
2022-09-15,26.69
1 change: 1 addition & 0 deletions s_and_p_data/AFL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,62.5
2022-09-13,60.79
2022-09-14,60.13
2022-09-15,59.56
1 change: 1 addition & 0 deletions s_and_p_data/AIG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,56.53
2022-09-13,54.34
2022-09-14,54.2
2022-09-15,54.18
1 change: 1 addition & 0 deletions s_and_p_data/AIZ.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,163.49
2022-09-13,158.49
2022-09-14,155.92
2022-09-15,155.76
1 change: 1 addition & 0 deletions s_and_p_data/AJG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,187.63
2022-09-13,184.81
2022-09-14,185.1
2022-09-15,184.52
1 change: 1 addition & 0 deletions s_and_p_data/AKAM.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,93.11
2022-09-13,89.66
2022-09-14,89.39
2022-09-15,88.24
1 change: 1 addition & 0 deletions s_and_p_data/ALB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,296.97
2022-09-13,298.09
2022-09-14,307.05
2022-09-15,286.75
1 change: 1 addition & 0 deletions s_and_p_data/ALGN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,267.79
2022-09-13,247.06
2022-09-14,246.74
2022-09-15,252.0
1 change: 1 addition & 0 deletions s_and_p_data/ALK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,46.82
2022-09-13,44.94
2022-09-14,45.96
2022-09-15,46.26
1 change: 1 addition & 0 deletions s_and_p_data/ALL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,127.1
2022-09-13,122.54
2022-09-14,124.0
2022-09-15,129.02
1 change: 1 addition & 0 deletions s_and_p_data/ALLE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2220,3 +2220,4 @@ Date,Close
2022-09-12,101.21
2022-09-13,95.89
2022-09-14,95.15
2022-09-15,93.15
1 change: 1 addition & 0 deletions s_and_p_data/AMAT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,96.3
2022-09-13,90.39
2022-09-14,90.64
2022-09-15,88.92
1 change: 1 addition & 0 deletions s_and_p_data/AMCR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2600,3 +2600,4 @@ Date,Close
2022-09-12,12.37
2022-09-13,11.94
2022-09-14,11.74
2022-09-15,11.79
1 change: 1 addition & 0 deletions s_and_p_data/AMD.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,84.64
2022-09-13,77.03
2022-09-14,77.45
2022-09-15,76.66
1 change: 1 addition & 0 deletions s_and_p_data/AME.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,126.83
2022-09-13,123.25
2022-09-14,123.06
2022-09-15,121.44
1 change: 1 addition & 0 deletions s_and_p_data/AMGN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,237.62
2022-09-13,226.86
2022-09-14,228.12
2022-09-15,227.66
1 change: 1 addition & 0 deletions s_and_p_data/AMP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,289.24
2022-09-13,277.72
2022-09-14,277.96
2022-09-15,277.35
1 change: 1 addition & 0 deletions s_and_p_data/AMT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,265.09
2022-09-13,254.63
2022-09-14,251.82
2022-09-15,245.06
1 change: 1 addition & 0 deletions s_and_p_data/AMZN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,136.45
2022-09-13,126.82
2022-09-14,128.55
2022-09-15,126.28
1 change: 1 addition & 0 deletions s_and_p_data/ANET.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2083,3 +2083,4 @@ Date,Close
2022-09-12,124.75
2022-09-13,119.92
2022-09-14,122.26
2022-09-15,116.94
1 change: 1 addition & 0 deletions s_and_p_data/ANSS.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,261.42
2022-09-13,248.76
2022-09-14,247.0
2022-09-15,241.45
1 change: 1 addition & 0 deletions s_and_p_data/AON.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,294.01
2022-09-13,284.04
2022-09-14,283.77
2022-09-15,280.13
1 change: 1 addition & 0 deletions s_and_p_data/AOS.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,56.17
2022-09-13,54.18
2022-09-14,52.27
2022-09-15,52.92
1 change: 1 addition & 0 deletions s_and_p_data/APA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,40.0
2022-09-13,39.11
2022-09-14,41.74
2022-09-15,41.49
1 change: 1 addition & 0 deletions s_and_p_data/APD.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,263.5
2022-09-13,256.08
2022-09-14,255.18
2022-09-15,248.47
1 change: 1 addition & 0 deletions s_and_p_data/APH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,76.4
2022-09-13,74.2
2022-09-14,73.93
2022-09-15,72.89
1 change: 1 addition & 0 deletions s_and_p_data/APTV.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2722,3 +2722,4 @@ Date,Close
2022-09-12,99.75
2022-09-13,97.03
2022-09-14,97.64
2022-09-15,96.75
1 change: 1 addition & 0 deletions s_and_p_data/ARE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,160.28
2022-09-13,153.73
2022-09-14,151.99
2022-09-15,150.89
1 change: 1 addition & 0 deletions s_and_p_data/ATO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,119.44
2022-09-13,116.46
2022-09-14,117.03
2022-09-15,114.12
1 change: 1 addition & 0 deletions s_and_p_data/ATVI.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,78.13
2022-09-13,76.76
2022-09-14,76.6
2022-09-15,76.83
1 change: 1 addition & 0 deletions s_and_p_data/AVB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,214.22
2022-09-13,207.85
2022-09-14,205.08
2022-09-15,201.32
1 change: 1 addition & 0 deletions s_and_p_data/AVGO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3299,3 +3299,4 @@ Date,Close
2022-09-12,529.06
2022-09-13,503.65
2022-09-14,510.75
2022-09-15,500.14
1 change: 1 addition & 0 deletions s_and_p_data/AVY.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,192.05
2022-09-13,184.67
2022-09-14,180.19
2022-09-15,179.36
1 change: 1 addition & 0 deletions s_and_p_data/AWK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3624,3 +3624,4 @@ Date,Close
2022-09-12,156.87
2022-09-13,152.14
2022-09-14,153.48
2022-09-15,147.86
1 change: 1 addition & 0 deletions s_and_p_data/AXP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,162.45
2022-09-13,155.35
2022-09-14,156.3
2022-09-15,156.13
1 change: 1 addition & 0 deletions s_and_p_data/AZO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,2220.38
2022-09-13,2138.36
2022-09-14,2133.01
2022-09-15,2144.94
1 change: 1 addition & 0 deletions s_and_p_data/BA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,158.72
2022-09-13,147.31
2022-09-14,149.26
2022-09-15,149.78
1 change: 1 addition & 0 deletions s_and_p_data/BAC.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,35.27
2022-09-13,34.0
2022-09-14,33.87
2022-09-15,34.51
1 change: 1 addition & 0 deletions s_and_p_data/BALL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,60.69
2022-09-13,58.58
2022-09-14,57.41
2022-09-15,57.66
1 change: 1 addition & 0 deletions s_and_p_data/BAX.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,59.78
2022-09-13,58.13
2022-09-14,59.11
2022-09-15,58.97
1 change: 1 addition & 0 deletions s_and_p_data/BBWI.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,40.44
2022-09-13,37.79
2022-09-14,38.31
2022-09-15,37.38
1 change: 1 addition & 0 deletions s_and_p_data/BBY.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,77.82
2022-09-13,73.69
2022-09-14,73.55
2022-09-15,72.42
1 change: 1 addition & 0 deletions s_and_p_data/BDX.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,264.23
2022-09-13,256.78
2022-09-14,258.95
2022-09-15,256.7
1 change: 1 addition & 0 deletions s_and_p_data/BEN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,26.75
2022-09-13,24.64
2022-09-14,24.54
2022-09-15,24.53
1 change: 1 addition & 0 deletions s_and_p_data/BF-B.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,73.49
2022-09-13,71.24
2022-09-14,72.04
2022-09-15,70.33
1 change: 1 addition & 0 deletions s_and_p_data/BIIB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,212.88
2022-09-13,203.91
2022-09-14,204.11
2022-09-15,206.72
1 change: 1 addition & 0 deletions s_and_p_data/BIO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,512.79
2022-09-13,479.4
2022-09-14,477.48
2022-09-15,472.75
1 change: 1 addition & 0 deletions s_and_p_data/BK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,44.28
2022-09-13,44.11
2022-09-14,43.72
2022-09-15,44.44
1 change: 1 addition & 0 deletions s_and_p_data/BKNG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,2013.32
2022-09-13,1920.8
2022-09-14,1967.38
2022-09-15,1956.77
1 change: 1 addition & 0 deletions s_and_p_data/BKR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,25.46
2022-09-13,24.54
2022-09-14,25.39
2022-09-15,24.33
1 change: 1 addition & 0 deletions s_and_p_data/BLK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,696.81
2022-09-13,644.91
2022-09-14,643.58
2022-09-15,632.34
1 change: 1 addition & 0 deletions s_and_p_data/BMY.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,72.36
2022-09-13,71.04
2022-09-14,70.47
2022-09-15,71.78
1 change: 1 addition & 0 deletions s_and_p_data/BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3898,3 +3898,4 @@ Date,Close
2022-09-12,173.04
2022-09-13,168.5
2022-09-14,166.76
2022-09-15,163.61
1 change: 1 addition & 0 deletions s_and_p_data/BRK-B.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,288.51
2022-09-13,278.29
2022-09-14,278.42
2022-09-15,276.7
1 change: 1 addition & 0 deletions s_and_p_data/BRO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,65.3
2022-09-13,62.76
2022-09-14,62.52
2022-09-15,61.49
1 change: 1 addition & 0 deletions s_and_p_data/BSX.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,43.46
2022-09-13,42.18
2022-09-14,42.07
2022-09-15,42.2
1 change: 1 addition & 0 deletions s_and_p_data/BWA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,39.43
2022-09-13,37.94
2022-09-14,37.08
2022-09-15,37.08
1 change: 1 addition & 0 deletions s_and_p_data/BXP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,87.21
2022-09-13,84.52
2022-09-14,83.72
2022-09-15,82.77
1 change: 1 addition & 0 deletions s_and_p_data/C.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3952,3 +3952,4 @@ Date,Close
2022-09-12,50.87
2022-09-13,49.0
2022-09-14,48.43
2022-09-15,48.44
Loading

0 comments on commit 9b43a13

Please sign in to comment.