year_intervals and long_periods

master
Dmitry Maylarov 4 years ago
parent be0652581e
commit c99c22de3c

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

@ -5,24 +5,16 @@ import strategies as st
import pandas as pd import pandas as pd
if __name__ == "__main__": if __name__ == "__main__":
stockList = ["BRK-A"] stockList = ["^GSPC"]
monthly_params = dict(sum=100000, coef=1.005, t_rate=1 + 0.02 / 12) monthly_params = dict(sum=100000, coef=1.005, t_rate=1 + 0.02 / 12)
# startDate = datetime.datetime.fromisoformat("2000-01-01") # startDate = datetime.datetime.fromisoformat("2000-01-01")
# endDate = datetime.datetime.fromisoformat("2022-01-01") # endDate = datetime.datetime.fromisoformat("2022-01-01")
print(stockList[0]) 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( stockData = lib.get_data(
stockList[0], stockList[0],
) )
start_date = stockData.index[0] start_date = stockData.index[0]
year_step = 3 year_step = 5
print( print(
"Investing monthly, increasing {:.2f}%, starting from ${}".format( "Investing monthly, increasing {:.2f}%, starting from ${}".format(
(monthly_params["coef"] * 100) - 100, (monthly_params["coef"] * 100) - 100,
Loading…
Cancel
Save