voly 0.0.220__py3-none-any.whl → 0.0.221__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/hd.py +3 -24
- voly/core/interpolate.py +2 -3
- {voly-0.0.220.dist-info → voly-0.0.221.dist-info}/METADATA +1 -1
- {voly-0.0.220.dist-info → voly-0.0.221.dist-info}/RECORD +7 -7
- {voly-0.0.220.dist-info → voly-0.0.221.dist-info}/WHEEL +1 -1
- {voly-0.0.220.dist-info → voly-0.0.221.dist-info}/licenses/LICENSE +0 -0
- {voly-0.0.220.dist-info → voly-0.0.221.dist-info}/top_level.txt +0 -0
voly/core/hd.py
CHANGED
@@ -164,13 +164,8 @@ def calculate_normal_hd(df_hist: pd.DataFrame,
|
|
164
164
|
mu_scaled = np.mean(scaled_returns)
|
165
165
|
sigma_scaled = np.std(scaled_returns)
|
166
166
|
|
167
|
-
# Apply Girsanov adjustment to shift to risk-neutral measure
|
168
|
-
expected_risk_neutral_mean = (r - 0.5 * sigma_scaled ** 2) * np.sqrt(t)
|
169
|
-
adjustment = mu_scaled - expected_risk_neutral_mean
|
170
|
-
mu_rn = mu_scaled - adjustment
|
171
|
-
|
172
167
|
# Calculate PDF using normal distribution in log-moneyness domain
|
173
|
-
pdf_lm = stats.norm.pdf(LM, loc=
|
168
|
+
pdf_lm = stats.norm.pdf(LM, loc=mu_scaled, scale=sigma_scaled)
|
174
169
|
|
175
170
|
# Normalize the PDF
|
176
171
|
pdf_lm = normalize_density(pdf_lm, dx)
|
@@ -230,11 +225,6 @@ def calculate_student_t_hd(df_hist: pd.DataFrame,
|
|
230
225
|
else:
|
231
226
|
df = 5 # Default value if kurtosis calculation fails
|
232
227
|
|
233
|
-
# Apply Girsanov adjustment to shift to risk-neutral measure
|
234
|
-
expected_risk_neutral_mean = (r - 0.5 * sigma_scaled ** 2) * np.sqrt(t)
|
235
|
-
adjustment = mu_scaled - expected_risk_neutral_mean
|
236
|
-
mu_rn = mu_scaled - adjustment
|
237
|
-
|
238
228
|
# Scale parameter for t-distribution
|
239
229
|
# In scipy's t-distribution, the scale parameter is different from normal std
|
240
230
|
# For t-distribution: variance = (df/(df-2)) * scale^2
|
@@ -242,7 +232,7 @@ def calculate_student_t_hd(df_hist: pd.DataFrame,
|
|
242
232
|
scale = sigma_scaled * np.sqrt((df - 2) / df) if df > 2 else sigma_scaled
|
243
233
|
|
244
234
|
# Calculate PDF using t-distribution in log-moneyness domain
|
245
|
-
pdf_lm = student_t.pdf(LM, df=df, loc=
|
235
|
+
pdf_lm = student_t.pdf(LM, df=df, loc=mu_scaled, scale=scale)
|
246
236
|
|
247
237
|
# Normalize the PDF
|
248
238
|
pdf_lm = normalize_density(pdf_lm, dx)
|
@@ -287,19 +277,8 @@ def calculate_kde_hd(df_hist: pd.DataFrame,
|
|
287
277
|
# Get scaled returns
|
288
278
|
scaled_returns, dte_returns = calculate_historical_returns(df_hist, n_periods)
|
289
279
|
|
290
|
-
# Calculate parameters (for Girsanov adjustment)
|
291
|
-
mu_scaled = np.mean(scaled_returns)
|
292
|
-
sigma_scaled = np.std(scaled_returns)
|
293
|
-
|
294
|
-
# Apply Girsanov adjustment to shift to risk-neutral measure
|
295
|
-
expected_risk_neutral_mean = (r - 0.5 * sigma_scaled ** 2) * np.sqrt(t)
|
296
|
-
adjustment = mu_scaled - expected_risk_neutral_mean
|
297
|
-
|
298
|
-
# Shift the returns to be risk-neutral
|
299
|
-
rn_returns = scaled_returns - adjustment + expected_risk_neutral_mean
|
300
|
-
|
301
280
|
# Fit KDE model using scipy's gaussian_kde with Scott's rule for bandwidth
|
302
|
-
kde = stats.gaussian_kde(
|
281
|
+
kde = stats.gaussian_kde(scaled_returns, bw_method='scott')
|
303
282
|
|
304
283
|
# Evaluate KDE at points in log-moneyness domain
|
305
284
|
pdf_lm = kde(LM)
|
voly/core/interpolate.py
CHANGED
@@ -29,7 +29,6 @@ def interpolate_model(fit_results: pd.DataFrame,
|
|
29
29
|
Returns:
|
30
30
|
- DataFrame with interpolated model parameters for the specified days
|
31
31
|
"""
|
32
|
-
logger.info(f"Interpolating model parameters using {method} method")
|
33
32
|
|
34
33
|
# Check if fit_results is valid
|
35
34
|
if fit_results is None or fit_results.empty:
|
@@ -68,7 +67,7 @@ def interpolate_model(fit_results: pd.DataFrame,
|
|
68
67
|
"Extrapolation may give unreliable results.")
|
69
68
|
|
70
69
|
# Columns to interpolate
|
71
|
-
param_columns = ['
|
70
|
+
param_columns = ['a', 'b', 'm', 'rho', 'sigma', 'nu', 'psi', 'p', 'c', 'nu_tilde']
|
72
71
|
|
73
72
|
# Create empty DataFrame for interpolated results
|
74
73
|
interpolated_df = pd.DataFrame(index=[f"{day}d" for day in target_days])
|
@@ -119,7 +118,7 @@ def interpolate_model(fit_results: pd.DataFrame,
|
|
119
118
|
interpolated_df[param] = f(target_years)
|
120
119
|
|
121
120
|
# Ensure consistent ordering of columns with expected structure
|
122
|
-
expected_columns = ['s', '
|
121
|
+
expected_columns = ['s', 't', 'r', 'maturity_date', 'a', 'b', 'm', 'rho', 'sigma',
|
123
122
|
'nu', 'psi', 'p', 'c', 'nu_tilde']
|
124
123
|
|
125
124
|
# Create final column order based on available columns
|
@@ -7,14 +7,14 @@ 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=SNF87C7-r-1IbKwf7rAhXkJ6X305yo7fCDJDdkwz3NM,14103
|
9
9
|
voly/core/fit.py,sha256=bVyx7qMgFFpTUjgoCUs58ppmeNN2CORnqPKbGUpV9xw,14081
|
10
|
-
voly/core/hd.py,sha256=
|
11
|
-
voly/core/interpolate.py,sha256
|
10
|
+
voly/core/hd.py,sha256=1Gbxvn2EVfOE89fJsjylsREzV_pE3Ab_a3rE0qEf71E,13865
|
11
|
+
voly/core/interpolate.py,sha256=-cNChFpuLnCSMOmfW2ldXxePgQXi-pxcjJvF2yImD1w,5222
|
12
12
|
voly/core/rnd.py,sha256=wiZ5OIjPDf1Th5_sQ9CZG5JgAo3EL8f63T_Rj1_VP-0,13214
|
13
13
|
voly/utils/__init__.py,sha256=E05mWatyC-PDOsCxQV1p5Xi1IgpOomxrNURyCx_gB-w,200
|
14
14
|
voly/utils/density.py,sha256=ONpRli-IaJDgOZ2sb27HHFc9_tkkGSATKl94JODd86A,5879
|
15
15
|
voly/utils/logger.py,sha256=4-_2bVJmq17Q0d7Rd2mPg1AeR8gxv6EPvcmBDMFWcSM,1744
|
16
|
-
voly-0.0.
|
17
|
-
voly-0.0.
|
18
|
-
voly-0.0.
|
19
|
-
voly-0.0.
|
20
|
-
voly-0.0.
|
16
|
+
voly-0.0.221.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
|
17
|
+
voly-0.0.221.dist-info/METADATA,sha256=tTEL0rXh-JthRV4fid-xpHwbKWPkqyt6F-J4U8itpC8,4115
|
18
|
+
voly-0.0.221.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
19
|
+
voly-0.0.221.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
|
20
|
+
voly-0.0.221.dist-info/RECORD,,
|
File without changes
|
File without changes
|