4 changed files with 25 additions and 3 deletions
@ -0,0 +1,21 @@ |
|||
from ..interfaces import Strategy, Portfolio |
|||
|
|||
class AllIn(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 filter(lambda kv: kv[1], ptf.content().items()): |
|||
money += current_conversion_rate[stock]*amount |
|||
ptf.widraw(stock, amount) |
|||
|
|||
# after get the greatest result |
|||
greatest = max(result, key=lambda k: result[k]) |
|||
|
|||
# then buy all the greatest result |
|||
ptf.deposit(amount/current_conversion_rate[greatest], greatest) |
Loading…
Reference in new issue