You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1.5 KiB

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