Skip to content

Commit

Permalink
Added code for pairs trading with randomly chosen pairs (instead of c…
Browse files Browse the repository at this point in the history
…ointegrated pairs).
  • Loading branch information
Ian Kaplan committed Feb 17, 2023
1 parent b59f370 commit 4e24364
Show file tree
Hide file tree
Showing 494 changed files with 634 additions and 137 deletions.
278 changes: 141 additions & 137 deletions pairs_trading_backtest.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions s_and_p_data/A.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,154.6
2023-02-14,153.04
2023-02-15,151.75
2023-02-16,148.28
1 change: 1 addition & 0 deletions s_and_p_data/AAL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,16.51
2023-02-14,16.79
2023-02-15,16.8
2023-02-16,16.39
1 change: 1 addition & 0 deletions s_and_p_data/AAP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,152.19
2023-02-14,150.76
2023-02-15,151.29
2023-02-16,150.19
1 change: 1 addition & 0 deletions s_and_p_data/AAPL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,153.85
2023-02-14,153.2
2023-02-15,155.33
2023-02-16,153.71
1 change: 1 addition & 0 deletions s_and_p_data/ABBV.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2548,3 +2548,4 @@ Date,Close
2023-02-13,153.73
2023-02-14,152.59
2023-02-15,151.06
2023-02-16,149.53
1 change: 1 addition & 0 deletions s_and_p_data/ABC.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,158.61
2023-02-14,157.36
2023-02-15,158.81
2023-02-16,160.47
1 change: 1 addition & 0 deletions s_and_p_data/ABT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,108.52
2023-02-14,107.26
2023-02-15,107.28
2023-02-16,106.08
1 change: 1 addition & 0 deletions s_and_p_data/ACN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,288.35
2023-02-14,284.77
2023-02-15,287.65
2023-02-16,281.22
1 change: 1 addition & 0 deletions s_and_p_data/ADBE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,375.0
2023-02-14,377.9
2023-02-15,375.94
2023-02-16,365.16
1 change: 1 addition & 0 deletions s_and_p_data/ADI.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,180.45
2023-02-14,182.54
2023-02-15,196.18
2023-02-16,193.83
1 change: 1 addition & 0 deletions s_and_p_data/ADM.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,81.9
2023-02-14,81.78
2023-02-15,81.74
2023-02-16,81.42
1 change: 1 addition & 0 deletions s_and_p_data/ADP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,227.36
2023-02-14,224.59
2023-02-15,227.85
2023-02-16,227.48
1 change: 1 addition & 0 deletions s_and_p_data/ADSK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,224.0
2023-02-14,228.04
2023-02-15,229.28
2023-02-16,222.13
1 change: 1 addition & 0 deletions s_and_p_data/AEE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,85.84
2023-02-14,85.2
2023-02-15,85.83
2023-02-16,85.84
1 change: 1 addition & 0 deletions s_and_p_data/AEP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,91.09
2023-02-14,90.48
2023-02-15,90.92
2023-02-16,90.7
1 change: 1 addition & 0 deletions s_and_p_data/AES.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,26.35
2023-02-14,26.29
2023-02-15,26.69
2023-02-16,26.37
1 change: 1 addition & 0 deletions s_and_p_data/AFL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,71.01
2023-02-14,69.21
2023-02-15,69.27
2023-02-16,69.13
1 change: 1 addition & 0 deletions s_and_p_data/AIG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,61.96
2023-02-14,61.52
2023-02-15,61.83
2023-02-16,62.16
1 change: 1 addition & 0 deletions s_and_p_data/AIZ.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,133.57
2023-02-14,130.25
2023-02-15,131.95
2023-02-16,132.94
1 change: 1 addition & 0 deletions s_and_p_data/AJG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,195.22
2023-02-14,188.25
2023-02-15,190.33
2023-02-16,188.63
1 change: 1 addition & 0 deletions s_and_p_data/AKAM.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,87.97
2023-02-14,87.79
2023-02-15,78.66
2023-02-16,77.07
1 change: 1 addition & 0 deletions s_and_p_data/ALB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,269.93
2023-02-14,270.7
2023-02-15,272.79
2023-02-16,285.62
1 change: 1 addition & 0 deletions s_and_p_data/ALGN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,325.26
2023-02-14,331.52
2023-02-15,338.39
2023-02-16,326.17
1 change: 1 addition & 0 deletions s_and_p_data/ALK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,50.16
2023-02-14,50.58
2023-02-15,50.27
2023-02-16,49.12
1 change: 1 addition & 0 deletions s_and_p_data/ALL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,136.51
2023-02-14,135.04
2023-02-15,137.15
2023-02-16,137.1
1 change: 1 addition & 0 deletions s_and_p_data/ALLE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2326,3 +2326,4 @@ Date,Close
2023-02-13,119.92
2023-02-14,119.86
2023-02-15,121.58
2023-02-16,118.75
1 change: 1 addition & 0 deletions s_and_p_data/AMAT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,116.53
2023-02-14,118.44
2023-02-15,119.46
2023-02-16,115.39
1 change: 1 addition & 0 deletions s_and_p_data/AMCR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2706,3 +2706,4 @@ Date,Close
2023-02-13,11.45
2023-02-14,11.4
2023-02-15,11.51
2023-02-16,11.41
1 change: 1 addition & 0 deletions s_and_p_data/AMD.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,83.13
2023-02-14,85.95
2023-02-15,85.18
2023-02-16,80.08
1 change: 1 addition & 0 deletions s_and_p_data/AME.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,145.83
2023-02-14,144.37
2023-02-15,146.2
2023-02-16,144.55
1 change: 1 addition & 0 deletions s_and_p_data/AMGN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,243.66
2023-02-14,241.03
2023-02-15,240.07
2023-02-16,234.22
1 change: 1 addition & 0 deletions s_and_p_data/AMP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,355.33
2023-02-14,352.74
2023-02-15,350.3
2023-02-16,349.47
1 change: 1 addition & 0 deletions s_and_p_data/AMT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,217.26
2023-02-14,215.15
2023-02-15,216.6
2023-02-16,212.0
1 change: 1 addition & 0 deletions s_and_p_data/AMZN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,99.54
2023-02-14,99.7
2023-02-15,101.16
2023-02-16,98.15
1 change: 1 addition & 0 deletions s_and_p_data/ANET.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2189,3 +2189,4 @@ Date,Close
2023-02-13,136.0
2023-02-14,141.46
2023-02-15,141.53
2023-02-16,141.68
1 change: 1 addition & 0 deletions s_and_p_data/ANSS.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,272.76
2023-02-14,274.28
2023-02-15,277.9
2023-02-16,273.24
1 change: 1 addition & 0 deletions s_and_p_data/AON.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,321.43
2023-02-14,312.44
2023-02-15,315.07
2023-02-16,310.25
1 change: 1 addition & 0 deletions s_and_p_data/AOS.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,68.03
2023-02-14,67.48
2023-02-15,68.03
2023-02-16,67.72
1 change: 1 addition & 0 deletions s_and_p_data/APA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,42.51
2023-02-14,42.47
2023-02-15,41.31
2023-02-16,40.14
1 change: 1 addition & 0 deletions s_and_p_data/APD.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,286.7
2023-02-14,281.49
2023-02-15,284.46
2023-02-16,280.73
1 change: 1 addition & 0 deletions s_and_p_data/APH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,81.11
2023-02-14,80.73
2023-02-15,81.46
2023-02-16,81.36
1 change: 1 addition & 0 deletions s_and_p_data/APTV.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2828,3 +2828,4 @@ Date,Close
2023-02-13,112.79
2023-02-14,121.1
2023-02-15,123.07
2023-02-16,120.73
1 change: 1 addition & 0 deletions s_and_p_data/ARE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,167.0
2023-02-14,165.08
2023-02-15,165.4
2023-02-16,162.01
1 change: 1 addition & 0 deletions s_and_p_data/ATO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,116.81
2023-02-14,115.77
2023-02-15,116.91
2023-02-16,115.69
1 change: 1 addition & 0 deletions s_and_p_data/ATVI.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,76.59
2023-02-14,76.78
2023-02-15,77.7
2023-02-16,77.51
1 change: 1 addition & 0 deletions s_and_p_data/AVB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,181.19
2023-02-14,180.08
2023-02-15,181.14
2023-02-16,180.12
1 change: 1 addition & 0 deletions s_and_p_data/AVGO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3405,3 +3405,4 @@ Date,Close
2023-02-13,601.12
2023-02-14,602.31
2023-02-15,607.69
2023-02-16,600.54
1 change: 1 addition & 0 deletions s_and_p_data/AVY.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,185.29
2023-02-14,184.24
2023-02-15,185.63
2023-02-16,182.05
1 change: 1 addition & 0 deletions s_and_p_data/AWK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3730,3 +3730,4 @@ Date,Close
2023-02-13,151.71
2023-02-14,149.31
2023-02-15,149.25
2023-02-16,147.46
1 change: 1 addition & 0 deletions s_and_p_data/AXP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,181.33
2023-02-14,181.02
2023-02-15,180.67
2023-02-16,177.94
1 change: 1 addition & 0 deletions s_and_p_data/AZO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,2543.51
2023-02-14,2546.27
2023-02-15,2580.27
2023-02-16,2571.35
1 change: 1 addition & 0 deletions s_and_p_data/BA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,215.65
2023-02-14,218.45
2023-02-15,217.44
2023-02-16,212.21
1 change: 1 addition & 0 deletions s_and_p_data/BAC.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,35.65
2023-02-14,35.62
2023-02-15,35.56
2023-02-16,35.28
1 change: 1 addition & 0 deletions s_and_p_data/BALL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,55.92
2023-02-14,56.93
2023-02-15,58.98
2023-02-16,57.39
1 change: 1 addition & 0 deletions s_and_p_data/BAX.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,40.5
2023-02-14,39.91
2023-02-15,40.06
2023-02-16,39.8
1 change: 1 addition & 0 deletions s_and_p_data/BBWI.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,44.73
2023-02-14,44.93
2023-02-15,43.24
2023-02-16,42.91
1 change: 1 addition & 0 deletions s_and_p_data/BBY.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,87.26
2023-02-14,88.31
2023-02-15,88.95
2023-02-16,88.2
1 change: 1 addition & 0 deletions s_and_p_data/BDX.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,247.25
2023-02-14,243.41
2023-02-15,243.55
2023-02-16,241.94
1 change: 1 addition & 0 deletions s_and_p_data/BEN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,31.76
2023-02-14,31.71
2023-02-15,31.74
2023-02-16,31.2
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 @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,65.89
2023-02-14,65.31
2023-02-15,65.58
2023-02-16,65.42
1 change: 1 addition & 0 deletions s_and_p_data/BIIB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,290.46
2023-02-14,289.08
2023-02-15,278.98
2023-02-16,271.53
1 change: 1 addition & 0 deletions s_and_p_data/BIO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,471.92
2023-02-14,462.52
2023-02-15,460.52
2023-02-16,455.91
1 change: 1 addition & 0 deletions s_and_p_data/BK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,51.92
2023-02-14,51.71
2023-02-15,51.77
2023-02-16,51.29
1 change: 1 addition & 0 deletions s_and_p_data/BKNG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,2423.03
2023-02-14,2471.05
2023-02-15,2516.58
2023-02-16,2493.18
1 change: 1 addition & 0 deletions s_and_p_data/BKR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,32.78
2023-02-14,32.46
2023-02-15,32.15
2023-02-16,32.26
1 change: 1 addition & 0 deletions s_and_p_data/BLK.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,736.91
2023-02-14,729.15
2023-02-15,724.19
2023-02-16,713.0
1 change: 1 addition & 0 deletions s_and_p_data/BMY.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,73.17
2023-02-14,72.25
2023-02-15,71.47
2023-02-16,70.85
1 change: 1 addition & 0 deletions s_and_p_data/BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4004,3 +4004,4 @@ Date,Close
2023-02-13,147.67
2023-02-14,144.55
2023-02-15,144.67
2023-02-16,143.59
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 @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,313.74
2023-02-14,310.79
2023-02-15,309.63
2023-02-16,308.18
1 change: 1 addition & 0 deletions s_and_p_data/BRO.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,58.47
2023-02-14,57.26
2023-02-15,57.92
2023-02-16,57.37
1 change: 1 addition & 0 deletions s_and_p_data/BSX.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,47.69
2023-02-14,47.28
2023-02-15,47.29
2023-02-16,46.48
1 change: 1 addition & 0 deletions s_and_p_data/BWA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,49.86
2023-02-14,49.69
2023-02-15,49.38
2023-02-16,50.32
1 change: 1 addition & 0 deletions s_and_p_data/BXP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,73.23
2023-02-14,72.34
2023-02-15,73.19
2023-02-16,71.37
1 change: 1 addition & 0 deletions s_and_p_data/C.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,51.0
2023-02-14,51.61
2023-02-15,51.82
2023-02-16,51.46
1 change: 1 addition & 0 deletions s_and_p_data/CAG.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,36.78
2023-02-14,36.06
2023-02-15,35.88
2023-02-16,35.82
1 change: 1 addition & 0 deletions s_and_p_data/CAH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,79.46
2023-02-14,78.75
2023-02-15,78.58
2023-02-16,78.64
1 change: 1 addition & 0 deletions s_and_p_data/CARR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,4 @@ Date,Close
2023-02-13,45.44
2023-02-14,45.13
2023-02-15,45.48
2023-02-16,45.23
1 change: 1 addition & 0 deletions s_and_p_data/CAT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,248.15
2023-02-14,244.36
2023-02-15,248.7
2023-02-16,246.52
1 change: 1 addition & 0 deletions s_and_p_data/CB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4058,3 +4058,4 @@ Date,Close
2023-02-13,215.5
2023-02-14,213.32
2023-02-15,212.95
2023-02-16,210.26
1 change: 1 addition & 0 deletions s_and_p_data/CBOE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3190,3 +3190,4 @@ Date,Close
2023-02-13,128.58
2023-02-14,126.55
2023-02-15,128.54
2023-02-16,126.73
Loading

0 comments on commit 4e24364

Please sign in to comment.