Browse Source

Nettoyage

- Suppression des print de debug
- Suppression de code commenté obsolète
- Le code est un peu plus compréhensible dans EMA2 et SMA2
master
Barthélemy Paléologue 7 months ago
parent
commit
ae1d131afe
  1. 15
      auto_trading/indicators/ema2.py
  2. 11
      auto_trading/indicators/slopy.py
  3. 12
      auto_trading/indicators/sma2.py
  4. 3
      auto_trading/strat/buyupselldown.py
  5. 5
      main.py

15
auto_trading/indicators/ema2.py

@ -1,6 +1,4 @@
"""EMA indicator, not ready yet."""
from calendar import c
from re import sub
import pandas as pd # type: ignore
from ..interfaces import Indicator
@ -9,7 +7,7 @@ from ..interfaces import Indicator
class EMA(Indicator):
"""Replay the value."""
def __init__(self, alpha: int):
def __init__(self, alpha: float):
"""Save the value."""
super().__init__()
self.alpha = alpha
@ -39,18 +37,13 @@ class EMA(Indicator):
res = {}
for column in ema.columns:
# pour chaque type d'action
# print(column)
coeff = emaDiff[column].get(ema.index[-1])
# print(
# f"Coeff directeur : {coeff}\n Ultieme {ultieme}\n Penultieme {penultieme}"
# )
coeff = emaDiff[column].get(ema.index[-1])
# TODO: ne pas hardcoder
trust = coeff / 5
normalization_factor = 0.2
trust = coeff * normalization_factor
res[column] = trust
print(trust)
return pd.Series(res)

11
auto_trading/indicators/slopy.py

@ -1,6 +1,4 @@
"""+1 when going up, -1 when going down, 0 when not moving enough."""
from calendar import c
from re import sub
import pandas as pd # type: ignore
from ..interfaces import Indicator
@ -36,13 +34,12 @@ class Slopy(Indicator):
res = {}
for column in coeffs.columns:
# pour chaque type d'action
# print(column)
coeff = coeffs[column].get(coeffs.index[-1])
# TODO: ne pas hardcoder
trust = 1 + (coeff / 5)
trust = coeffs[column].get(coeffs.index[-1])
# on clamp l'indicateur entre [-1, 1]
trust = min(trust, 1.0)
trust = max(trust, 0.0)
trust = max(trust, -1.0)
res[column] = trust

12
auto_trading/indicators/sma2.py

@ -1,6 +1,4 @@
"""SMA indicator, not ready yet."""
from calendar import c
from re import sub
import pandas as pd
from ..interfaces import Indicator
@ -39,18 +37,12 @@ class SMA(Indicator):
res = {}
for column in sma.columns:
# pour chaque type d'action
# print(column)
coeff = smaDiff[column].get(sma.index[-1])
# print(
# f"Coeff directeur : {coeff}\n Ultieme {ultieme}\n Penultieme {penultieme}"
# )
# TODO: ne pas hardcoder
trust = coeff / 5
normalization_factor = 0.2
trust = coeff * normalization_factor
res[column] = trust
print(trust)
return pd.Series(res)

3
auto_trading/strat/buyupselldown.py

@ -1,4 +1,3 @@
from re import S
from typing import Dict, List
import pandas as pd # type: ignore
@ -43,7 +42,7 @@ class BuyUpSellDown(Strategy):
trust = 0
for (index, row) in indicators_results.iterrows():
trust += row[stock_name]
print(trust)
#print(trust)
if market_price is None:
# retry later

5
main.py

@ -3,13 +3,9 @@ import pandas as pd # type: ignore
import logging
from auto_trading.broker.backtest import Backtest
from auto_trading.indicators.dumb import Dumb
from auto_trading.indicators.ema2 import EMA
from auto_trading.indicators.slopy import Slopy
from auto_trading.indicators.sma2 import SMA
from auto_trading.interfaces import Indicator
from auto_trading.strat.buyupselldown import BuyUpSellDown
from auto_trading.strat.hold import Hold
from auto_trading.ptf.in_memory import InMemoryPortfolio
from auto_trading.bot import Bot
@ -31,7 +27,6 @@ if __name__ == "__main__":
bot.run()
###### Visualisation du Dataset ######
ANALYSE_DATASET = False
if ANALYSE_DATASET:
data = bt.data.unstack()

Loading…
Cancel
Save