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.

44 lines
1.4 KiB

from import Backtest
from auto_trading.strat.all_in import AllIn
from auto_trading.ptf.in_memory import InMemoryPortfolio
from auto_trading.predictor.mean_agg import MeanAggregator
from auto_trading.predictor.normalized import NormalizedPredictor
from auto_trading.predictor.selector import SelectorPredictor
from auto_trading.predictor.random_predictor import RandomPredictor
from import Bot
from tqdm import tqdm # type: ignore
import pandas as pd # type: ignore
pd.options.plotting.backend = "plotly"
if __name__ == "__main__":
csv = "data/gold.csv"
bt = Backtest(csv, start=10)
start = {name: 0 for name in}
start["USD"] = 10_000
pred = MeanAggregator(
[RandomPredictor(), SelectorPredictor({"USD": -0.1}), RandomPredictor()]
bot = Bot(
ptf=InMemoryPortfolio(start.copy()), strategy=AllIn(), broker=bt, predictor=pred
data = pd.DataFrame(,
for date in tqdm(data.index):
current_investments = bot.ptf.content()
converted_investments = {
name: amount * bot.current_conversion_rate[name]
for name, amount in current_investments.items()
data.loc[date] = converted_investments
# data.plot().show() # faster plot