voly 0.0.186__tar.gz → 0.0.187__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.
- {voly-0.0.186/src/voly.egg-info → voly-0.0.187}/PKG-INFO +1 -1
- {voly-0.0.186 → voly-0.0.187}/pyproject.toml +2 -2
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/fit.py +57 -0
- {voly-0.0.186 → voly-0.0.187/src/voly.egg-info}/PKG-INFO +1 -1
- {voly-0.0.186 → voly-0.0.187}/LICENSE +0 -0
- {voly-0.0.186 → voly-0.0.187}/README.md +0 -0
- {voly-0.0.186 → voly-0.0.187}/setup.cfg +0 -0
- {voly-0.0.186 → voly-0.0.187}/setup.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/__init__.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/client.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/__init__.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/charts.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/data.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/hd.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/interpolate.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/core/rnd.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/exceptions.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/formulas.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/models.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/utils/__init__.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/utils/density.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly/utils/logger.py +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly.egg-info/SOURCES.txt +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly.egg-info/dependency_links.txt +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly.egg-info/requires.txt +0 -0
- {voly-0.0.186 → voly-0.0.187}/src/voly.egg-info/top_level.txt +0 -0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "voly"
|
7
|
-
version = "0.0.
|
7
|
+
version = "0.0.187"
|
8
8
|
description = "Options & volatility research package"
|
9
9
|
readme = "README.md"
|
10
10
|
authors = [
|
@@ -60,7 +60,7 @@ line_length = 100
|
|
60
60
|
multi_line_output = 3
|
61
61
|
|
62
62
|
[tool.mypy]
|
63
|
-
python_version = "0.0.
|
63
|
+
python_version = "0.0.187"
|
64
64
|
warn_return_any = true
|
65
65
|
warn_unused_configs = true
|
66
66
|
disallow_untyped_defs = true
|
@@ -370,3 +370,60 @@ def fit_model(option_chain: pd.DataFrame) -> pd.DataFrame:
|
|
370
370
|
|
371
371
|
logger.info("Model fitting complete.")
|
372
372
|
return results_df
|
373
|
+
|
374
|
+
|
375
|
+
@catch_exception
|
376
|
+
def get_iv_surface(model_results: pd.DataFrame,
|
377
|
+
domain_params: Tuple[float, float, int] = (-1.5, 1.5, 1000),
|
378
|
+
return_domain: str = 'log_moneyness') -> Tuple[Dict[str, np.ndarray], Dict[str, np.ndarray]]:
|
379
|
+
"""
|
380
|
+
Generate implied volatility surface using optimized SVI parameters.
|
381
|
+
|
382
|
+
Works with both regular fit_results and interpolated_results dataframes.
|
383
|
+
|
384
|
+
Parameters:
|
385
|
+
- model_results: DataFrame from fit_model() or interpolate_model(). Maturity names or DTM as Index
|
386
|
+
- domain_params: Tuple of (min, max, num_points) for the log-moneyness array
|
387
|
+
- return_domain: Domain for x-axis values ('log_moneyness', 'moneyness', 'returns', 'strikes', 'delta')
|
388
|
+
|
389
|
+
Returns:
|
390
|
+
- Tuple of (iv_surface, x_surface)
|
391
|
+
iv_surface: Dictionary mapping maturity/dtm names to IV arrays
|
392
|
+
x_surface: Dictionary mapping maturity/dtm names to requested x domain arrays
|
393
|
+
"""
|
394
|
+
# Check if required columns are present
|
395
|
+
required_columns = ['a', 'b', 'm', 'rho', 'sigma', 't']
|
396
|
+
missing_columns = [col for col in required_columns if col not in model_results.columns]
|
397
|
+
if missing_columns:
|
398
|
+
raise VolyError(f"Required columns missing in model_results: {missing_columns}")
|
399
|
+
|
400
|
+
# Generate implied volatility surface in log-moneyness domain
|
401
|
+
LM = np.linspace(domain_params[0], domain_params[1], domain_params[2])
|
402
|
+
|
403
|
+
iv_surface = {}
|
404
|
+
x_surface = {}
|
405
|
+
|
406
|
+
# Process each maturity/dtm
|
407
|
+
for i in model_results.index:
|
408
|
+
# Calculate SVI total implied variance and convert to IV
|
409
|
+
params = [
|
410
|
+
model_results.loc[i, 'a'],
|
411
|
+
model_results.loc[i, 'b'],
|
412
|
+
model_results.loc[i, 'm'],
|
413
|
+
model_results.loc[i, 'rho'],
|
414
|
+
model_results.loc[i, 'sigma']
|
415
|
+
]
|
416
|
+
s = model_results.loc[i, 's']
|
417
|
+
r = model_results.loc[i, 'r']
|
418
|
+
t = model_results.loc[i, 't']
|
419
|
+
|
420
|
+
# Calculate implied volatility
|
421
|
+
w = np.array([SVIModel.svi(x, *params) for x in LM])
|
422
|
+
o = np.sqrt(w / t)
|
423
|
+
iv_surface[i] = o
|
424
|
+
|
425
|
+
# Calculate x domain for this maturity/dtm
|
426
|
+
x = get_domain(domain_params, s, r, o, t, return_domain)
|
427
|
+
x_surface[i] = x
|
428
|
+
|
429
|
+
return iv_surface, x_surface
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|