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.

32 lines
960 B

import pytest
from datetime import datetime
from pandas import DataFrame # type: ignore
from auto_trading.strat.yoyo import Yoyo
from auto_trading.interfaces import PTFState as State
from auto_trading.orders import Long, Short
date = datetime.strptime("2015-03-31", "%Y-%m-%d")
"data, state, output",
(DataFrame(), State(balance=0, stocks={}), None),
(DataFrame({"close": {(date, "AAPL"): 0}}), State(balance=0, stocks={}), None),
DataFrame({"close": {(date, "AAPL"): 10}}),
State(balance=0, stocks={"AAPL": 1}),
(DataFrame({"close": {(date, "AAPL"): 10}}), State(balance=10, stocks={}), Long),
def test_yoyo(data, state, output):
strat = Yoyo("AAPL")
res =, state)
if output is None:
assert len(res) == 0
assert len(res) == 1
assert isinstance(res[0], output)