Run projections and backtests in parallel.
This commit is contained in:
@@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
|
|||||||
import seaborn as sns
|
import seaborn as sns
|
||||||
from scipy.stats import norm
|
from scipy.stats import norm
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
|
from multiprocessing import Process
|
||||||
|
|
||||||
|
|
||||||
# Utility functions
|
# Utility functions
|
||||||
@@ -948,45 +949,13 @@ def create_backtest_plot(
|
|||||||
return historical_projections
|
return historical_projections
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def run_projection(df):
|
||||||
analysis, df = analyze_bitcoin_prices("prices.csv")
|
projections = create_plots(df, start="2016-07-09", project_days=365 * 4)
|
||||||
# create_plots(df) # Full history
|
|
||||||
# create_plots(df, start='2022-01-01') # From 2022 onwards
|
|
||||||
# create_plots(df, start='2023-01-01', end='2023-12-31') # Just 2023
|
|
||||||
# Create plots with different time ranges and projections
|
|
||||||
projections = create_plots(df, start="2011-01-01", project_days=365 * 4)
|
|
||||||
print("\nProjected Prices at Key Points:")
|
print("\nProjected Prices at Key Points:")
|
||||||
print(projections.iloc[[29, 89, 179, 364]].round(2)) # 30, 90, 180, 365 days
|
print(projections.iloc[[29, 89, 179, 364]].round(2)) # 30, 90, 180, 365 days
|
||||||
|
|
||||||
# Create multiple backtests for different periods
|
|
||||||
backtests = [
|
|
||||||
# First to second halving
|
|
||||||
{
|
|
||||||
"start_date": "2012-11-28", # First halving
|
|
||||||
"backtest_date": "2016-07-09", # Second halving
|
|
||||||
"project_days": 1460, # 4 years
|
|
||||||
},
|
|
||||||
# Second to third halving
|
|
||||||
{
|
|
||||||
"start_date": "2016-07-09", # Second halving
|
|
||||||
"backtest_date": "2020-05-11", # Third halving
|
|
||||||
"project_days": 1460, # 4 years
|
|
||||||
},
|
|
||||||
# Third halving onwards
|
|
||||||
{
|
|
||||||
"start_date": "2020-05-11", # Third halving
|
|
||||||
"backtest_date": "2024-04-19", # Fourth halving (projected)
|
|
||||||
"project_days": 1460, # 4 years
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"start_date": "2016-07-09", # Second halving
|
|
||||||
"backtest_date": "2024-04-19", # Fourth halving (projected)
|
|
||||||
"project_days": 1460, # 4 years
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
# Run all backtests
|
def run_backtest(params, df):
|
||||||
for params in backtests:
|
|
||||||
print(
|
print(
|
||||||
f"\nRunning backtest from {params['start_date']} to {params['backtest_date']}"
|
f"\nRunning backtest from {params['start_date']} to {params['backtest_date']}"
|
||||||
)
|
)
|
||||||
@@ -998,9 +967,7 @@ if __name__ == "__main__":
|
|||||||
actual_prices = validation_df.set_index("Date")["Close"]
|
actual_prices = validation_df.set_index("Date")["Close"]
|
||||||
|
|
||||||
for days in [30, 90, 180, 365]:
|
for days in [30, 90, 180, 365]:
|
||||||
target_date = pd.to_datetime(params["backtest_date"]) + pd.Timedelta(
|
target_date = pd.to_datetime(params["backtest_date"]) + pd.Timedelta(days=days)
|
||||||
days=days
|
|
||||||
)
|
|
||||||
if (
|
if (
|
||||||
target_date in actual_prices.index
|
target_date in actual_prices.index
|
||||||
and target_date in backtest_projections.index
|
and target_date in backtest_projections.index
|
||||||
@@ -1013,3 +980,49 @@ if __name__ == "__main__":
|
|||||||
print(
|
print(
|
||||||
f"Projected Range: ${projected['Lower_95']:,.2f} - ${projected['Upper_95']:,.2f}"
|
f"Projected Range: ${projected['Lower_95']:,.2f} - ${projected['Upper_95']:,.2f}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
analysis, df = analyze_bitcoin_prices("prices.csv")
|
||||||
|
procs = []
|
||||||
|
|
||||||
|
# Create main projection
|
||||||
|
proc = Process(target=run_projection, args=(df,))
|
||||||
|
proc.start()
|
||||||
|
procs.append(proc)
|
||||||
|
|
||||||
|
# Create multiple backtests for different periods
|
||||||
|
backtests = [
|
||||||
|
# First until fourth halving
|
||||||
|
{
|
||||||
|
"start_date": "2012-11-28",
|
||||||
|
"backtest_date": "2024-04-19",
|
||||||
|
"project_days": 1460,
|
||||||
|
},
|
||||||
|
# First until third halving
|
||||||
|
{
|
||||||
|
"start_date": "2012-11-28",
|
||||||
|
"backtest_date": "2020-05-11",
|
||||||
|
"project_days": 1460,
|
||||||
|
},
|
||||||
|
# Second until fourth halving
|
||||||
|
{
|
||||||
|
"start_date": "2016-07-09",
|
||||||
|
"backtest_date": "2024-04-19",
|
||||||
|
"project_days": 1460,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
# Run all backtests
|
||||||
|
for params in backtests:
|
||||||
|
proc = Process(
|
||||||
|
target=run_backtest,
|
||||||
|
args=(
|
||||||
|
params,
|
||||||
|
df,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
procs.append(proc)
|
||||||
|
proc.start()
|
||||||
|
for proc in procs:
|
||||||
|
proc.join()
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
"Date","Price","Open","High","Low","Vol.","Change %"
|
"Date","Price","Open","High","Low","Vol.","Change %"
|
||||||
"11/15/2024","88,096.2","87,297.2","88,348.6","87,276.2","109.10K","0.92%"
|
"11/15/2024","89,481.8","87,297.2","90,670.6","87,118.8","159.36K","2.51%"
|
||||||
"11/14/2024","87,294.0","90,424.8","91,726.7","86,740.2","153.34K","-3.46%"
|
"11/14/2024","87,294.0","90,424.8","91,726.7","86,740.2","153.34K","-3.46%"
|
||||||
"11/13/2024","90,422.2","87,971.2","93,226.6","86,168.4","257.57K","2.82%"
|
"11/13/2024","90,422.2","87,971.2","93,226.6","86,168.4","257.57K","2.82%"
|
||||||
"11/12/2024","87,941.3","88,665.0","89,929.6","85,122.2","288.68K","-0.82%"
|
"11/12/2024","87,941.3","88,665.0","89,929.6","85,122.2","288.68K","-0.82%"
|
||||||
|
|||||||
|
Reference in New Issue
Block a user