Browse Source

fix: fillna with zeros

pull/14/head
QuentinN42 11 months ago
parent
commit
b1a2588560
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 5
      auto_trading/main.py
  2. 14
      auto_trading/predictor/selector.py
  3. 4
      auto_trading/strat/all_in.py
  4. 11
      main.py

5
auto_trading/main.py

@ -2,6 +2,9 @@
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
@ -23,7 +26,7 @@ class Bot:
def run_once(self):
"""run the bot once"""
data = self.broker.next()
current_conversion_rate = data.iloc[-1].to_dict()
current_conversion_rate = data.iloc[-1].fillna(0).to_dict()
self.strategy.run(self.ptf, self.predictor.predict(data), current_conversion_rate)
def print_results(self):

14
auto_trading/predictor/selector.py

@ -0,0 +1,14 @@
import pandas as pd
from ..interfaces import Predictor
class SelectorPredictor(Predictor):
def __init__(self, to_return) -> None:
self.to_return = to_return
def predict(self, data: pd.DataFrame) -> dict:
"""It's just random"""
return {k:0 for k in data.to_dict().keys()} | self.to_return

4
auto_trading/strat/all_in.py

@ -18,5 +18,7 @@ class AllIn(Strategy):
# after get the greatest result
greatest = max(result, key=lambda k: result[k])
# then buy all the greatest result
ptf.deposit(money/current_conversion_rate[greatest], greatest)
to_add = money/current_conversion_rate[greatest]
ptf.deposit(to_add, greatest)

11
main.py

@ -3,6 +3,7 @@ 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.main import Bot
if __name__ == '__main__':
@ -10,7 +11,7 @@ if __name__ == '__main__':
with open(csv, 'r') as f:
head = f.readline().replace("\n", "").split(",")[1:]
pred = MeanAggregator([NormalizedPredictor() for _ in range(4)])
pred = MeanAggregator([NormalizedPredictor(), SelectorPredictor({"Tether": 0.7})])
bot = Bot(
ptf=InMemoryPortfolio({k:1 for k in head}),
@ -19,6 +20,10 @@ if __name__ == '__main__':
predictor=pred
)
bot.run()
bot.print_results()
print("\n")
for _ in range(3):
bot.run_once()
bot.print_results()
print("\n")

Loading…
Cancel
Save