Browse Source

strat meanRevert + diagramme

pull/14/head
QuentinBernhard 1 year ago
committed by Gitea
parent
commit
a2faa7719e
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 27
      auto_trading/strat/meanRevert.py
  2. 4
      documents/Diagramme.drawio-2.svg

27
auto_trading/strat/meanRevert.py

@ -0,0 +1,27 @@
from ..interfaces import Strategy, Portfolio
import numpy as np
class meanRevert(Strategy):
"""Just all in the greatest result"""
def __init__(self):
"""Initialise the anti strat"""
def run(self, ptf: Portfolio, result: dict, current_conversion_rate: dict) -> None:
"""Run the strategy"""
# first sell all the stocks
money = 0
for stock, amount in ptf.content().items():
#print(f"{stock}: {amount}")
if amount > 0:
money += current_conversion_rate[stock]*amount
ptf.widraw(amount, stock)
# after get the greatest result
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]<epsilon else 0))
# then buy all the greatest result
to_add = money/current_conversion_rate[greatest]
ptf.deposit(to_add, greatest)

4
documents/Diagramme.drawio-2.svg

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

Loading…
Cancel
Save