ivolatility-backtesting 2.153__tar.gz → 2.154__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/PKG-INFO +1 -1
  2. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting/ivolatility_backtesting.py +2 -7
  3. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting.egg-info/PKG-INFO +1 -1
  4. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting.egg-info/SOURCES.txt +2 -1
  5. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/pyproject.toml +1 -1
  6. ivolatility_backtesting-2.154/tests/test_2154_put_atm_legs.py +78 -0
  7. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/README.md +0 -0
  8. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting/__init__.py +0 -0
  9. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting.egg-info/dependency_links.txt +0 -0
  10. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting.egg-info/requires.txt +0 -0
  11. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/ivolatility_backtesting.egg-info/top_level.txt +0 -0
  12. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/setup.cfg +0 -0
  13. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2142_fixes.py +0 -0
  14. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2144_duckdb_dedup.py +0 -0
  15. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2146_vix_vro.py +0 -0
  16. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2147_cents_multiplier.py +0 -0
  17. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2148_loader_memory.py +0 -0
  18. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2149_client_errors.py +0 -0
  19. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2150_prompt_patterns.py +0 -0
  20. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2152_cache_lock_and_rate_limit.py +0 -0
  21. {ivolatility_backtesting-2.153 → ivolatility_backtesting-2.154}/tests/test_2153_cache_lock_kept.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ivolatility_backtesting
3
- Version: 2.153
3
+ Version: 2.154
4
4
  Summary: A universal backtesting framework for financial strategies using the IVolatility API.
5
5
  Author-email: IVolatility <support@ivolatility.com>
6
6
  Project-URL: Homepage, https://ivolatility.com
@@ -10117,10 +10117,7 @@ class StopLossManager:
10117
10117
  long_strike = pos.get('long_strike', pos.get('near_strike'))
10118
10118
  short_strike = pos.get('short_strike', pos.get('far_strike'))
10119
10119
  if long_strike and short_strike:
10120
- # Infer option type: default to 'C' (call) unless position says otherwise
10121
- opt_type = 'C'
10122
- if pos.get('opt_type', '').upper().startswith('P'):
10123
- opt_type = 'P'
10120
+ opt_type = _norm_opt_type_char(dict(pos, strategy_type=strategy_type))
10124
10121
  # Check for per-leg expirations (diagonal/calendar)
10125
10122
  long_exp = pos.get('long_expiration', pos.get('near_expiration'))
10126
10123
  short_exp = pos.get('short_expiration', pos.get('far_expiration'))
@@ -10131,9 +10128,7 @@ class StopLossManager:
10131
10128
  elif pos.get('strike'):
10132
10129
  # Single-leg CUSTOM fallback
10133
10130
  strike = pos['strike']
10134
- opt_type = 'C'
10135
- if pos.get('opt_type', '').upper().startswith('P'):
10136
- opt_type = 'P'
10131
+ opt_type = _norm_opt_type_char(dict(pos, strategy_type=strategy_type))
10137
10132
  direction = 'short' if pos.get('is_short_bias') else 'long'
10138
10133
  legs.append({'strike': strike, 'type': opt_type, 'direction': direction,
10139
10134
  'entry_key': 'call_entry_bid' if opt_type == 'C' else 'put_entry_bid'})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ivolatility_backtesting
3
- Version: 2.153
3
+ Version: 2.154
4
4
  Summary: A universal backtesting framework for financial strategies using the IVolatility API.
5
5
  Author-email: IVolatility <support@ivolatility.com>
6
6
  Project-URL: Homepage, https://ivolatility.com
@@ -16,4 +16,5 @@ tests/test_2148_loader_memory.py
16
16
  tests/test_2149_client_errors.py
17
17
  tests/test_2150_prompt_patterns.py
18
18
  tests/test_2152_cache_lock_and_rate_limit.py
19
- tests/test_2153_cache_lock_kept.py
19
+ tests/test_2153_cache_lock_kept.py
20
+ tests/test_2154_put_atm_legs.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ivolatility_backtesting"
7
- version = "2.153"
7
+ version = "2.154"
8
8
  description = "A universal backtesting framework for financial strategies using the IVolatility API."
9
9
  readme = "README.md"
