|
|
@ -35,30 +35,38 @@ class BuyUpSellDown(Strategy): |
|
|
|
# if I have some money |
|
|
|
for stock_name in indicators_results.columns: |
|
|
|
# for each stock |
|
|
|
if (balance := state.balance) > 0: |
|
|
|
# I calculate the value of the stock |
|
|
|
market_price = ( |
|
|
|
data.loc[data.index[-1][0]].close.to_dict().get(stock_name) |
|
|
|
) |
|
|
|
# I calculate the value of the stock |
|
|
|
market_price = data.loc[data.index[-1][0]].close.to_dict().get(stock_name) |
|
|
|
|
|
|
|
trust = int(indicators_results[stock_name]) |
|
|
|
|
|
|
|
trust = int(indicators_results[stock_name]) |
|
|
|
print(trust) |
|
|
|
if market_price is None: |
|
|
|
# retry later |
|
|
|
return [] |
|
|
|
|
|
|
|
if market_price is None: |
|
|
|
# retry later |
|
|
|
return [] |
|
|
|
if trust > 0: |
|
|
|
if (balance := state.balance) > 0: |
|
|
|
|
|
|
|
amount = balance / (market_price * nb_stock_type) |
|
|
|
amount = balance / (market_price * nb_stock_type) |
|
|
|
|
|
|
|
if trust > 0: |
|
|
|
# and I buy it all at market price |
|
|
|
orders.append( |
|
|
|
Long(stock=stock_name, amount=amount, price=market_price) |
|
|
|
) |
|
|
|
elif trust < 0: |
|
|
|
# and I sell it all at market price |
|
|
|
orders.append( |
|
|
|
Short(stock=stock_name, amount=amount, price=market_price) |
|
|
|
else: |
|
|
|
# I don't have money |
|
|
|
orders |
|
|
|
# print("A PU DE THUNE") |
|
|
|
elif trust < 0: |
|
|
|
# and I sell it all at market price |
|
|
|
orders |
|
|
|
# print(state.stocks) |
|
|
|
orders.append( |
|
|
|
Short( |
|
|
|
stock=stock_name, |
|
|
|
amount=state.stocks[stock_name], |
|
|
|
price=market_price, |
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
print(state.stocks) |
|
|
|
return orders # type: ignore |
|
|
|