voly 0.0.186__py3-none-any.whl → 0.0.187__py3-none-any.whl

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/core/fit.py CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: voly
3
- Version: 0.0.186
3
+ Version: 0.0.187
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
@@ -6,15 +6,15 @@ voly/models.py,sha256=2aNGsF3joCx4jGbiF8m0zxEW_nvcSBERSYPSKCXV3us,7019
6
6
  voly/core/__init__.py,sha256=bu6fS2I1Pj9fPPnl-zY3L7NqrZSY5Zy6NY2uMUvdhKs,183
7
7
  voly/core/charts.py,sha256=2S-BfCo30aj1_xlNLqF-za5rQWxF_mWKIdtdOe5bgbw,12735
8
8
  voly/core/data.py,sha256=9v9iuE2XdIIlzoRAB7q1ol7YghBzBsPGAiwZ11oDuis,13650
9
- voly/core/fit.py,sha256=pfGRzycJ9WERHc-nIowpWQQ8nZbGHlOlRDUxgkkfvnY,15448
9
+ voly/core/fit.py,sha256=9OxPK9wB3Z9qKqJY3VHEeyGMXTbcQIerpdNVvv9uEzc,17685
10
10
  voly/core/hd.py,sha256=UFAyLncNUHivpPAcko6IK1bC55mudVtdlRFfXp63HXE,14771
11
11
  voly/core/interpolate.py,sha256=JkK172-FXyhesW3hY4pEeuJWG3Bugq7QZXbeKoRpLuo,5305
12
12
  voly/core/rnd.py,sha256=GoC3m1Q46Wnk5tV_mstr-3_aktHeue6BBLh4DQTciW0,13307
13
13
  voly/utils/__init__.py,sha256=E05mWatyC-PDOsCxQV1p5Xi1IgpOomxrNURyCx_gB-w,200
14
14
  voly/utils/density.py,sha256=q0fX4im9TGwMCZ32Hzdv8CNh56KnJo8bmG5w0gVWZH8,5879
15
15
  voly/utils/logger.py,sha256=4-_2bVJmq17Q0d7Rd2mPg1AeR8gxv6EPvcmBDMFWcSM,1744
16
- voly-0.0.186.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
17
- voly-0.0.186.dist-info/METADATA,sha256=GUbTWWjdupPDNj3wHCYQ5b5qu0hmHWNsO8KPXRKpAW8,4115
18
- voly-0.0.186.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
19
- voly-0.0.186.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
20
- voly-0.0.186.dist-info/RECORD,,
16
+ voly-0.0.187.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
17
+ voly-0.0.187.dist-info/METADATA,sha256=KgUZUqhsINQLwpKamaL2tU5iZFJyrWk_Yo8K5L4gYHo,4115
18
+ voly-0.0.187.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
19
+ voly-0.0.187.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
20
+ voly-0.0.187.dist-info/RECORD,,
File without changes