From c99c22de3c0140dd66b258a4f48eb09765f7dd7b Mon Sep 17 00:00:00 2001 From: Dmitry Maylarov Date: Wed, 2 Feb 2022 21:43:24 +0300 Subject: [PATCH] year_intervals and long_periods --- long_periods.py | 39 +++++++++++++++++++++++++++++++++ compare.py => year_intervals.py | 12 ++-------- 2 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 long_periods.py rename compare.py => year_intervals.py (82%) diff --git a/long_periods.py b/long_periods.py new file mode 100644 index 0000000..0ad330c --- /dev/null +++ b/long_periods.py @@ -0,0 +1,39 @@ +import datetime +import lib +from matplotlib import pyplot as plt +import strategies as st +import pandas as pd + +if __name__ == "__main__": + stockList = ["^GSPC"] + monthly_params = dict(sum=100000, coef=1.005, t_rate=1 + 0.02 / 12) + # startDate = datetime.datetime.fromisoformat("2000-01-01") + # endDate = datetime.datetime.fromisoformat("2022-01-01") + print(stockList[0]) + stockData = lib.get_data( + stockList[0], + ) + print( + "Investing monthly, increasing {:.2f}%, starting from ${}".format( + (monthly_params["coef"] * 100) - 100, + monthly_params["sum"], + ) + ) + for period_years in (10, 20): + end = datetime.date.today() + start = end - datetime.timedelta(days=period_years * 365) + stockData = lib.get_data(stockList[0], start, end) + print( + "{} to {}, {:.1f} years".format( + start, + end, + (end - start).days / 365, + ) + ) + newdf = pd.concat( + [ + lib.test_strategy(stockData, strategy, monthly_params) + for strategy in (st.DCA, st.QDCA) + ] + ) + print(newdf.to_string()) diff --git a/compare.py b/year_intervals.py similarity index 82% rename from compare.py rename to year_intervals.py index 8938cd7..44da8b4 100644 --- a/compare.py +++ b/year_intervals.py @@ -5,24 +5,16 @@ import strategies as st import pandas as pd if __name__ == "__main__": - stockList = ["BRK-A"] + stockList = ["^GSPC"] monthly_params = dict(sum=100000, coef=1.005, t_rate=1 + 0.02 / 12) # startDate = datetime.datetime.fromisoformat("2000-01-01") # endDate = datetime.datetime.fromisoformat("2022-01-01") print(stockList[0]) - """ - for period_years in (10, 20): - end_date = datetime.datetime.now() - start_date = end_date - datetime.timedelta(days=period_years * 365) - stockData = get_data(stockList[0], start_date, end_date) - simulate(stockData, monthly_params) - """ - period_years = 5 stockData = lib.get_data( stockList[0], ) start_date = stockData.index[0] - year_step = 3 + year_step = 5 print( "Investing monthly, increasing {:.2f}%, starting from ${}".format( (monthly_params["coef"] * 100) - 100,