10
10
  authors = [
@@ -0,0 +1,78 @@
1
+ # Tests for the intraday-SL leg builder: option type of single-leg aliases without opt_type.
2
+ #
3
+ # Runs standalone (no pytest needed): python3 tests/test_2154_put_atm_legs.py
4
+ # Also pytest-compatible for CI: pytest tests/test_2154_put_atm_legs.py
5
+ import os
6
+ import sys
7
+ import traceback
8
+
9
+ import matplotlib
10
+ matplotlib.use('Agg')
11
+
12
+ _REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13
+ sys.path.insert(0, os.path.join(_REPO, 'ivolatility_backtesting'))
14
+ import ivolatility_backtesting as lib # noqa: E402
15
+
16
+
17
+ def _legs(pos):
18
+ return lib.StopLossManager()._get_position_legs(pos, pos['strategy_type'])
19
+
20
+
21
+ def test_short_put_atm_without_opt_type_is_a_short_put():
22
+ legs = _legs({'strategy_type': 'PUT_ATM', 'strike': 337.5, 'is_short_bias': True})
23
+ assert legs == [{'strike': 337.5, 'type': 'P', 'direction': 'short', 'entry_key': 'put_entry_bid'}], legs
24
+
25
+
26
+ def test_short_put_atm_with_opt_type_unchanged():
27
+ legs = _legs({'strategy_type': 'PUT_ATM', 'strike': 337.5, 'is_short_bias': True, 'opt_type': 'put'})
28
+ assert legs[0]['type'] == 'P' and legs[0]['direction'] == 'short', legs
29
+
30
+
31
+ def test_long_put_atm_without_opt_type_is_a_long_put():
32
+ legs = _legs({'strategy_type': 'PUT_ATM', 'strike': 337.5})
33
+ assert legs[0]['type'] == 'P' and legs[0]['direction'] == 'long', legs
34
+
35
+
36
+ def test_custom_single_leg_still_defaults_to_call():
37
+ legs = _legs({'strategy_type': 'CUSTOM', 'strike': 100.0, 'is_short_bias': True})
38
+ assert legs[0]['type'] == 'C' and legs[0]['entry_key'] == 'call_entry_bid', legs
39
+
40
+
41
+ def test_custom_spread_put_by_opt_type():
42
+ legs = _legs({'strategy_type': 'CUSTOM', 'long_strike': 95.0, 'short_strike': 100.0, 'opt_type': 'P'})
43
+ assert [lg['type'] for lg in legs] == ['P', 'P'], legs
44
+
45
+
46
+ def test_custom_spread_defaults_to_call():
47
+ legs = _legs({'strategy_type': 'CUSTOM', 'long_strike': 100.0, 'short_strike': 105.0})
48
+ assert [lg['type'] for lg in legs] == ['C', 'C'], legs
49
+
50
+
51
+ def test_put_spread_fallback_type_from_strategy_name():
52
+ legs = _legs({'strategy_type': 'PUT_ATM', 'long_strike': 95.0, 'short_strike': 100.0})
53
+ assert [lg['type'] for lg in legs] == ['P', 'P'], legs
54
+
55
+
56
+ def test_opt_type_none_takes_type_from_strategy_name():
57
+ legs = _legs({'strategy_type': 'PUT_ATM', 'strike': 337.5, 'is_short_bias': True, 'opt_type': None})
58
+ assert legs[0]['type'] == 'P' and legs[0]['direction'] == 'short', legs
59
+
60
+
61
+ def test_explicit_short_put_branch_unchanged():
62
+ legs = _legs({'strategy_type': 'SHORT_PUT', 'strike': 337.5})
63
+ assert legs == [{'strike': 337.5, 'type': 'P', 'direction': 'short', 'entry_key': 'put_entry_bid'}], legs
64
+
65
+
66
+ if __name__ == '__main__':
67
+ failed = 0
68
+ tests = [(n, f) for n, f in sorted(globals().items()) if n.startswith('test_') and callable(f)]
69
+ for name, fn in tests:
70
+ try:
71
+ fn()
72
+ print(f'PASS {name}')
73
+ except Exception:
74
+ failed += 1
75
+ print(f'FAIL {name}')
76
+ traceback.print_exc()
77
+ print(f'{len(tests) - failed}/{len(tests)} passed')
78
+ sys.exit(1 if failed else 0)