Browse Source

feat: indicators aggregation

pull/14/head
QuentinN42 10 months ago
parent
commit
e2bf43ef8e
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 4
      auto_trading/interfaces.py
  2. 19
      tests/interfaces/test_strategy.py

4
auto_trading/interfaces.py

@ -111,7 +111,9 @@ class Strategy(ABC):
Returns:
List[Order]: A list of orders to execute.
"""
indicators_results: DataFrame = ...
indicators_results = DataFrame(
{k: v(data) for k, v in self.indicators.items()}
).T
return self.execute(data, indicators_results, state)
@abstractmethod

19
tests/interfaces/test_strategy.py

@ -0,0 +1,19 @@
from pandas import DataFrame, Series # type: ignore
from auto_trading.interfaces import Strategy
from auto_trading.indicators.dumb import Dumb
s1 = Series({"GOOG": 1, "GOOGL": 2})
s2 = Series({"GOOG": 3, "GOOGL": 4})
result = DataFrame({"GOOG": {"n1": 1, "n2": 3}, "GOOGL": {"n1": 2, "n2": 4}})
class UselessStrategy(Strategy):
def execute(self, data, indicators_results: DataFrame, ptf_state):
assert (indicators_results == result).all().all()
def test_indicators_agg():
strat = UselessStrategy({"n1": Dumb(s1), "n2": Dumb(s2)})
strat.run(DataFrame(), None)
Loading…
Cancel
Save