voly 0.0.160__py3-none-any.whl → 0.0.162__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/formulas.py +28 -7
- {voly-0.0.160.dist-info → voly-0.0.162.dist-info}/METADATA +1 -1
- {voly-0.0.160.dist-info → voly-0.0.162.dist-info}/RECORD +6 -6
- {voly-0.0.160.dist-info → voly-0.0.162.dist-info}/WHEEL +1 -1
- {voly-0.0.160.dist-info → voly-0.0.162.dist-info}/licenses/LICENSE +0 -0
- {voly-0.0.160.dist-info → voly-0.0.162.dist-info}/top_level.txt +0 -0
voly/formulas.py
CHANGED
@@ -15,22 +15,43 @@ from typing import Tuple
|
|
15
15
|
def vectorize_inputs(func):
|
16
16
|
"""
|
17
17
|
Decorator to vectorize Black-Scholes functions to handle both scalar and array inputs.
|
18
|
+
For invalid inputs (K <= 0, o <= 0, or t <= 0), returns np.nan instead of trying to compute.
|
18
19
|
"""
|
20
|
+
|
19
21
|
def wrapper(s, K, r, o, t, option_type='call'):
|
20
22
|
# Check if inputs are scalar
|
21
23
|
K_scalar = np.isscalar(K)
|
22
24
|
o_scalar = np.isscalar(o)
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
t_scalar = np.isscalar(t)
|
26
|
+
|
27
|
+
# Convert pandas Series to numpy arrays if needed
|
28
|
+
if isinstance(K, pd.Series):
|
29
|
+
K = K.values
|
30
|
+
if isinstance(o, pd.Series):
|
31
|
+
o = o.values
|
32
|
+
if isinstance(t, pd.Series):
|
33
|
+
t = t.values
|
34
|
+
|
35
|
+
# If all inputs are scalar, use the original function directly
|
36
|
+
if K_scalar and o_scalar and t_scalar:
|
26
37
|
return func(s, K, r, o, t, option_type)
|
27
38
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
39
|
+
# For arrays, we need to apply the function element-wise
|
40
|
+
# Instead of using np.vectorize directly, we'll create a custom vectorized function
|
41
|
+
# that handles the conditions properly
|
42
|
+
def safe_vectorized_func(K_val, o_val, t_val):
|
43
|
+
# Check for invalid strike price, volatility, or time values
|
44
|
+
if K_val <= 0 or o_val <= 0 or t_val <= 0:
|
45
|
+
return np.nan # Return NaN for invalid inputs
|
46
|
+
else:
|
47
|
+
# Only call the function if inputs are valid
|
48
|
+
return func(s, K_val, r, o_val, t_val, option_type)
|
49
|
+
|
50
|
+
# Now use numpy's vectorize on our safe function
|
51
|
+
vectorized_func = np.vectorize(safe_vectorized_func)
|
31
52
|
|
32
53
|
# Call the vectorized function with the inputs
|
33
|
-
return vectorized_func(K, o)
|
54
|
+
return vectorized_func(K, o, t)
|
34
55
|
|
35
56
|
return wrapper
|
36
57
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
voly/__init__.py,sha256=8xyDk7rFCn_MOD5hxuv5cxxKZvBVRiSIM7TgaMPpwpw,211
|
2
2
|
voly/client.py,sha256=-yE1_cBvjkK-BO_kKCYtn4WPbNOhAzT0hsfykU5LvQQ,14761
|
3
3
|
voly/exceptions.py,sha256=PBsbn1vNMvKcCJwwJ4lBO6glD85jo1h2qiEmD7ArAjs,92
|
4
|
-
voly/formulas.py,sha256=
|
4
|
+
voly/formulas.py,sha256=2A_QzGxor411Qq5HqzS_YwvkViXauGhelooRGwcdCPE,11635
|
5
5
|
voly/models.py,sha256=o-pHujGfr5Gn8ItckMzLI4Q8yaX9FQaV8UjCxv2zgTY,3364
|
6
6
|
voly/core/__init__.py,sha256=bu6fS2I1Pj9fPPnl-zY3L7NqrZSY5Zy6NY2uMUvdhKs,183
|
7
7
|
voly/core/charts.py,sha256=E21OZB5lTY4YL2flgaFJ6s5g3_ExtAQT2zryZZxLPyM,12735
|
@@ -13,8 +13,8 @@ voly/core/rnd.py,sha256=GoC3m1Q46Wnk5tV_mstr-3_aktHeue6BBLh4DQTciW0,13307
|
|
13
13
|
voly/utils/__init__.py,sha256=E05mWatyC-PDOsCxQV1p5Xi1IgpOomxrNURyCx_gB-w,200
|
14
14
|
voly/utils/density.py,sha256=q0fX4im9TGwMCZ32Hzdv8CNh56KnJo8bmG5w0gVWZH8,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.162.dist-info/licenses/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
|
17
|
+
voly-0.0.162.dist-info/METADATA,sha256=h25kYFEQA8dVWGnDHNdpm7KLhBIuzF7I2txHAMTSsCY,4115
|
18
|
+
voly-0.0.162.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
|
19
|
+
voly-0.0.162.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
|
20
|
+
voly-0.0.162.dist-info/RECORD,,
|
File without changes
|
File without changes
|