voly 0.0.38__tar.gz → 0.0.40__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: voly
3
- Version: 0.0.38
3
+ Version: 0.0.40
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "voly"
7
- version = "0.0.38"
7
+ version = "0.0.40"
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.38"
63
+ python_version = "0.0.40"
64
64
  warn_return_any = true
65
65
  warn_unused_configs = true
66
66
  disallow_untyped_defs = true
@@ -346,13 +346,13 @@ def plot_fit_performance(fit_performance: pd.DataFrame) -> go.Figure:
346
346
 
347
347
 
348
348
  @catch_exception
349
- def plot_3d_surface(moneyness_grid: np.ndarray,
349
+ def plot_3d_surface(moneyness_array: np.ndarray,
350
350
  iv_surface: dict[float, np.ndarray]) -> go.Figure:
351
351
  """
352
352
  Plot 3D implied volatility surface.
353
353
 
354
354
  Parameters:
355
- - moneyness_grid: grid of moneyness values
355
+ - moneyness_array: grid of moneyness values
356
356
  - iv_surface: Dictionary mapping expiry times to IV arrays
357
357
 
358
358
  Returns:
@@ -361,13 +361,13 @@ def plot_3d_surface(moneyness_grid: np.ndarray,
361
361
  start_color = '#60AEFC'
362
362
  end_color = '#002040' # Darker blue
363
363
  custom_blue_scale = [[0, start_color], [1, end_color]]
364
- yte_values = list(iv_surface.keys())
364
+ maturities = list(iv_surface.keys())
365
365
 
366
366
  # Convert implied volatility surface to array
367
- z_array = np.array([iv_surface[t] for t in yte_values])
367
+ z_array = np.array([iv_surface[m] for m in maturities])
368
368
 
369
369
  # Create mesh grid
370
- X, Y = np.meshgrid(moneyness_grid, yte_values)
370
+ X, Y = np.meshgrid(moneyness_array, maturities)
371
371
  Z = z_array * 100 # Convert to percentage
372
372
 
373
373
  # Create 3D surface plot with custom blue colorscale
@@ -393,7 +393,7 @@ def plot_3d_surface(moneyness_grid: np.ndarray,
393
393
 
394
394
 
395
395
  @catch_exception
396
- def plot_rnd(moneyness_grid: np.ndarray,
396
+ def plot_rnd(moneyness_array: np.ndarray,
397
397
  rnd_values: np.ndarray,
398
398
  spot_price: float = 1.0,
399
399
  title: str = 'Risk-Neutral Density') -> go.Figure:
@@ -401,7 +401,7 @@ def plot_rnd(moneyness_grid: np.ndarray,
401
401
  Plot risk-neutral density (RND).
402
402
 
403
403
  Parameters:
404
- - moneyness_grid: Grid of log-moneyness values
404
+ - moneyness_array: Grid of log-moneyness values
405
405
  - rnd_values: RND values
406
406
  - spot_price: Spot price for converting to absolute prices
407
407
  - title: Plot title
@@ -413,10 +413,10 @@ def plot_rnd(moneyness_grid: np.ndarray,
413
413
  fig = go.Figure()
414
414
 
415
415
  # Convert to prices and normalize RND
416
- prices = spot_price * np.exp(moneyness_grid)
416
+ prices = spot_price * np.exp(moneyness_array)
417
417
 
418
418
  # Normalize the RND to integrate to 1
419
- dx = moneyness_grid[1] - moneyness_grid[0]
419
+ dx = moneyness_array[1] - moneyness_array[0]
420
420
  total_density = np.sum(rnd_values) * dx
421
421
  normalized_rnd = rnd_values / total_density if total_density > 0 else rnd_values
422
422
 
@@ -463,7 +463,7 @@ def plot_rnd(moneyness_grid: np.ndarray,
463
463
 
464
464
 
465
465
  @catch_exception
466
- def plot_rnd_all_expiries(moneyness_grid: np.ndarray,
466
+ def plot_rnd_all_expiries(moneyness_array: np.ndarray,
467
467
  rnd_surface: Dict[str, np.ndarray],
468
468
  param_matrix: pd.DataFrame,
469
469
  spot_price: float = 1.0) -> go.Figure:
@@ -471,7 +471,7 @@ def plot_rnd_all_expiries(moneyness_grid: np.ndarray,
471
471
  Plot risk-neutral densities for all expiries.
472
472
 
473
473
  Parameters:
474
- - moneyness_grid: Grid of log-moneyness values
474
+ - moneyness_array: Grid of log-moneyness values
475
475
  - rnd_surface: Dictionary mapping maturity names to RND arrays
476
476
  - param_matrix: Matrix containing model parameters with maturity info
477
477
  - spot_price: Spot price for converting to absolute prices
@@ -494,7 +494,7 @@ def plot_rnd_all_expiries(moneyness_grid: np.ndarray,
494
494
  for i in range(n_maturities)]
495
495
 
496
496
  # Convert to prices
497
- prices = spot_price * np.exp(moneyness_grid)
497
+ prices = spot_price * np.exp(moneyness_array)
498
498
 
499
499
  # Add traces for each expiry
500
500
  for i, maturity_name in enumerate(maturity_names):
@@ -502,7 +502,7 @@ def plot_rnd_all_expiries(moneyness_grid: np.ndarray,
502
502
  dte = dte_values[maturity_name]
503
503
 
504
504
  # Normalize the RND
505
- dx = moneyness_grid[1] - moneyness_grid[0]
505
+ dx = moneyness_array[1] - moneyness_array[0]
506
506
  total_density = np.sum(rnd) * dx
507
507
  normalized_rnd = rnd / total_density if total_density > 0 else rnd
508
508
 
@@ -543,7 +543,7 @@ def plot_rnd_all_expiries(moneyness_grid: np.ndarray,
543
543
 
544
544
 
545
545
  @catch_exception
546
- def plot_rnd_3d(moneyness_grid: np.ndarray,
546
+ def plot_rnd_3d(moneyness_array: np.ndarray,
547
547
  rnd_surface: Dict[str, np.ndarray],
548
548
  param_matrix: pd.DataFrame,
549
549
  spot_price: float = 1.0) -> go.Figure:
@@ -551,7 +551,7 @@ def plot_rnd_3d(moneyness_grid: np.ndarray,
551
551
  Plot 3D surface of risk-neutral densities.
552
552
 
553
553
  Parameters:
554
- - moneyness_grid: Grid of log-moneyness values
554
+ - moneyness_array: Grid of log-moneyness values
555
555
  - rnd_surface: Dictionary mapping maturity names to RND arrays
556
556
  - param_matrix: Matrix containing model parameters with maturity info
557
557
  - spot_price: Spot price for converting to absolute prices
@@ -569,7 +569,7 @@ def plot_rnd_3d(moneyness_grid: np.ndarray,
569
569
  dte_list = [dte_values[name] for name in maturity_names]
570
570
 
571
571
  # Convert to prices
572
- prices = spot_price * np.exp(moneyness_grid)
572
+ prices = spot_price * np.exp(moneyness_array)
573
573
 
574
574
  # Create z-data matrix and normalize RNDs
575
575
  z_data = np.zeros((len(maturity_names), len(prices)))
@@ -578,7 +578,7 @@ def plot_rnd_3d(moneyness_grid: np.ndarray,
578
578
  rnd = rnd_surface[name]
579
579
 
580
580
  # Normalize the RND
581
- dx = moneyness_grid[1] - moneyness_grid[0]
581
+ dx = moneyness_array[1] - moneyness_array[0]
582
582
  total_density = np.sum(rnd) * dx
583
583
  normalized_rnd = rnd / total_density if total_density > 0 else rnd
584
584
 
@@ -770,7 +770,7 @@ def plot_rnd_statistics(rnd_statistics: pd.DataFrame,
770
770
 
771
771
 
772
772
  @catch_exception
773
- def plot_cdf(moneyness_grid: np.ndarray,
773
+ def plot_cdf(moneyness_array: np.ndarray,
774
774
  rnd_values: np.ndarray,
775
775
  spot_price: float = 1.0,
776
776
  title: str = 'Cumulative Distribution Function') -> go.Figure:
@@ -778,7 +778,7 @@ def plot_cdf(moneyness_grid: np.ndarray,
778
778
  Plot the cumulative distribution function (CDF) from RND values.
779
779
 
780
780
  Parameters:
781
- - moneyness_grid: Grid of log-moneyness values
781
+ - moneyness_array: Grid of log-moneyness values
782
782
  - rnd_values: RND values
783
783
  - spot_price: Spot price for converting to absolute prices
784
784
  - title: Plot title
@@ -787,10 +787,10 @@ def plot_cdf(moneyness_grid: np.ndarray,
787
787
  - Plotly figure
788
788
  """
789
789
  # Convert to prices and normalize RND
790
- prices = spot_price * np.exp(moneyness_grid)
790
+ prices = spot_price * np.exp(moneyness_array)
791
791
 
792
792
  # Normalize the RND
793
- dx = moneyness_grid[1] - moneyness_grid[0]
793
+ dx = moneyness_array[1] - moneyness_array[0]
794
794
  total_density = np.sum(rnd_values) * dx
795
795
  normalized_rnd = rnd_values / total_density if total_density > 0 else rnd_values
796
796
 
@@ -850,7 +850,7 @@ def plot_cdf(moneyness_grid: np.ndarray,
850
850
 
851
851
 
852
852
  @catch_exception
853
- def plot_pdf(moneyness_grid: np.ndarray,
853
+ def plot_pdf(moneyness_array: np.ndarray,
854
854
  rnd_values: np.ndarray,
855
855
  spot_price: float = 1.0,
856
856
  title: str = 'Probability Density Function') -> go.Figure:
@@ -858,7 +858,7 @@ def plot_pdf(moneyness_grid: np.ndarray,
858
858
  Plot the probability density function (PDF) from RND values.
859
859
 
860
860
  Parameters:
861
- - moneyness_grid: Grid of log-moneyness values
861
+ - moneyness_array: Grid of log-moneyness values
862
862
  - rnd_values: RND values
863
863
  - spot_price: Spot price for converting to absolute prices
864
864
  - title: Plot title
@@ -867,7 +867,7 @@ def plot_pdf(moneyness_grid: np.ndarray,
867
867
  - Plotly figure
868
868
  """
869
869
  # This is essentially the same as plot_rnd but with a different title
870
- return plot_rnd(moneyness_grid, rnd_values, spot_price, title)
870
+ return plot_rnd(moneyness_array, rnd_values, spot_price, title)
871
871
 
872
872
 
873
873
  @catch_exception
@@ -886,13 +886,13 @@ def plot_interpolated_surface(
886
886
  - Plotly figure
887
887
  """
888
888
  # Extract data from interpolation results
889
- moneyness_grid = interp_results['moneyness_grid']
889
+ moneyness_array = interp_results['moneyness_array']
890
890
  target_expiries_years = interp_results['target_expiries_years']
891
891
  iv_surface = interp_results['iv_surface']
892
892
 
893
893
  # Create a 3D surface plot
894
894
  fig = plot_3d_surface(
895
- moneyness=moneyness_grid,
895
+ moneyness=moneyness_array,
896
896
  expiries=target_expiries_years,
897
897
  iv_surface=iv_surface,
898
898
  title=title
@@ -295,6 +295,6 @@ def get_iv_surface(fit_results: Dict[str, Any],
295
295
  for maturity, yte in zip(maturity_values, yte_values):
296
296
  svi_params = param_matrix[maturity].values
297
297
  w_svi = [SVIModel.svi(x, *svi_params) for x in moneyness_array]
298
- iv_surface[yte] = np.sqrt(np.array(w_svi) / yte)
298
+ iv_surface[maturity] = np.sqrt(np.array(w_svi) / yte)
299
299
 
300
300
  return moneyness_array, iv_surface
@@ -43,11 +43,9 @@ def get_rnd_surface(fit_results: Dict[str, Any],
43
43
  maturity_values = fit_results['fit_performance']['Maturity']
44
44
  param_matrix = fit_results['raw_param_matrix']
45
45
 
46
- # Generate implied volatility for each expiry
46
+ # Generate rnd for each expiry
47
47
  for maturity, yte in zip(maturity_values, yte_values):
48
48
  svi_params_list = list(param_matrix[maturity].values)
49
-
50
- # Adjust parameter order to match function signatures
51
49
  a, b, sigma, rho, m = svi_params_list
52
50
 
53
51
  # Calculate total variance
@@ -55,8 +53,7 @@ def get_rnd_surface(fit_results: Dict[str, Any],
55
53
 
56
54
  # Calculate risk-neutral density using the base RND function
57
55
  rnd_values = np.array([rnd(x, var) for x, var in zip(moneyness_array, total_var)])
58
-
59
- rnd_surface[maturity_name] = rnd_values
56
+ rnd_surface[maturity] = rnd_values
60
57
 
61
58
  return moneyness_array, rnd_surface
62
59
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: voly
3
- Version: 0.0.38
3
+ Version: 0.0.40
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
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