|
|
@ -7,34 +7,35 @@ from auto_trading.orders import Long |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"state, output", |
|
|
|
"data, state, output", |
|
|
|
[ |
|
|
|
(State(balance=0, stocks={}, conversion_rate=DataFrame()), None), |
|
|
|
(DataFrame(), State(balance=0, stocks={}), None), |
|
|
|
( |
|
|
|
State(balance=10, stocks={}, conversion_rate=DataFrame({"AAPL": [10]})), |
|
|
|
DataFrame({"AAPL": [10]}), |
|
|
|
State(balance=10, stocks={}), |
|
|
|
Long(stock="AAPL", amount=1, price=10), |
|
|
|
), |
|
|
|
( |
|
|
|
DataFrame({"AAPL": [10]}), |
|
|
|
State( |
|
|
|
balance=10, |
|
|
|
stocks={"AAPL": 5}, |
|
|
|
conversion_rate=DataFrame({"AAPL": [10]}), |
|
|
|
), |
|
|
|
Long(stock="AAPL", amount=1, price=10), |
|
|
|
), |
|
|
|
( |
|
|
|
DataFrame({"AAPL": [10], "TSLA": [20]}), |
|
|
|
State( |
|
|
|
balance=10, |
|
|
|
stocks={"AAPL": 5, "TSLA": 5}, |
|
|
|
conversion_rate=DataFrame({"AAPL": [10], "TSLA": [20]}), |
|
|
|
), |
|
|
|
Long(stock="AAPL", amount=1, price=10), |
|
|
|
), |
|
|
|
], |
|
|
|
) |
|
|
|
def test_hold(state, output): |
|
|
|
def test_hold(data, state, output): |
|
|
|
strat = Hold(to_hold="AAPL") |
|
|
|
res = strat.execute(DataFrame(), DataFrame(), state) |
|
|
|
res = strat.run(data, state) |
|
|
|
if output is None: |
|
|
|
assert len(res) == 0 |
|
|
|
else: |
|
|
|