voly 0.0.139__py3-none-any.whl → 0.0.141__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 CHANGED
@@ -20,7 +20,7 @@ from voly.formulas import (
20
20
  from voly.core.data import fetch_option_chain, process_option_chain
21
21
  from voly.core.fit import fit_model, get_iv_surface
22
22
  from voly.core.rnd import get_rnd_surface
23
- from voly.core.hd import get_historical_data, get_hd_surface, get_garch_hd_surface
23
+ from voly.core.hd import get_historical_data, get_hd_surface
24
24
  from voly.core.interpolate import interpolate_model
25
25
  from voly.core.charts import (
26
26
  plot_all_smiles, plot_raw_parameters, plot_jw_parameters, plot_fit_performance, plot_3d_surface,
voly/core/rnd.py CHANGED
@@ -163,7 +163,7 @@ def rookley(domain_params, s, r, o, t, return_domain):
163
163
  moments = get_all_moments(x, pdf)
164
164
  return pdf, cdf, x, moments
165
165
 
166
-
166
+ '''
167
167
  @catch_exception
168
168
  def get_all_moments(x, pdf, model_params=None):
169
169
  mean = np.trapz(x * pdf, x) # E[X]
@@ -219,6 +219,96 @@ def get_all_moments(x, pdf, model_params=None):
219
219
  moments.update(model_params)
220
220
 
221
221
  return moments
222
+ '''
223
+
224
+ @catch_exception
225
+ def get_all_moments(x, pdf, model_params=None):
226
+ # Precompute dx for integration
227
+ dx = np.diff(x, prepend=x[0])
228
+
229
+ # Raw Moments (μ_k = E[X^k])
230
+ raw_moments = {
231
+ 'raw_0': np.trapz(pdf, x), # Zeroth (~1)
232
+ 'raw_1': np.trapz(x * pdf, x), # First (mean)
233
+ 'raw_2': np.trapz(x**2 * pdf, x), # Second
234
+ 'raw_3': np.trapz(x**3 * pdf, x), # Third
235
+ 'raw_4': np.trapz(x**4 * pdf, x), # Fourth
236
+ 'raw_5': np.trapz(x**5 * pdf, x), # Fifth
237
+ 'raw_6': np.trapz(x**6 * pdf, x), # Sixth
238
+ }
239
+
240
+ mean = raw_moments['raw_1']
241
+ variance = np.trapz((x - mean)**2 * pdf, x) # m_2
242
+ std_dev = np.sqrt(variance)
243
+
244
+ # Central Moments (m_k = E[(X - μ)^k])
245
+ central_moments = {
246
+ 'cent_0': raw_moments['raw_0'], # Zeroth (~1)
247
+ 'cent_1': np.trapz((x - mean) * pdf, x), # First (~0)
248
+ 'cent_2': variance, # Second (variance)
249
+ 'cent_3': np.trapz((x - mean)**3 * pdf, x), # Third
250
+ 'cent_4': np.trapz((x - mean)**4 * pdf, x), # Fourth
251
+ 'cent_5': np.trapz((x - mean)**5 * pdf, x), # Fifth
252
+ 'cent_6': np.trapz((x - mean)**6 * pdf, x), # Sixth
253
+ }
254
+
255
+ # Standardized Moments (m̄_k = E[((X - μ)/σ)^k])
256
+ z = (x - mean) / std_dev
257
+ standardized_moments = {
258
+ 'std_0': np.trapz(pdf, x), # Zeroth (~1)
259
+ 'std_1': np.trapz(z * pdf, x), # First (~0)
260
+ 'std_2': np.trapz(z**2 * pdf, x), # Second (~1)
261
+ 'std_3': np.trapz(z**3 * pdf, x), # Skewness
262
+ 'std_4': np.trapz(z**4 * pdf, x), # Kurtosis
263
+ 'std_5': np.trapz(z**5 * pdf, x), # Fifth
264
+ 'std_6': np.trapz(z**6 * pdf, x), # Sixth
265
+ }
266
+
267
+ # Extra statistics
268
+ cdf = np.cumsum(pdf * dx)
269
+ median = x[np.searchsorted(cdf, 0.5)] # Median
270
+ mode = x[np.argmax(pdf)] # Mode
271
+ excess_kurtosis = standardized_moments['std_4'] - 3
272
+ q25 = x[np.searchsorted(cdf, 0.25)] # 25th percentile
273
+ q75 = x[np.searchsorted(cdf, 0.75)] # 75th percentile
274
+ iqr = q75 - q25
275
+ entropy = -np.trapz(pdf * np.log(pdf + 1e-10), x)
276
+
277
+ # Z-score areas
278
+ o1p = np.sum(pdf[(z > 0) & (z < 1)] * dx[(z > 0) & (z < 1)])
279
+ o2p = np.sum(pdf[(z >= 1) & (z < 2)] * dx[(z >= 1) & (z < 2)])
280
+ o3p = np.sum(pdf[(z >= 2) & (z < 3)] * dx[(z >= 2) & (z < 3)])
281
+ o4p = np.sum(pdf[z >= 3] * dx[z >= 3])
282
+ o1n = np.sum(pdf[(z < 0) & (z > -1)] * dx[(z < 0) & (z > -1)])
283
+ o2n = np.sum(pdf[(z <= -1) & (z > -2)] * dx[(z <= -1) & (z > -2)])
284
+ o3n = np.sum(pdf[(z <= -2) & (z > -3)] * dx[(z <= -2) & (z > -3)])
285
+ o4n = np.sum(pdf[z <= -3] * dx[z <= -3])
286
+
287
+ # Combine results
288
+ moments = {
289
+ 'raw_moments': raw_moments,
290
+ 'central_moments': central_moments,
291
+ 'standardized_moments': standardized_moments,
292
+ 'mean': mean,
293
+ 'variance': variance,
294
+ 'std_dev': std_dev,
295
+ 'median': median,
296
+ 'mode': mode,
297
+ 'excess_kurtosis': excess_kurtosis,
298
+ 'q25': q25,
299
+ 'q75': q75,
300
+ 'iqr': iqr,
301
+ 'entropy': entropy,
302
+ 'z_score_areas': {
303
+ 'o1p': o1p, 'o2p': o2p, 'o3p': o3p, 'o4p': o4p,
304
+ 'o1n': o1n, 'o2n': o2n, 'o3n': o3n, 'o4n': o4n
305
+ }
306
+ }
307
+
308
+ if model_params is not None:
309
+ moments.update(model_params)
310
+
311
+ return moments
222
312
 
223
313
 
224
314
  @catch_exception
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: voly
3
- Version: 0.0.139
3
+ Version: 0.0.141
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
@@ -1,5 +1,5 @@
1
1
  voly/__init__.py,sha256=8xyDk7rFCn_MOD5hxuv5cxxKZvBVRiSIM7TgaMPpwpw,211
2
- voly/client.py,sha256=ZYwuHGKBZA5EPb9gTPpJjMvpfohO4P8BrlCXyICt1K4,14271
2
+ voly/client.py,sha256=Lj3YY6P1VBQD5C_psPh2pSxCMVvFjRBybrMrs4e9qXI,14249
3
3
  voly/exceptions.py,sha256=PBsbn1vNMvKcCJwwJ4lBO6glD85jo1h2qiEmD7ArAjs,92
4
4
  voly/formulas.py,sha256=G_soRiPwQlHy6milOAj6TdmBWr-fNZpMvm0joXAMZ90,10767
5
5
  voly/models.py,sha256=o-pHujGfr5Gn8ItckMzLI4Q8yaX9FQaV8UjCxv2zgTY,3364
@@ -9,11 +9,11 @@ voly/core/data.py,sha256=pDeuYhP0GX4RbtlqByvsE3rfHcIkix0BU5MLW8sKIeI,8935
9
9
  voly/core/fit.py,sha256=Tb9eeG7e_2dQTcqt6aqEwFrZdy6jR9rSNqe6tzOdVhQ,9245
10
10
  voly/core/hd.py,sha256=K2X0isAchumuRPcc5RSEkMOR5sOeb_I3twwqAZYYL1A,16809
11
11
  voly/core/interpolate.py,sha256=JkK172-FXyhesW3hY4pEeuJWG3Bugq7QZXbeKoRpLuo,5305
12
- voly/core/rnd.py,sha256=GG4cZpWChy8ptIwanuullkx3Bai50rFjqa9E-D9q2_Q,10246
12
+ voly/core/rnd.py,sha256=kF_TUxlfFHI9WF3JAh6mS-mggia0zogPdY01yvuYoxM,13589
13
13
  voly/utils/__init__.py,sha256=E05mWatyC-PDOsCxQV1p5Xi1IgpOomxrNURyCx_gB-w,200
14
14
  voly/utils/logger.py,sha256=4-_2bVJmq17Q0d7Rd2mPg1AeR8gxv6EPvcmBDMFWcSM,1744
15
- voly-0.0.139.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
16
- voly-0.0.139.dist-info/METADATA,sha256=u97jThVrQ5u0ZR5eqizFoLE7rm8abYNioJt8kdZNDv0,4115
17
- voly-0.0.139.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
18
- voly-0.0.139.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
19
- voly-0.0.139.dist-info/RECORD,,
15
+ voly-0.0.141.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
16
+ voly-0.0.141.dist-info/METADATA,sha256=UC3R8Dldao7KZLPGHwtU6JCj0lYgzeQ7hmCZGZELlYc,4115
17
+ voly-0.0.141.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
18
+ voly-0.0.141.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
19
+ voly-0.0.141.dist-info/RECORD,,
File without changes