()
| 153 | |
| 154 | @python_version_request |
| 155 | def test_simulator_stop_twap() -> None: |
| 156 | order = get_order() |
| 157 | simulator = get_simulator(order) |
| 158 | NUM_STEPS = 7 |
| 159 | for i in range(NUM_STEPS): |
| 160 | simulator.step(TOTAL_POSITION / NUM_STEPS) |
| 161 | |
| 162 | HISTORY_STEP_LENGTH = 30 * NUM_STEPS |
| 163 | state = simulator.get_state() |
| 164 | assert len(state.history_exec) == HISTORY_STEP_LENGTH |
| 165 | |
| 166 | assert (state.history_exec["deal_amount"] == TOTAL_POSITION / HISTORY_STEP_LENGTH).all() |
| 167 | assert is_close(state.history_steps["position"].iloc[0], TOTAL_POSITION * (NUM_STEPS - 1) / NUM_STEPS) |
| 168 | assert is_close(state.history_steps["position"].iloc[-1], 0.0) |
| 169 | assert is_close(state.position, 0.0) |
| 170 | assert is_close(state.metrics["ffr"], 1.0) |
| 171 | |
| 172 | assert is_close(state.metrics["market_price"], state.backtest_data.get_deal_price().mean()) |
| 173 | assert is_close(state.metrics["market_volume"], state.backtest_data.get_volume().sum()) |
| 174 | assert is_close(state.metrics["trade_price"], state.metrics["market_price"]) |
| 175 | assert is_close(state.metrics["pa"], 0.0) |
| 176 | |
| 177 | assert simulator.done() |
| 178 | |
| 179 | |
| 180 | @python_version_request |
nothing calls this directly
no test coverage detected