From eda640865eff4caaacc31bf830097938abb207f3 Mon Sep 17 00:00:00 2001 From: thibaudlabat <> Date: Mon, 6 Dec 2021 14:55:24 +0100 Subject: [PATCH 1/2] je sais plus --- .gitignore | 2 ++ auto_trading/main.py | 15 +++++++++++---- auto_trading/strat/all_in.py | 5 ++++- main.py | 19 +++++++++++++++---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 2efc8dc..5e54756 100644 --- a/.gitignore +++ b/.gitignore @@ -225,3 +225,5 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +# JetBrains Tools +.idea/ diff --git a/auto_trading/main.py b/auto_trading/main.py index 1c8836d..cde8b70 100644 --- a/auto_trading/main.py +++ b/auto_trading/main.py @@ -4,7 +4,6 @@ """ import pandas as pd - from .interfaces import Portfolio, Strategy, Broker, Predictor @@ -17,6 +16,8 @@ class Bot: self.strategy = strategy self.broker = broker self.predictor = predictor + self._current_conversion_rate = None + self._balance = 0 # USD$ def run(self): """run the bot""" @@ -26,10 +27,16 @@ class Bot: def run_once(self): """run the bot once""" data = self.broker.next() - current_conversion_rate = data.iloc[-1].fillna(0).to_dict() - self.strategy.run(self.ptf, self.predictor.predict(data), current_conversion_rate) + 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(): + 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 diff --git a/auto_trading/strat/all_in.py b/auto_trading/strat/all_in.py index 80ea8c4..d138471 100644 --- a/auto_trading/strat/all_in.py +++ b/auto_trading/strat/all_in.py @@ -1,4 +1,5 @@ from ..interfaces import Strategy, Portfolio +import numpy as np class AllIn(Strategy): """Just all in the greatest result""" @@ -17,7 +18,9 @@ class AllIn(Strategy): ptf.widraw(amount, stock) # after get the greatest result - greatest = max(result, key=lambda k: result[k]) + result = {k:-1 if np.isnan(v) else v for k,v in result.items() } + epsilon = 1e-6 + greatest = max(result, key=lambda k: result[k]-(np.inf if current_conversion_rate[k] Date: Sun, 16 Jan 2022 19:13:05 +0100 Subject: [PATCH 2/2] chore: added requirements --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..46c38e1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +matplotlib +numpy +pandas