voly 0.0.134__tar.gz → 0.0.136__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.134/src/voly.egg-info → voly-0.0.136}/PKG-INFO +1 -1
- {voly-0.0.134 → voly-0.0.136}/pyproject.toml +2 -2
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/hd.py +38 -6
- {voly-0.0.134 → voly-0.0.136/src/voly.egg-info}/PKG-INFO +1 -1
- {voly-0.0.134 → voly-0.0.136}/LICENSE +0 -0
- {voly-0.0.134 → voly-0.0.136}/README.md +0 -0
- {voly-0.0.134 → voly-0.0.136}/setup.cfg +0 -0
- {voly-0.0.134 → voly-0.0.136}/setup.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/__init__.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/client.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/__init__.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/charts.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/data.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/fit.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/interpolate.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/core/rnd.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/exceptions.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/formulas.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/models.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/utils/__init__.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly/utils/logger.py +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly.egg-info/SOURCES.txt +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly.egg-info/dependency_links.txt +0 -0
- {voly-0.0.134 → voly-0.0.136}/src/voly.egg-info/requires.txt +0 -0
- {voly-0.0.134 → voly-0.0.136}/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.136"
|
|
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.136"
|
|
64
64
|
warn_return_any = true
|
|
65
65
|
warn_unused_configs = true
|
|
66
66
|
disallow_untyped_defs = true
|
|
@@ -449,7 +449,15 @@ def get_garch_hd_surface(model_results: pd.DataFrame,
|
|
|
449
449
|
if missing_columns:
|
|
450
450
|
raise VolyError(f"Required columns missing in model_results: {missing_columns}")
|
|
451
451
|
|
|
452
|
-
#
|
|
452
|
+
# Determine granularity from df_hist
|
|
453
|
+
if len(df_hist) > 1:
|
|
454
|
+
# Calculate minutes between consecutive timestamps
|
|
455
|
+
minutes_diff = (df_hist.index[1] - df_hist.index[0]).total_seconds() / 60
|
|
456
|
+
minutes_per_period = int(minutes_diff)
|
|
457
|
+
else:
|
|
458
|
+
raise VolyError("Cannot determine granularity from df_hist.")
|
|
459
|
+
|
|
460
|
+
# Calculate log returns based on the determined granularity
|
|
453
461
|
log_returns = np.log(df_hist['close'] / df_hist['close'].shift(1)) * 100
|
|
454
462
|
log_returns = log_returns.dropna().values
|
|
455
463
|
|
|
@@ -465,15 +473,20 @@ def get_garch_hd_surface(model_results: pd.DataFrame,
|
|
|
465
473
|
r = model_results.loc[i, 'r'] # Risk-free rate
|
|
466
474
|
t = model_results.loc[i, 't'] # Time to maturity in years
|
|
467
475
|
|
|
468
|
-
|
|
476
|
+
# Fix for very short-term maturities - use floating-point days
|
|
477
|
+
tau_days_float = t * 365.25 # Exact number of days (as float)
|
|
478
|
+
tau_day = max(1, int(tau_days_float)) # Ensure minimum of 1 day for simulation
|
|
469
479
|
|
|
470
|
-
logger.info(f"Processing GARCH HD for maturity {i} (t={t:.4f} years, {
|
|
480
|
+
logger.info(f"Processing GARCH HD for maturity {i} (t={t:.4f} years, {tau_days_float:.2f} days)")
|
|
481
|
+
|
|
482
|
+
# Calculate the number of periods that match the time to expiry
|
|
483
|
+
n_periods = max(1, int(t * 365.25 * 24 * 60 / minutes_per_period))
|
|
471
484
|
|
|
472
485
|
# Initialize GARCH model
|
|
473
486
|
garch_model = GARCHModel(
|
|
474
487
|
data=log_returns,
|
|
475
488
|
data_name=str(i),
|
|
476
|
-
n_fits=min(n_fits, len(log_returns) // 3),
|
|
489
|
+
n_fits=min(n_fits, len(log_returns) // 3),
|
|
477
490
|
window_length=min(window_length, len(log_returns) // 3),
|
|
478
491
|
z_h=0.1
|
|
479
492
|
)
|
|
@@ -485,8 +498,27 @@ def get_garch_hd_surface(model_results: pd.DataFrame,
|
|
|
485
498
|
variate_parameters=variate_parameters
|
|
486
499
|
)
|
|
487
500
|
|
|
488
|
-
#
|
|
489
|
-
|
|
501
|
+
# Scale the simulated returns to match target time horizon
|
|
502
|
+
# Use floating-point days to avoid division by zero
|
|
503
|
+
scaling_factor = np.sqrt(n_periods / tau_days_float)
|
|
504
|
+
scaled_log_returns = simulated_log_returns * scaling_factor
|
|
505
|
+
|
|
506
|
+
# Risk-neutral adjustment (Girsanov transformation)
|
|
507
|
+
# Calculate empirical mean and volatility of the scaled returns
|
|
508
|
+
mu_scaled = scaled_log_returns.mean()
|
|
509
|
+
sigma_scaled = scaled_log_returns.std()
|
|
510
|
+
|
|
511
|
+
# Expected risk-neutral drift
|
|
512
|
+
expected_risk_neutral_mean = (r - 0.5 * (sigma_scaled / 100) ** 2) * 100 * np.sqrt(t)
|
|
513
|
+
|
|
514
|
+
# Calculate adjustment to shift physical to risk-neutral measure
|
|
515
|
+
adjustment = mu_scaled - expected_risk_neutral_mean
|
|
516
|
+
|
|
517
|
+
# Adjust the returns to the risk-neutral measure
|
|
518
|
+
risk_neutral_log_returns = scaled_log_returns - adjustment
|
|
519
|
+
|
|
520
|
+
# Convert to terminal prices using the risk-neutral returns
|
|
521
|
+
simulated_prices = s * np.exp(risk_neutral_log_returns / 100)
|
|
490
522
|
|
|
491
523
|
# Convert to moneyness domain
|
|
492
524
|
simulated_moneyness = s / simulated_prices
|
|
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
|