Browse Source

maintenant ça fonctionne (presque)

victor_tabary
Victor Tabary 8 months ago
parent
commit
046de5db63
  1. 1
      auto_trading/strat/all_in.py
  2. 15
      auto_trading/strat/buy_and_hold.py

1
auto_trading/strat/all_in.py

@ -15,6 +15,7 @@ class AllIn(Strategy):
for stock, amount in ptf.content().items():
# print(f"{stock}: {amount}")
if amount > 0:
print(stock)
money += current_conversion_rate[stock] * amount
ptf.widraw(amount, stock)

15
auto_trading/strat/buy_and_hold.py

@ -11,14 +11,21 @@ class BuyAndHold(Strategy):
def run(self, ptf: Portfolio, result: dict, current_conversion_rate: dict) -> None:
"""Run the strategy"""
money = 0
amount = ptf.content()['USD']/10
money += current_conversion_rate['USD'] * amount
ptf.widraw(amount, 'USD')
"""amount = ptf.content()['USD']
money += current_conversion_rate['USD'] * amount / 100
ptf.widraw(amount / 100, 'USD')"""
for stock, amount in ptf.content().items():
# print(f"{stock}: {amount}")
if amount > 0:
#print(stock)
money += current_conversion_rate[stock] * amount/10
ptf.widraw(amount/10, stock)
result = {k: -1 if np.isnan(v) else v for k, v in result.items()}
epsilon = 1e-3
epsilon = 1e-6
greatest = max(result, key=lambda k: result[k] - (np.inf if current_conversion_rate[k] < epsilon else 0))
#greatest='USD'
# then buy all the greatest result
to_add = money / current_conversion_rate[greatest]
ptf.deposit(to_add, greatest)

Loading…
Cancel
Save