voly 0.0.66__py3-none-any.whl → 0.0.68__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/client.py +2 -5
- voly/core/fit.py +69 -20
- {voly-0.0.66.dist-info → voly-0.0.68.dist-info}/METADATA +1 -1
- {voly-0.0.66.dist-info → voly-0.0.68.dist-info}/RECORD +7 -7
- {voly-0.0.66.dist-info → voly-0.0.68.dist-info}/LICENSE +0 -0
- {voly-0.0.66.dist-info → voly-0.0.68.dist-info}/WHEEL +0 -0
- {voly-0.0.66.dist-info → voly-0.0.68.dist-info}/top_level.txt +0 -0
voly/client.py
CHANGED
|
@@ -338,17 +338,14 @@ class VolyClient:
|
|
|
338
338
|
logger.info(f"Fitting {model_name.upper()} model to market data")
|
|
339
339
|
|
|
340
340
|
# Fit the model
|
|
341
|
-
fit_results
|
|
341
|
+
fit_results = fit_model(
|
|
342
342
|
option_chain=option_chain,
|
|
343
343
|
model_name=model_name,
|
|
344
344
|
initial_params=initial_params,
|
|
345
345
|
param_bounds=param_bounds
|
|
346
346
|
)
|
|
347
347
|
|
|
348
|
-
return
|
|
349
|
-
'fit_results': fit_results,
|
|
350
|
-
'fit_performance': fit_performance
|
|
351
|
-
}
|
|
348
|
+
return fit_results
|
|
352
349
|
|
|
353
350
|
@staticmethod
|
|
354
351
|
def get_iv_surface(fit_results: Dict[str, Any],
|
voly/core/fit.py
CHANGED
|
@@ -53,22 +53,42 @@ def fit_model(option_chain: pd.DataFrame,
|
|
|
53
53
|
initial_params = initial_params or SVIModel.DEFAULT_INITIAL_PARAMS
|
|
54
54
|
param_bounds = param_bounds or SVIModel.DEFAULT_PARAM_BOUNDS
|
|
55
55
|
|
|
56
|
-
# Define column names
|
|
57
|
-
|
|
58
|
-
's'
|
|
59
|
-
'
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
|
|
56
|
+
# Define column names and their data types
|
|
57
|
+
column_dtypes = {
|
|
58
|
+
's': float,
|
|
59
|
+
'u': float,
|
|
60
|
+
'maturity_date': 'datetime64[ns]',
|
|
61
|
+
'dtm': float,
|
|
62
|
+
'ytm': float,
|
|
63
|
+
'a': float,
|
|
64
|
+
'b': float,
|
|
65
|
+
'rho': float,
|
|
66
|
+
'm': float,
|
|
67
|
+
'sigma': float,
|
|
68
|
+
'nu': float,
|
|
69
|
+
'psi': float,
|
|
70
|
+
'p': float,
|
|
71
|
+
'c': float,
|
|
72
|
+
'nu_tilde': float,
|
|
73
|
+
'oi': float,
|
|
74
|
+
'volume': float,
|
|
75
|
+
'r': float,
|
|
76
|
+
'fit_success': bool,
|
|
77
|
+
'cost': float,
|
|
78
|
+
'optimality': float,
|
|
79
|
+
'rmse': float,
|
|
80
|
+
'mae': float,
|
|
81
|
+
'r2': float,
|
|
82
|
+
'max_error': float,
|
|
83
|
+
'n_points': int
|
|
84
|
+
}
|
|
65
85
|
|
|
66
86
|
# Get unique maturities and sort them
|
|
67
87
|
unique_ytms = sorted(option_chain['ytm'].unique())
|
|
68
88
|
maturity_names = [option_chain[option_chain['ytm'] == ytm]['maturity_name'].iloc[0] for ytm in unique_ytms]
|
|
69
89
|
|
|
70
|
-
#
|
|
71
|
-
|
|
90
|
+
# Store results in a dictionary first
|
|
91
|
+
results_data = {col: [] for col in column_dtypes.keys()}
|
|
72
92
|
|
|
73
93
|
# ANSI color codes for terminal output
|
|
74
94
|
GREEN, RED, RESET = '\033[32m', '\033[31m', '\033[0m'
|
|
@@ -119,21 +139,50 @@ def fit_model(option_chain: pd.DataFrame,
|
|
|
119
139
|
# Calculate Jump-Wing parameters
|
|
120
140
|
nu, psi, p, c, nu_tilde = SVIModel.raw_to_jw_params(a, b, sigma, rho, m, ytm)
|
|
121
141
|
|
|
122
|
-
# Store
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
]
|
|
142
|
+
# Store values in the results dictionary with proper types
|
|
143
|
+
results_data['s'].append(float(s))
|
|
144
|
+
results_data['u'].append(float(u))
|
|
145
|
+
results_data['maturity_date'].append(maturity_data['maturity_date'].iloc[0])
|
|
146
|
+
results_data['dtm'].append(float(dtm))
|
|
147
|
+
results_data['ytm'].append(float(ytm))
|
|
148
|
+
results_data['a'].append(float(a))
|
|
149
|
+
results_data['b'].append(float(b))
|
|
150
|
+
results_data['rho'].append(float(rho))
|
|
151
|
+
results_data['m'].append(float(m))
|
|
152
|
+
results_data['sigma'].append(float(sigma))
|
|
153
|
+
results_data['nu'].append(float(nu))
|
|
154
|
+
results_data['psi'].append(float(psi))
|
|
155
|
+
results_data['p'].append(float(p))
|
|
156
|
+
results_data['c'].append(float(c))
|
|
157
|
+
results_data['nu_tilde'].append(float(nu_tilde))
|
|
158
|
+
results_data['oi'].append(float(oi))
|
|
159
|
+
results_data['volume'].append(float(volume))
|
|
160
|
+
results_data['r'].append(float(r))
|
|
161
|
+
results_data['fit_success'].append(bool(result.success))
|
|
162
|
+
results_data['cost'].append(float(result.cost))
|
|
163
|
+
results_data['optimality'].append(float(result.optimality))
|
|
164
|
+
results_data['rmse'].append(float(rmse))
|
|
165
|
+
results_data['mae'].append(float(mae))
|
|
166
|
+
results_data['r2'].append(float(r2))
|
|
167
|
+
results_data['max_error'].append(float(max_error))
|
|
168
|
+
results_data['n_points'].append(int(len(maturity_data)))
|
|
131
169
|
|
|
132
170
|
# Log result
|
|
133
171
|
status = f'{GREEN}SUCCESS{RESET}' if result.success else f'{RED}FAILED{RESET}'
|
|
134
172
|
logger.info(f'Optimization for {maturity_name}: {status}')
|
|
135
173
|
logger.info('-------------------------------------')
|
|
136
174
|
|
|
175
|
+
# Create DataFrame with proper types
|
|
176
|
+
results_df = pd.DataFrame(results_data, index=maturity_names)
|
|
177
|
+
|
|
178
|
+
# Convert columns to appropriate types
|
|
179
|
+
for col, dtype in column_dtypes.items():
|
|
180
|
+
if col in results_df.columns:
|
|
181
|
+
try:
|
|
182
|
+
results_df[col] = results_df[col].astype(dtype)
|
|
183
|
+
except (ValueError, TypeError) as e:
|
|
184
|
+
logger.warning(f"Could not convert column {col} to {dtype}: {e}")
|
|
185
|
+
|
|
137
186
|
return results_df
|
|
138
187
|
|
|
139
188
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
voly/__init__.py,sha256=8xyDk7rFCn_MOD5hxuv5cxxKZvBVRiSIM7TgaMPpwpw,211
|
|
2
|
-
voly/client.py,sha256=
|
|
2
|
+
voly/client.py,sha256=fXcS856ZYyJrhHjxUhGnth4N4BQbR-ExMYd25CTpR64,20539
|
|
3
3
|
voly/exceptions.py,sha256=PBsbn1vNMvKcCJwwJ4lBO6glD85jo1h2qiEmD7ArAjs,92
|
|
4
4
|
voly/formulas.py,sha256=wSbGAH6GuQThT9QyQY4Ud2eUf9fo1YFHglUmP6fNris,11871
|
|
5
5
|
voly/models.py,sha256=LXXIlpXZQEfXTuCngxC8Hd3bWtw6wdXDCSGxTLmHM-c,3659
|
|
6
6
|
voly/core/__init__.py,sha256=bu6fS2I1Pj9fPPnl-zY3L7NqrZSY5Zy6NY2uMUvdhKs,183
|
|
7
7
|
voly/core/charts.py,sha256=rsAkVddQVwAwCle9NQ-_zDO-29U7gPF_Zx8n4OjK-X8,28467
|
|
8
8
|
voly/core/data.py,sha256=e8qBArubNqPkrfuIYB_q2WhRf7TKzA4Z3FhMC-xyLEE,8862
|
|
9
|
-
voly/core/fit.py,sha256=
|
|
9
|
+
voly/core/fit.py,sha256=JOr2XjM-I9HtfbyEN0tdGuNCZimQ2ttm4lNUpF-tKb4,9226
|
|
10
10
|
voly/core/interpolate.py,sha256=ztVIePJZOh-CIbn69wkh1JW2rKywNe2FEewRN0zcSAo,8185
|
|
11
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.68.dist-info/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
|
|
15
|
+
voly-0.0.68.dist-info/METADATA,sha256=GcwW-KAqS4hbQ3ARYxkdDYKqC4U7aef7kQYZbeVeY4U,4092
|
|
16
|
+
voly-0.0.68.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
17
|
+
voly-0.0.68.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
|
|
18
|
+
voly-0.0.68.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|