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.

35 lines
967 B

1 year ago
import pandas as pd # type: ignore
from auto_trading.broker.backtest import Backtest
from auto_trading.strat.hold import Hold
1 year ago
from auto_trading.strat.buyhighselllow import BuyHighSellLow
from auto_trading.ptf.in_memory import InMemoryPortfolio
from auto_trading.bot import Bot
1 year ago
1 year ago
pd.options.plotting.backend = "plotly"
1 year ago
if __name__ == "__main__":
bt = Backtest("./data/NYSE_smallest.csv")
ptf = InMemoryPortfolio(
base_balance=100, change_rate_getter=lambda: bt.current_change
)
1 year ago
strategy = BuyHighSellLow("WLTW")
1 year ago
bot = Bot(ptf, strategy, bt)
1 year ago
bot.run()
1 year ago
for order in ptf.orders_history:
print(order)
print(bot.ptf.total_balance(bot.broker.current_change))
1 year ago
ch_history: pd.DataFrame = bot.broker.change_rate_history # type: ignore
st_history = pd.DataFrame(
[s.stocks for s in bot.ptf.states_history],
index=ch_history.index,
)
(st_history * ch_history).fillna(0).plot.area().show()