ivolatility-backtesting 2.164__tar.gz → 2.165__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.
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/PKG-INFO +4 -3
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting/ivolatility_backtesting.py +30 -1
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting.egg-info/PKG-INFO +4 -3
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting.egg-info/SOURCES.txt +2 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting.egg-info/requires.txt +2 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/pyproject.toml +4 -3
- ivolatility_backtesting-2.165/tests/test_2165_parquet_engine_error.py +55 -0
- ivolatility_backtesting-2.165/tests/test_2165_renamed_symbol.py +115 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/README.md +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting/__init__.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting.egg-info/dependency_links.txt +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting.egg-info/top_level.txt +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/setup.cfg +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2142_fixes.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2144_duckdb_dedup.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2146_vix_vro.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2147_cents_multiplier.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2148_loader_memory.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2149_client_errors.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2150_prompt_patterns.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2152_cache_lock_and_rate_limit.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2153_cache_lock_kept.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2154_put_atm_legs.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_bar_prefetch.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_intraday_exits.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_ivx_stock_holes.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_key_redaction.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_long_expiry.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_opt_stop_merge.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2156_phantom_quotes.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2157_sl_symbol.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2158_default_path_golden.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2158_entry_time.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2159_entry_rule.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_day_price_order.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_exit_rule.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_option_lean_rule.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_prefetch_cancel.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2161_assignment.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2162_entry_minute_window.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2163_rotation.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2164_stock_price_stops.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_price_ta_indicators.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_stock_loader_coverage.py +0 -0
- {ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_vix_percentile_direction.py +0 -0
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ivolatility_backtesting
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.165
|
|
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
|
|
7
7
|
Keywords: backtesting,finance,trading,ivolatility
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
10
9
|
Classifier: Programming Language :: Python :: 3.9
|
|
11
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
14
|
Classifier: Operating System :: OS Independent
|
|
16
|
-
Requires-Python: >=3.
|
|
15
|
+
Requires-Python: >=3.9
|
|
17
16
|
Description-Content-Type: text/markdown
|
|
18
17
|
Requires-Dist: pandas<3.0,>=1.5.0
|
|
19
18
|
Requires-Dist: numpy<3.0,>=1.21.0
|
|
@@ -21,6 +20,8 @@ Requires-Dist: matplotlib>=3.5.0
|
|
|
21
20
|
Requires-Dist: seaborn>=0.11.0
|
|
22
21
|
Requires-Dist: ivolatility>=1.9.6
|
|
23
22
|
Requires-Dist: psutil>=7.1.0
|
|
23
|
+
Requires-Dist: fastparquet>=2023.1.0
|
|
24
|
+
Requires-Dist: duckdb>=1.0.0
|
|
24
25
|
|
|
25
26
|
# IVolatility Backtesting Framework v1.32
|
|
26
27
|
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
# 4. ASYNC parallel chunk loading (~10x faster preload)
|
|
9
9
|
# ============================================================
|
|
10
10
|
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
11
13
|
import atexit
|
|
12
14
|
import bisect
|
|
13
15
|
import collections
|
|
@@ -8429,7 +8431,25 @@ def _is_client_error(exc):
|
|
|
8429
8431
|
return status is not None and 400 <= status < 500 and status != 429
|
|
8430
8432
|
|
|
8431
8433
|
|
|
8432
|
-
def
|
|
8434
|
+
def _stamp_requested_symbol(normalized, endpoint, params):
|
|
8435
|
+
"""API returns the pre-rename symbol in older rows (FB for META); readers key on `symbol`, so stamp the requested one."""
|
|
8436
|
+
if not isinstance(normalized, dict) or '/equities/eod/stock-prices' not in str(endpoint):
|
|
8437
|
+
return normalized
|
|
8438
|
+
sym = params.get('symbol')
|
|
8439
|
+
if not isinstance(sym, str) or not sym.strip() or ',' in sym or ' ' in sym.strip():
|
|
8440
|
+
return normalized
|
|
8441
|
+
data = normalized.get('data')
|
|
8442
|
+
if isinstance(data, pd.DataFrame):
|
|
8443
|
+
if not data.empty:
|
|
8444
|
+
data = data.copy()
|
|
8445
|
+
data['symbol'] = sym
|
|
8446
|
+
normalized = dict(normalized, data=data)
|
|
8447
|
+
elif isinstance(data, list) and data and isinstance(data[0], dict):
|
|
8448
|
+
normalized = dict(normalized, data=[dict(r, symbol=sym) for r in data])
|
|
8449
|
+
return normalized
|
|
8450
|
+
|
|
8451
|
+
|
|
8452
|
+
def api_call(endpoint, cache_config=None, debug=False, max_retries=3, skip_parquet_cache=False,
|
|
8433
8453
|
_chunk_info=None, **kwargs):
|
|
8434
8454
|
"""
|
|
8435
8455
|
Make API call with automatic response normalization, caching, and retry logic
|
|
@@ -8890,6 +8910,7 @@ def _api_call_internal(endpoint, cache_config, debug, debug_level, skip_parquet_
|
|
|
8890
8910
|
# TIMING: Response normalization
|
|
8891
8911
|
t_normalize_start = time.perf_counter()
|
|
8892
8912
|
normalized = APIHelper.normalize_response(response, debug=debug)
|
|
8913
|
+
normalized = _stamp_requested_symbol(normalized, endpoint, kwargs)
|
|
8893
8914
|
t_normalize_elapsed = (time.perf_counter() - t_normalize_start) * 1000 # ms
|
|
8894
8915
|
_bt_logger.info(f"[DIAG] NORMALIZE END {_ci_str} thread={_tid_diag} elapsed={t_normalize_elapsed:.0f}ms")
|
|
8895
8916
|
|
|
@@ -29719,6 +29740,10 @@ def get_cache_config(disk_enabled: bool = True, memory_enabled: bool = True,
|
|
|
29719
29740
|
# ============================================================
|
|
29720
29741
|
# CACHE MODES (unified caching architecture)
|
|
29721
29742
|
# ============================================================
|
|
29743
|
+
_PARQUET_ENGINE_MISSING = ("parquet engine missing: cached chunks cannot be written, so the backtest would run on 0 rows; "
|
|
29744
|
+
"run `pip install fastparquet` (installed with ivolatility_backtesting>=2.165) or `pip install pyarrow`")
|
|
29745
|
+
|
|
29746
|
+
|
|
29722
29747
|
class CacheMode:
|
|
29723
29748
|
"""Cache mode constants for unified caching architecture."""
|
|
29724
29749
|
ORIGINAL_PARQUET = 'original_parquet' # pandas reads Parquet one-by-one (legacy)
|
|
@@ -30038,6 +30063,8 @@ class UniversalCacheManager:
|
|
|
30038
30063
|
df.to_parquet(file_path, compression='snappy')
|
|
30039
30064
|
else:
|
|
30040
30065
|
df.to_parquet(file_path)
|
|
30066
|
+
except ImportError as e:
|
|
30067
|
+
raise RuntimeError(_PARQUET_ENGINE_MISSING) from e
|
|
30041
30068
|
except Exception as e:
|
|
30042
30069
|
if self.debug:
|
|
30043
30070
|
print(f"[CACHE] ❌ Error saving to disk: {e}")
|
|
@@ -30539,6 +30566,8 @@ class UniversalCacheManager:
|
|
|
30539
30566
|
df.to_parquet(filepath, index=False, compression='snappy')
|
|
30540
30567
|
else:
|
|
30541
30568
|
df.to_parquet(filepath, index=False)
|
|
30569
|
+
except ImportError as e:
|
|
30570
|
+
raise RuntimeError(_PARQUET_ENGINE_MISSING) from e
|
|
30542
30571
|
except Exception as e:
|
|
30543
30572
|
if self.debug:
|
|
30544
30573
|
print(f"[CACHE] ❌ Error saving chunk: {e}")
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ivolatility_backtesting
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.165
|
|
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
|
|
7
7
|
Keywords: backtesting,finance,trading,ivolatility
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
10
9
|
Classifier: Programming Language :: Python :: 3.9
|
|
11
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
14
|
Classifier: Operating System :: OS Independent
|
|
16
|
-
Requires-Python: >=3.
|
|
15
|
+
Requires-Python: >=3.9
|
|
17
16
|
Description-Content-Type: text/markdown
|
|
18
17
|
Requires-Dist: pandas<3.0,>=1.5.0
|
|
19
18
|
Requires-Dist: numpy<3.0,>=1.21.0
|
|
@@ -21,6 +20,8 @@ Requires-Dist: matplotlib>=3.5.0
|
|
|
21
20
|
Requires-Dist: seaborn>=0.11.0
|
|
22
21
|
Requires-Dist: ivolatility>=1.9.6
|
|
23
22
|
Requires-Dist: psutil>=7.1.0
|
|
23
|
+
Requires-Dist: fastparquet>=2023.1.0
|
|
24
|
+
Requires-Dist: duckdb>=1.0.0
|
|
24
25
|
|
|
25
26
|
# IVolatility Backtesting Framework v1.32
|
|
26
27
|
|
|
@@ -37,6 +37,8 @@ tests/test_2161_assignment.py
|
|
|
37
37
|
tests/test_2162_entry_minute_window.py
|
|
38
38
|
tests/test_2163_rotation.py
|
|
39
39
|
tests/test_2164_stock_price_stops.py
|
|
40
|
+
tests/test_2165_parquet_engine_error.py
|
|
41
|
+
tests/test_2165_renamed_symbol.py
|
|
40
42
|
tests/test_price_ta_indicators.py
|
|
41
43
|
tests/test_stock_loader_coverage.py
|
|
42
44
|
tests/test_vix_percentile_direction.py
|
|
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ivolatility_backtesting"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.165"
|
|
8
8
|
description = "A universal backtesting framework for financial strategies using the IVolatility API."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name = "IVolatility", email = "support@ivolatility.com" }
|
|
12
12
|
]
|
|
13
13
|
license = { file = "LICENSE" }
|
|
14
|
-
requires-python = ">=3.
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
15
|
dependencies = [
|
|
16
16
|
"pandas>=1.5.0,<3.0",
|
|
17
17
|
"numpy>=1.21.0,<3.0",
|
|
@@ -19,11 +19,12 @@ dependencies = [
|
|
|
19
19
|
"seaborn>=0.11.0",
|
|
20
20
|
"ivolatility>=1.9.6",
|
|
21
21
|
"psutil>=7.1.0",
|
|
22
|
+
"fastparquet>=2023.1.0",
|
|
23
|
+
"duckdb>=1.0.0",
|
|
22
24
|
]
|
|
23
25
|
keywords = ["backtesting", "finance", "trading", "ivolatility"]
|
|
24
26
|
classifiers = [
|
|
25
27
|
"Programming Language :: Python :: 3",
|
|
26
|
-
"Programming Language :: Python :: 3.8",
|
|
27
28
|
"Programming Language :: Python :: 3.9",
|
|
28
29
|
"Programming Language :: Python :: 3.10",
|
|
29
30
|
"Programming Language :: Python :: 3.11",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Missing parquet engine must raise RuntimeError, never cache an empty file; pyproject must pin fastparquet and duckdb; the module must import on Python 3.9."""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
_TESTS = os.path.dirname(os.path.abspath(__file__))
|
|
10
|
+
sys.path.insert(0, _TESTS)
|
|
11
|
+
from test_2158_entry_time import lib # noqa: E402
|
|
12
|
+
|
|
13
|
+
PYPROJECT = os.path.join(os.path.dirname(_TESTS), 'pyproject.toml')
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _no_engine(*args, **kwargs):
|
|
17
|
+
raise ImportError("Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _df():
|
|
21
|
+
return pd.DataFrame({'date': pd.bdate_range('2024-01-02', periods=3), 'close': [1.0, 2.0, 3.0]})
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_set_chunk_without_engine_raises_clear_error(monkeypatch):
|
|
25
|
+
monkeypatch.setattr(pd.DataFrame, 'to_parquet', _no_engine)
|
|
26
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
27
|
+
cm = lib.UniversalCacheManager({'cache_dir': tmp, 'memory_enabled': False, 'bulk_concat': True})
|
|
28
|
+
with pytest.raises(RuntimeError, match='fastparquet'):
|
|
29
|
+
cm.set_chunk(_df(), symbol='SPY', start_date='2024-01-02', end_date='2024-01-04', data_type='stock')
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_save_to_disk_without_engine_raises_clear_error(monkeypatch):
|
|
33
|
+
monkeypatch.setattr(pd.DataFrame, 'to_parquet', _no_engine)
|
|
34
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
35
|
+
cm = lib.UniversalCacheManager({'cache_dir': tmp, 'memory_enabled': False})
|
|
36
|
+
with pytest.raises(RuntimeError, match='fastparquet'):
|
|
37
|
+
cm._save_to_disk(os.path.join(tmp, 'x.parquet'), _df())
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_set_chunk_with_engine_still_saves():
|
|
41
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
42
|
+
cm = lib.UniversalCacheManager({'cache_dir': tmp, 'memory_enabled': False, 'bulk_concat': True})
|
|
43
|
+
assert cm.set_chunk(_df(), symbol='SPY', start_date='2024-01-02', end_date='2024-01-04', data_type='stock')
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_pyproject_declares_cache_engines():
|
|
47
|
+
text = open(PYPROJECT, encoding='utf-8').read()
|
|
48
|
+
assert '"fastparquet' in text
|
|
49
|
+
assert '"duckdb' in text
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_module_annotations_are_lazy_for_python_39():
|
|
53
|
+
src = open(lib.__file__, encoding='utf-8').read()
|
|
54
|
+
first_stmt = next(l for l in src.splitlines() if l.strip() and not l.lstrip().startswith('#'))
|
|
55
|
+
assert first_stmt == 'from __future__ import annotations'
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Daily prices of a renamed ticker (META, formerly FB) must land under the requested symbol:
|
|
2
|
+
# the API labels pre-rename rows with the old symbol, every reader filters on `symbol`.
|
|
3
|
+
#
|
|
4
|
+
# Runs standalone (no pytest needed): python3 tests/test_2165_renamed_symbol.py
|
|
5
|
+
# Also pytest-compatible for CI: pytest tests/test_2165_renamed_symbol.py
|
|
6
|
+
import contextlib
|
|
7
|
+
import io
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
import tempfile
|
|
11
|
+
import traceback
|
|
12
|
+
|
|
13
|
+
os.environ['HOME'] = tempfile.mkdtemp(prefix='ivb_home_')
|
|
14
|
+
import matplotlib # noqa: E402
|
|
15
|
+
matplotlib.use('Agg')
|
|
16
|
+
|
|
17
|
+
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
18
|
+
sys.path.insert(0, os.path.join(_REPO, 'ivolatility_backtesting'))
|
|
19
|
+
import pandas as pd # noqa: E402
|
|
20
|
+
import ivolatility_backtesting as lib # noqa: E402
|
|
21
|
+
|
|
22
|
+
RENAME = pd.Timestamp('2022-06-09')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _api_rows(start, end):
|
|
26
|
+
"""What /equities/eod/stock-prices?symbol=META returns: FB before the rename, META after."""
|
|
27
|
+
rows = []
|
|
28
|
+
for i, d in enumerate(pd.bdate_range(start, end)):
|
|
29
|
+
rows.append({'record_no': i + 1, 'date': d.strftime('%Y-%m-%d'),
|
|
30
|
+
'symbol': 'FB' if d < RENAME else 'META', 'exchange': 'NASDAQ',
|
|
31
|
+
'open': 100.0 + i, 'high': 101.0 + i, 'low': 99.0 + i, 'close': 100.5 + i,
|
|
32
|
+
'volume': 1000, 'unadjusted_close': 100.5 + i})
|
|
33
|
+
return rows
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _fake_method(endpoint, calls):
|
|
37
|
+
def method(**kw):
|
|
38
|
+
calls.append((endpoint, dict(kw)))
|
|
39
|
+
if endpoint == '/equities/eod/stock-prices':
|
|
40
|
+
return {'status': 'ok', 'data': _api_rows(kw['from_'], kw['to'])}
|
|
41
|
+
return {'status': 'ok', 'data': []}
|
|
42
|
+
return method
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_REAL_API_CALL = lib.api_call # other test modules replace lib.api_call for good
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@contextlib.contextmanager
|
|
49
|
+
def _patched_api(calls):
|
|
50
|
+
saved = (lib.APIManager.get_method, lib.api_call)
|
|
51
|
+
lib.APIManager.get_method = staticmethod(lambda endpoint: _fake_method(endpoint, calls))
|
|
52
|
+
lib.api_call = _REAL_API_CALL
|
|
53
|
+
try:
|
|
54
|
+
yield
|
|
55
|
+
finally:
|
|
56
|
+
lib.APIManager.get_method, lib.api_call = saved
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_api_call_stamps_requested_symbol():
|
|
60
|
+
calls = []
|
|
61
|
+
with _patched_api(calls), contextlib.redirect_stdout(io.StringIO()):
|
|
62
|
+
out = lib.api_call('/equities/eod/stock-prices', symbol='META', from_='2022-06-01', to='2022-06-15')
|
|
63
|
+
data = out['data'] if isinstance(out, dict) else out
|
|
64
|
+
data = data if isinstance(data, pd.DataFrame) else pd.DataFrame(data)
|
|
65
|
+
assert set(data['symbol']) == {'META'}, set(data['symbol'])
|
|
66
|
+
assert len(data) == len(pd.bdate_range('2022-06-01', '2022-06-15'))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_other_endpoints_and_symbol_lists_untouched():
|
|
70
|
+
rows = [{'date': '2022-06-01', 'symbol': 'FB'}]
|
|
71
|
+
same = lib._stamp_requested_symbol({'data': rows}, '/equities/eod/ivx', {'symbol': 'META'})
|
|
72
|
+
assert same['data'][0]['symbol'] == 'FB'
|
|
73
|
+
same = lib._stamp_requested_symbol({'data': rows}, '/equities/eod/stock-prices', {'symbol': 'META,FB'})
|
|
74
|
+
assert same['data'][0]['symbol'] == 'FB'
|
|
75
|
+
assert lib._stamp_requested_symbol(None, '/equities/eod/stock-prices', {'symbol': 'META'}) is None
|
|
76
|
+
df_in = {'data': pd.DataFrame(rows), '_is_df': True}
|
|
77
|
+
assert lib._stamp_requested_symbol(df_in, '/equities/eod/stock-prices', {'symbol': 'META'})['data']['symbol'].tolist() == ['META']
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_duckdb_loader_keeps_pre_rename_history_under_requested_symbol():
|
|
81
|
+
tmp = tempfile.mkdtemp(prefix='ivb_rename_')
|
|
82
|
+
cc = lib._normalize_cache_config({'cache_mode': 'duckdb_SSD_storage', 'cache_dir': tmp, 'disk_enabled': True})
|
|
83
|
+
start, end = '2022-05-02', '2022-07-15'
|
|
84
|
+
calls = []
|
|
85
|
+
with _patched_api(calls), contextlib.redirect_stdout(io.StringIO()):
|
|
86
|
+
df = lib._load_stock_to_duckdb({'symbol': 'META'}, cc, 'META', start, end)
|
|
87
|
+
expected = len(pd.bdate_range(start, end))
|
|
88
|
+
assert df is not None and len(df) == expected, (None if df is None else len(df), expected)
|
|
89
|
+
assert set(df['symbol']) == {'META'}, set(df['symbol'])
|
|
90
|
+
|
|
91
|
+
conn = lib._get_duckdb_storage_conn(cc)
|
|
92
|
+
n_meta = conn.execute("SELECT COUNT(*) FROM stock_eod WHERE symbol = 'META'").fetchone()[0]
|
|
93
|
+
n_fb = conn.execute("SELECT COUNT(*) FROM stock_eod WHERE symbol = 'FB'").fetchone()[0]
|
|
94
|
+
first = conn.execute("SELECT MIN(date) FROM stock_eod WHERE symbol = 'META'").fetchone()[0]
|
|
95
|
+
assert n_meta == expected and n_fb == 0, (n_meta, n_fb)
|
|
96
|
+
assert str(first) == start, first
|
|
97
|
+
|
|
98
|
+
ta = lib.calculate_price_ta_indicator(df, sma_period=5, ma_fast_period=3, ma_slow_period=5,
|
|
99
|
+
donchian_period=5, roc_period=3, rsi_wilder_period=3)
|
|
100
|
+
assert len(ta) == expected
|
|
101
|
+
assert ta.sort_values('date')['sma'].isna().sum() == 4, 'one warm-up, not one per symbol'
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__ == '__main__':
|
|
105
|
+
failed = 0
|
|
106
|
+
for name, fn in sorted(globals().items()):
|
|
107
|
+
if name.startswith('test_') and callable(fn):
|
|
108
|
+
try:
|
|
109
|
+
fn()
|
|
110
|
+
print(f'PASS {name}')
|
|
111
|
+
except Exception:
|
|
112
|
+
failed += 1
|
|
113
|
+
print(f'FAIL {name}')
|
|
114
|
+
traceback.print_exc()
|
|
115
|
+
sys.exit(1 if failed else 0)
|
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/ivolatility_backtesting/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2144_duckdb_dedup.py
RENAMED
|
File without changes
|
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2147_cents_multiplier.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2148_loader_memory.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2149_client_errors.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2150_prompt_patterns.py
RENAMED
|
File without changes
|
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2153_cache_lock_kept.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2154_put_atm_legs.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_bar_prefetch.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_intraday_exits.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_ivx_stock_holes.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_key_redaction.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_long_expiry.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2155_opt_stop_merge.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2156_phantom_quotes.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2157_sl_symbol.py
RENAMED
|
File without changes
|
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2158_entry_time.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2159_entry_rule.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_day_price_order.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_exit_rule.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_option_lean_rule.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2160_prefetch_cancel.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2161_assignment.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_2164_stock_price_stops.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_price_ta_indicators.py
RENAMED
|
File without changes
|
{ivolatility_backtesting-2.164 → ivolatility_backtesting-2.165}/tests/test_stock_loader_coverage.py
RENAMED
|
File without changes
|
|
File without changes
|