2 changed files with 29 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||
import pytest |
|||
from pandas import DataFrame # type: ignore |
|||
|
|||
from auto_trading.ptf.in_memory import InMemoryPortfolio |
|||
from auto_trading.interfaces import PTFState as State |
|||
from auto_trading.orders import Long, Short |
|||
|
|||
|
|||
@pytest.mark.parametrize( |
|||
"change_rate, start_stocks, start_balance, order, stop_stocks, stop_balance", |
|||
[ |
|||
({"AAPL": 10}, {"AAPL": 0}, 10, Long("AAPL", 1, 10), {"AAPL": 1}, 0), |
|||
({"AAPL": 10}, {"AAPL": 0}, 10, Long("AAPL", 0.5, 10), {"AAPL": 0.5}, 5), |
|||
({"AAPL": 10}, {"AAPL": 0}, 10, Long("AAPL", 0.5, 20), {"AAPL": 0.5}, 0), |
|||
({"AAPL": 10}, {"AAPL": 1}, 0, Short("AAPL", 1, 10), {"AAPL": 0}, 10), |
|||
({"AAPL": 10}, {"AAPL": 1}, 0, Short("AAPL", 0.5, 10), {"AAPL": 0.5}, 5), |
|||
({"AAPL": 10}, {"AAPL": 1}, 0, Short("AAPL", 0.5, 5), {"AAPL": 0.5}, 2.5), |
|||
], |
|||
) |
|||
def test_execute( |
|||
change_rate, start_stocks, start_balance, order, stop_stocks, stop_balance |
|||
): |
|||
ptf = InMemoryPortfolio(lambda: change_rate) |
|||
ptf._stocks = start_stocks |
|||
ptf._balance = start_balance |
|||
ptf.execute_multiples([order]) |
|||
assert ptf._stocks == stop_stocks |
|||
assert ptf._balance == stop_balance |
Loading…
Reference in new issue