voly 0.0.38__py3-none-any.whl → 0.0.40__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/charts.py +26 -26
- voly/core/fit.py +1 -1
- voly/core/rnd.py +2 -5
- {voly-0.0.38.dist-info → voly-0.0.40.dist-info}/METADATA +1 -1
- {voly-0.0.38.dist-info → voly-0.0.40.dist-info}/RECORD +8 -8
- {voly-0.0.38.dist-info → voly-0.0.40.dist-info}/LICENSE +0 -0
- {voly-0.0.38.dist-info → voly-0.0.40.dist-info}/WHEEL +0 -0
- {voly-0.0.38.dist-info → voly-0.0.40.dist-info}/top_level.txt +0 -0
voly/core/charts.py
CHANGED
|
@@ -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(
|
|
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
|
-
-
|
|
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
|
-
|
|
364
|
+
maturities = list(iv_surface.keys())
|
|
365
365
|
|
|
366
366
|
# Convert implied volatility surface to array
|
|
367
|
-
z_array = np.array([iv_surface[
|
|
367
|
+
z_array = np.array([iv_surface[m] for m in maturities])
|
|
368
368
|
|
|
369
369
|
# Create mesh grid
|
|
370
|
-
X, Y = np.meshgrid(
|
|
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(
|
|
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
|
-
-
|
|
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(
|
|
416
|
+
prices = spot_price * np.exp(moneyness_array)
|
|
417
417
|
|
|
418
418
|
# Normalize the RND to integrate to 1
|
|
419
|
-
dx =
|
|
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(
|
|
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
|
-
-
|
|
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(
|
|
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 =
|
|
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(
|
|
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
|
-
-
|
|
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(
|
|
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 =
|
|
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(
|
|
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
|
-
-
|
|
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(
|
|
790
|
+
prices = spot_price * np.exp(moneyness_array)
|
|
791
791
|
|
|
792
792
|
# Normalize the RND
|
|
793
|
-
dx =
|
|
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(
|
|
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
|
-
-
|
|
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(
|
|
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
|
-
|
|
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=
|
|
895
|
+
moneyness=moneyness_array,
|
|
896
896
|
expiries=target_expiries_years,
|
|
897
897
|
iv_surface=iv_surface,
|
|
898
898
|
title=title
|
voly/core/fit.py
CHANGED
|
@@ -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[
|
|
298
|
+
iv_surface[maturity] = np.sqrt(np.array(w_svi) / yte)
|
|
299
299
|
|
|
300
300
|
return moneyness_array, iv_surface
|
voly/core/rnd.py
CHANGED
|
@@ -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
|
|
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
|
|
|
@@ -4,15 +4,15 @@ voly/exceptions.py,sha256=PBsbn1vNMvKcCJwwJ4lBO6glD85jo1h2qiEmD7ArAjs,92
|
|
|
4
4
|
voly/formulas.py,sha256=7NQZtYWFT_VOyAVNQHLB5-8caGAdtzU8y8eFcYJsZn8,7256
|
|
5
5
|
voly/models.py,sha256=YJ12aamLz_-aOni4Qm0_XV9u4bjKK3vfJz0J2gc1h0o,3565
|
|
6
6
|
voly/core/__init__.py,sha256=bu6fS2I1Pj9fPPnl-zY3L7NqrZSY5Zy6NY2uMUvdhKs,183
|
|
7
|
-
voly/core/charts.py,sha256=
|
|
7
|
+
voly/core/charts.py,sha256=tt8WZfAKmfb5YQiVXYAXt9ROT_FRMB4w_Lbe5ihjh5E,26725
|
|
8
8
|
voly/core/data.py,sha256=Dfk-ByHpdteUiLXr0p-wRLr3VAmdyjdDBKwjwdTgCjA,9939
|
|
9
|
-
voly/core/fit.py,sha256=
|
|
9
|
+
voly/core/fit.py,sha256=O4PMihVWI1NIEFU4_RkKvT73p0Jk0tB-ot5moMXAW78,9950
|
|
10
10
|
voly/core/interpolate.py,sha256=ztVIePJZOh-CIbn69wkh1JW2rKywNe2FEewRN0zcSAo,8185
|
|
11
|
-
voly/core/rnd.py,sha256=
|
|
11
|
+
voly/core/rnd.py,sha256=8FTU-Qp9epW9yE4XSOdiFGIRXrGyXqF6mVgZn1NMvxk,11813
|
|
12
12
|
voly/utils/__init__.py,sha256=E05mWatyC-PDOsCxQV1p5Xi1IgpOomxrNURyCx_gB-w,200
|
|
13
13
|
voly/utils/logger.py,sha256=4-_2bVJmq17Q0d7Rd2mPg1AeR8gxv6EPvcmBDMFWcSM,1744
|
|
14
|
-
voly-0.0.
|
|
15
|
-
voly-0.0.
|
|
16
|
-
voly-0.0.
|
|
17
|
-
voly-0.0.
|
|
18
|
-
voly-0.0.
|
|
14
|
+
voly-0.0.40.dist-info/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
|
|
15
|
+
voly-0.0.40.dist-info/METADATA,sha256=82ZAciFjV9qvdgsfzv3L-wjRbwfjUUhUjwzzHUb0j0E,4092
|
|
16
|
+
voly-0.0.40.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
17
|
+
voly-0.0.40.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
|
|
18
|
+
voly-0.0.40.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|