voly 0.0.140__py3-none-any.whl → 0.0.142__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/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,109 @@ def get_all_moments(x, pdf, model_params=None):
219
219
  moments.update(model_params)
220
220
 
221
221
  return moments
222
+ '''
223
+
224
+
225
+ @catch_exception
226
+ def get_all_moments(x, pdf, model_params=None):
227
+ # Precompute dx for integration
228
+ dx = np.diff(x, prepend=x[0])
229
+
230
+ # Raw Moments (μ_k = E[X^k])
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
+ mean = raw_1
240
+ variance = np.trapz((x - mean)**2 * pdf, x) # m_2
241
+ std_dev = np.sqrt(variance)
242
+
243
+ # Central Moments (m_k = E[(X - μ)^k])
244
+ cent_0 = raw_0 # Zeroth (~1)
245
+ cent_1 = np.trapz((x - mean) * pdf, x) # First (~0)
246
+ cent_2 = variance # Second (variance)
247
+ cent_3 = np.trapz((x - mean)**3 * pdf, x) # Third
248
+ cent_4 = np.trapz((x - mean)**4 * pdf, x) # Fourth
249
+ cent_5 = np.trapz((x - mean)**5 * pdf, x) # Fifth
250
+ cent_6 = np.trapz((x - mean)**6 * pdf, x) # Sixth
251
+
252
+ # Standardized Moments (m̄_k = E[((X - μ)/σ)^k])
253
+ z = (x - mean) / std_dev
254
+ std_0 = np.trapz(pdf, x) # Zeroth (~1)
255
+ std_1 = np.trapz(z * pdf, x) # First (~0)
256
+ std_2 = np.trapz(z**2 * pdf, x) # Second (~1)
257
+ std_3 = np.trapz(z**3 * pdf, x) # Skewness
258
+ std_4 = np.trapz(z**4 * pdf, x) # Kurtosis
259
+ std_5 = np.trapz(z**5 * pdf, x) # Fifth
260
+ std_6 = np.trapz(z**6 * pdf, x) # Sixth
261
+
262
+ # Extra statistics
263
+ cdf = np.cumsum(pdf * dx)
264
+ median = x[np.searchsorted(cdf, 0.5)] # Median
265
+ excess_kurtosis = std_4 - 3
266
+ q25 = x[np.searchsorted(cdf, 0.25)] # 25th percentile
267
+ q75 = x[np.searchsorted(cdf, 0.75)] # 75th percentile
268
+ iqr = q75 - q25
269
+ entropy = -np.trapz(pdf * np.log(pdf + 1e-10), x)
270
+
271
+ # Z-score areas
272
+ o1p = np.sum(pdf[(z > 0) & (z < 1)] * dx[(z > 0) & (z < 1)])
273
+ o2p = np.sum(pdf[(z >= 1) & (z < 2)] * dx[(z >= 1) & (z < 2)])
274
+ o3p = np.sum(pdf[(z >= 2) & (z < 3)] * dx[(z >= 2) & (z < 3)])
275
+ o4p = np.sum(pdf[z >= 3] * dx[z >= 3])
276
+ o1n = np.sum(pdf[(z < 0) & (z > -1)] * dx[(z < 0) & (z > -1)])
277
+ o2n = np.sum(pdf[(z <= -1) & (z > -2)] * dx[(z <= -1) & (z > -2)])
278
+ o3n = np.sum(pdf[(z <= -2) & (z > -3)] * dx[(z <= -2) & (z > -3)])
279
+ o4n = np.sum(pdf[z <= -3] * dx[z <= -3])
280
+
281
+ # Combine results as flat columns
282
+ moments = {
283
+ 'raw_0': raw_0,
284
+ 'raw_1': raw_1,
285
+ 'raw_2': raw_2,
286
+ 'raw_3': raw_3,
287
+ 'raw_4': raw_4,
288
+ 'raw_5': raw_5,
289
+ 'raw_6': raw_6,
290
+ 'cent_0': cent_0,
291
+ 'cent_1': cent_1,
292
+ 'cent_2': cent_2,
293
+ 'cent_3': cent_3,
294
+ 'cent_4': cent_4,
295
+ 'cent_5': cent_5,
296
+ 'cent_6': cent_6,
297
+ 'std_0': std_0,
298
+ 'std_1': std_1,
299
+ 'std_2': std_2,
300
+ 'std_3': std_3,
301
+ 'std_4': std_4,
302
+ 'std_5': std_5,
303
+ 'std_6': std_6,
304
+ 'median': median,
305
+ 'std_dev': std_dev,
306
+ 'excess_kurtosis': excess_kurtosis,
307
+ 'q25': q25,
308
+ 'q75': q75,
309
+ 'iqr': iqr,
310
+ 'entropy': entropy,
311
+ 'o1p': o1p,
312
+ 'o2p': o2p,
313
+ 'o3p': o3p,
314
+ 'o4p': o4p,
315
+ 'o1n': o1n,
316
+ 'o2n': o2n,
317
+ 'o3n': o3n,
318
+ 'o4n': o4n
319
+ }
320
+
321
+ if model_params is not None:
322
+ moments.update(model_params)
323
+
324
+ return moments
222
325
 
223
326
 
224
327
  @catch_exception
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: voly
3
- Version: 0.0.140
3
+ Version: 0.0.142
4
4
  Summary: Options & volatility research package
5
5
  Author-email: Manu de Cara <manu.de.cara@gmail.com>
6
6
  License: MIT
@@ -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=masjK4WrVb925gPGboD8iDAaEN7FY7S4OHYthHPtA3o,13613
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.140.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
16
- voly-0.0.140.dist-info/METADATA,sha256=6hSGujPj6Hbvl2sk8ru_YmxlQ28IpUNXZASJC-iaoLY,4115
17
- voly-0.0.140.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
18
- voly-0.0.140.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
19
- voly-0.0.140.dist-info/RECORD,,
15
+ voly-0.0.142.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
16
+ voly-0.0.142.dist-info/METADATA,sha256=BLz0X2tkaiZqfL5cYXcihLfbrZra3AQRrRXPXrNkS5w,4115
17
+ voly-0.0.142.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
18
+ voly-0.0.142.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
19
+ voly-0.0.142.dist-info/RECORD,,
File without changes