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.
 
 

82 lines
2.3 KiB

"""Realy basic tests."""
import logging
from auto_trading.strat.buyupselldown import BuyUpSellDown
import pytest
from datetime import datetime, timedelta
from pandas import DataFrame, Series # type: ignore
from auto_trading.interfaces import PTFState as State
from auto_trading.orders import Long, Short
today = datetime.today()
@pytest.mark.parametrize(
"data, state, output",
[
(DataFrame(), State(balance=0, stocks={}), []),
(
DataFrame({"close": {(today, "AAPL"): []}}),
State(balance=10, stocks={}),
[],
),
(
DataFrame({"close": {(today, "AAPL"): 10}}),
State(balance=10, stocks={}),
[],
),
(
DataFrame({"close": {(today, "AAPL"): 10}}),
State(
balance=10,
stocks={"AAPL": 5},
),
[],
),
(
DataFrame({"close": {(today, "AAPL"): 10, (today, "TSLA"): 10}}),
State(
balance=10,
stocks={"AAPL": 5, "TSLA": 5},
),
[],
),
(
DataFrame({
"close": {
(today, "AAPL"): 5,
(today, "TSLA"): 50,
(today + timedelta(days=1), "AAPL"): 7,
(today + timedelta(days=1), "TSLA"): 40,
(today + timedelta(days=2), "AAPL"): 10,
(today + timedelta(days=2), "TSLA"): 30,
(today + timedelta(days=3), "AAPL"): 15,
(today + timedelta(days=3), "TSLA"): 15,
(today + timedelta(days=4), "AAPL"): 20,
(today + timedelta(days=4), "TSLA"): 10,
(today + timedelta(days=5), "AAPL"): 30,
(today + timedelta(days=5), "TSLA"): 5,
}
}),
State(
balance=100,
stocks={"TSLA":20},
),
[Long(stock="AAPL", amount=1.6666666666666667, price=30), Short(stock="TSLA", amount=20, price=5)],
),
],
)
def test_hold(data, state, output):
strat = BuyUpSellDown()
res = strat.run(data, state)
logging.info(res)
assert len(res) == len(output)
assert res == output