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.
 
 

43 lines
1.3 KiB

import pandas as pd # type: ignore
import logging
from auto_trading.broker.backtest import Backtest
from auto_trading.indicators.ema import EMA
from auto_trading.indicators.sma import SMA
from auto_trading.interfaces import Strategy
from auto_trading.orders import Long, Short
from auto_trading.strat.Yoyo import Yoyo
from auto_trading.strat.hold import Hold
from auto_trading.ptf.in_memory import InMemoryPortfolio
from auto_trading.bot import Bot
from auto_trading.strat.prop import Prop
pd.options.plotting.backend = "plotly"
logging.basicConfig(level=logging.DEBUG)
if __name__ == "__main__":
bt = Backtest("./data/NYSE_small.csv")
ptf = InMemoryPortfolio(
base_balance=100, change_rate_getter=lambda: bt.current_change
)
# strategy = Hold("GOOGL")
# strategy = Prop({"EMA": EMA(10)})
strategy = Yoyo('GOOGL')
bot = Bot(ptf, strategy, bt)
bot.run()
for order in ptf.orders_history:
print(order)
print(bot.ptf.total_balance(bot.broker.current_change))
# plot the history
ch_history: pd.DataFrame = bot.broker.change_rate_history # type: ignore
ch_history['USD'] = 1
st_history = bot.ptf.states_history
st_history.index = ch_history.index
(st_history * ch_history).fillna(0).plot.area().show()