fix(cli): require named stress shocks
This commit is contained in:
+2
-2
@@ -669,8 +669,8 @@ mtdata-cli trade_var_cvar_calculate --symbol EURUSD --method parametric --transf
|
||||
|
||||
### Stress Open Positions
|
||||
```bash
|
||||
mtdata-cli trade_stress_test '{"EURUSD":-2.0,"GBPUSD":-1.5}' --json
|
||||
mtdata-cli trade_stress_test '{"*":-3.0}' --detail full --json
|
||||
mtdata-cli trade_stress_test --shocks '{"EURUSD":-2.0,"GBPUSD":-1.5}' --json
|
||||
mtdata-cli trade_stress_test --shocks '{"*":-3.0}' --detail full --json
|
||||
```
|
||||
|
||||
Shock values are percentage price moves. `*` is a fallback for any open-position symbol without an explicit shock. The tool is read-only and reports estimated P&L and equity impact.
|
||||
|
||||
@@ -155,10 +155,10 @@ impact. Useful for "what if EURUSD drops 2% and everything else 3%?" scenarios.
|
||||
|
||||
```bash
|
||||
# Per-symbol shocks
|
||||
mtdata-cli trade_stress_test '{"EURUSD":-2.0,"GBPUSD":-1.5}' --json
|
||||
mtdata-cli trade_stress_test --shocks '{"EURUSD":-2.0,"GBPUSD":-1.5}' --json
|
||||
|
||||
# Wildcard shock applied to every position without an explicit entry
|
||||
mtdata-cli trade_stress_test '{"*":-3.0}' --detail full --json
|
||||
mtdata-cli trade_stress_test --shocks '{"*":-3.0}' --detail full --json
|
||||
```
|
||||
|
||||
| Parameter | Default | Description |
|
||||
|
||||
@@ -65,10 +65,12 @@ _MULTI_VALUE_SYMBOL_POSITIONAL_COMMANDS = frozenset(
|
||||
|
||||
_COMMAND_REQUIRED_OPTIONS: set[tuple[str, str]] = {
|
||||
("trade_modify", "ticket"),
|
||||
("trade_stress_test", "shocks"),
|
||||
}
|
||||
|
||||
_NAMED_ONLY_REQUIRED_PARAMS: set[tuple[str, str]] = {
|
||||
("trade_modify", "ticket"),
|
||||
("trade_stress_test", "shocks"),
|
||||
}
|
||||
|
||||
_PRESERVE_OMITTED_DEFAULT_PARAMS: set[tuple[str, str]] = {
|
||||
|
||||
@@ -1743,6 +1743,26 @@ class TestResolveParamKwargs:
|
||||
"'{\"*\":-2}' or '{\"EURUSD\":-1,\"XAUUSD\":-3}'."
|
||||
)
|
||||
|
||||
def test_trade_stress_test_requires_named_shocks_option(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
func_info = {
|
||||
"params": [
|
||||
{
|
||||
"name": "shocks",
|
||||
"type": Dict[str, float],
|
||||
"required": True,
|
||||
"default": None,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
add_dynamic_arguments(parser, func_info, cmd_name="trade_stress_test")
|
||||
|
||||
parsed = parser.parse_args(["--shocks", '{"*":-2}'])
|
||||
assert parsed.shocks == '{"*":-2}'
|
||||
with pytest.raises(SystemExit):
|
||||
parser.parse_args(['{"*":-2}'])
|
||||
|
||||
def test_finviz_calendar_start_help_is_command_specific(self):
|
||||
param = {
|
||||
"name": "start",
|
||||
|
||||
Reference in New Issue
Block a user