Browse Source

feat: indicators return series

pull/14/head
QuentinN42 10 months ago
parent
commit
b79ff18ccd
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 4
      auto_trading/indicators/dumb.py
  2. 6
      auto_trading/interfaces.py
  3. 10
      tests/indicators/test_dumb.py

4
auto_trading/indicators/dumb.py

@ -7,12 +7,12 @@ from ..interfaces import Indicator
class Dumb(Indicator):
"""Replay the value."""
def __init__(self, value: pd.DataFrame):
def __init__(self, value: pd.Series):
"""Save the value."""
super().__init__()
self.value = value
def __call__(self, data: pd.DataFrame) -> pd.DataFrame:
def __call__(self, data: pd.DataFrame) -> pd.Series:
"""Return a dataframe of valuation of each stock from the input data.
Args:

6
auto_trading/interfaces.py

@ -5,8 +5,8 @@ import logging
from abc import ABC, abstractmethod, abstractproperty
from dataclasses import dataclass, field
from datetime import timedelta, datetime
from pandas import DataFrame, Timedelta # type: ignore
from datetime import datetime
from pandas import DataFrame, Timedelta, Series # type: ignore
from typing import Dict, List, Optional, Any, Callable
from .errors import OrderException, UnknowOrder, PTFException
@ -78,7 +78,7 @@ class Indicator(ABC):
self.logger = logging.getLogger(self.__class__.__name__)
@abstractmethod
def __call__(self, data: DataFrame) -> DataFrame:
def __call__(self, data: DataFrame) -> Series:
"""Return a dataframe of valuation of each stock from the input data.
Args:

10
tests/indicators/test_dumb.py

@ -1,7 +1,7 @@
"""Realy basic tests."""
import pytest
from pandas import DataFrame # type: ignore
from pandas import DataFrame, Series # type: ignore
from auto_trading.indicators.dumb import Dumb
@ -9,11 +9,11 @@ from auto_trading.indicators.dumb import Dumb
@pytest.mark.parametrize(
"value",
[
(DataFrame()),
(DataFrame({"AAPL": [0], "GOOG": [1], "GOOGL": [2]})),
(Series()),
(Series({"AAPL": 0, "GOOG": 1, "GOOGL": 2})),
],
)
def test_dumb(value: DataFrame) -> None:
def test_dumb(value: Series) -> None:
"""Test the dumb indicator."""
dumb = Dumb(value)
assert (dumb(DataFrame()) == value).all().all()
assert (dumb(DataFrame()) == value).all()

Loading…
Cancel
Save