You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
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],
|
|
)
|
|
start_date = stockData.index[0]
|
|
year_step = 5
|
|
print(
|
|
"Investing monthly, increasing {:.2f}%, starting from ${}".format(
|
|
(monthly_params["coef"] * 100) - 100,
|
|
monthly_params["sum"],
|
|
)
|
|
)
|
|
for start_year in range(start_date.year, datetime.datetime.today().year, year_step):
|
|
start_date = datetime.date(start_year, 1, 1)
|
|
end_date = datetime.date(start_year + year_step - 1, 12, 31)
|
|
if (today := datetime.date.today()) < end_date:
|
|
end_date = today
|
|
stockData = lib.get_data(stockList[0], start_date, end_date)
|
|
start, end = lib.get_data_borders(stockData)
|
|
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())
|
|
# print(df[["annual%", "froi%", "cost", "total_value", "max_dd%", "max_md"]])
|
|
# print(newdf["annual%"])
|