Browse Source

feat: test slopy

Signed-off-by: QuentinN42 <quentin@lieumont.fr>
master
QuentinN42 7 months ago
parent
commit
9280ffce97
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 57
      tests/indicators/test_slopy.py

57
tests/indicators/test_slopy.py

@ -0,0 +1,57 @@
"""Realy basic tests."""
import pytest
from datetime import datetime
from pandas import DataFrame, Series # type: ignore
from auto_trading.indicators.slopy import Slopy
def date(j: int) -> datetime:
return datetime.strptime(f"2015-03-{j}", "%Y-%m-%d")
@pytest.mark.parametrize(
"data, expected",
[
(
DataFrame(
{
"close": {
(date(i), st): 10 if i == 10 and st == "GOOG" else 0
for i in range(1, 11)
for st in ("GOOG", "GOOGL")
}
}
),
{"GOOG": 1.0, "GOOGL": 0.0},
),
(
DataFrame(
{
"close": {
(date(i), st): 9.5 if i == 10 and st == "GOOG" else 10
for i in range(1, 11)
for st in ("GOOG", "GOOGL")
}
}
),
{"GOOG": -0.5, "GOOGL": 0.0},
),
(
DataFrame(
{
"close": {
(date(i), st): 0 if i == 10 and st == "GOOG" else 10
for i in range(1, 11)
for st in ("GOOG", "GOOGL")
}
}
),
{"GOOG": -1.0, "GOOGL": 0.0},
),
],
)
def test_sma(data: DataFrame, expected: Series) -> None:
"""Test the SMA indicator."""
sma = Slopy()
assert sma(data).to_dict() == expected
Loading…
Cancel
Save