2 changed files with 0 additions and 31 deletions
@ -1,27 +0,0 @@ |
|||
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) |
Before Width: | Height: | Size: 22 KiB |
Loading…
Reference in new issue