voly 0.0.66__tar.gz → 0.0.68__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.66
3
+ Version: 0.0.68
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.66"
7
+ version = "0.0.68"
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.66"
63
+ python_version = "0.0.68"
64
64
  warn_return_any = true
65
65
  warn_unused_configs = true
66
66
  disallow_untyped_defs = true
@@ -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, fit_performance = fit_model(
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],
@@ -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 for the result DataFrame
57
- result_columns = [
58
- 's', 'u', 'maturity_date', 'dtm', 'ytm',
59
- 'a', 'b', 'rho', 'm', 'sigma',
60
- 'nu', 'psi', 'p', 'c', 'nu_tilde',
61
- 'oi', 'volume', 'r',
62
- 'fit_success', 'cost', 'optimality',
63
- 'rmse', 'mae', 'r2', 'max_error', 'n_points'
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
- # Create empty DataFrame with maturity_names as index
71
- results_df = pd.DataFrame(index=maturity_names, columns=result_columns)
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 all results in the DataFrame
123
- results_df.loc[maturity_name] = [
124
- s, u, maturity_data['maturity_date'].iloc[0], dtm, ytm,
125
- a, b, rho, m, sigma,
126
- nu, psi, p, c, nu_tilde,
127
- oi, volume, r,
128
- result.success, result.cost, result.optimality,
129
- rmse, mae, r2, max_error, len(maturity_data)
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,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: voly
3
- Version: 0.0.66
3
+ Version: 0.0.68
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
File without changes