Browse Source

Meilleure strat

master
Barthélemy Paléologue 1 year ago
parent
commit
26e8f45349
  1. 6
      auto_trading/indicators/slopy.py
  2. 42
      auto_trading/strat/buyupselldown.py
  3. 2
      main.py

6
auto_trading/indicators/slopy.py

@ -46,10 +46,12 @@ class Slopy(Indicator):
ultieme = lastND[column].get(lastND.index[-1])
penultieme = lastND[column].get(lastND.index[-2])
if ultieme > penultieme:
if ultieme / penultieme > 1.05:
res[column] = 1
else:
elif ultieme / penultieme < 0.95:
res[column] = -1
else:
res[column] = 0
else:
res[column] = 1

42
auto_trading/strat/buyupselldown.py

@ -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

2
main.py

@ -42,6 +42,8 @@ if __name__ == "__main__":
for order in ptf.history:
print(order)
# plt.plot(bot.balance_history, label="balance")
print(bot.ptf.total_balance(bot.broker.current_change))
plt.show()

Loading…
Cancel
Save