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.
 
 

42 lines
1.2 KiB

"""
One script to rule them all, One script to find them,
One script to bring them all and in the darkness bind them
"""
import pandas as pd
from .interfaces import Portfolio, Strategy, Broker, Predictor
class Bot:
"""the main class"""
def __init__(self, ptf: Portfolio, strategy: Strategy, broker: Broker, predictor: Predictor):
"""initialize the bot"""
self.ptf = ptf
self.strategy = strategy
self.broker = broker
self.predictor = predictor
self._current_conversion_rate = None
self._balance = 0 # USD$
def run(self):
"""run the bot"""
while self.broker:
self.run_once()
def run_once(self):
"""run the bot once"""
data = self.broker.next()
self._current_conversion_rate = data.iloc[-1].fillna(0).to_dict()
self.strategy.run(self.ptf, self.predictor.predict(data), self._current_conversion_rate)
def print_results(self):
"""print the results"""
for k, v in self.ptf.content().items():
print(f"{k}: {v:e}")
def balance(self):
money = 0
for k, v in self.ptf.content().items():
money += self._current_conversion_rate[k] * v
return money