voly 0.0.42__tar.gz → 0.0.44__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.42
3
+ Version: 0.0.44
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.42"
7
+ version = "0.0.44"
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.42"
63
+ python_version = "0.0.44"
64
64
  warn_return_any = true
65
65
  warn_unused_configs = true
66
66
  disallow_untyped_defs = true
@@ -10,19 +10,50 @@ from voly.models import SVIModel
10
10
  from math import exp
11
11
 
12
12
 
13
- def d1(s: float, k: float, r: float, vol: float, t: float) -> float:
13
+ @catch_exception
14
+ def vectorize_inputs(func):
15
+ """
16
+ Decorator to vectorize Black-Scholes functions to handle both scalar and array inputs.
17
+ """
18
+ def wrapper(s, k, r, vol, t, option_type='call'):
19
+ # Check if inputs are scalar
20
+ k_scalar = np.isscalar(k)
21
+ vol_scalar = np.isscalar(vol)
22
+
23
+ # If both inputs are scalar, use the original function directly
24
+ if k_scalar and vol_scalar:
25
+ return func(s, k, r, vol, t, option_type)
26
+
27
+ # Use NumPy's vectorize to handle array inputs
28
+ vectorized_func = np.vectorize(lambda k_val, vol_val:
29
+ func(s, k_val, r, vol_val, t, option_type))
30
+
31
+ # Call the vectorized function with the inputs
32
+ return vectorized_func(k, vol)
33
+
34
+ return wrapper
35
+
36
+
37
+ @catch_exception
38
+ @vectorize_inputs
39
+ def d1(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
40
+ # option_type is ignored in this function but included for compatibility
14
41
  if vol <= 0 or t <= 0:
15
42
  return np.nan
16
43
  return (np.log(s / k) + (r + vol * vol / 2) * t) / (vol * np.sqrt(t))
17
44
 
18
45
 
19
- def d2(s: float, k: float, r: float, vol: float, t: float) -> float:
46
+ @catch_exception
47
+ @vectorize_inputs
48
+ def d2(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
49
+ # option_type is ignored in this function but included for compatibility
20
50
  if vol <= 0 or t <= 0:
21
51
  return np.nan
22
- return d1(s, k, r, vol, t) - vol * np.sqrt(t)
52
+ return d1(s, k, r, vol, t, option_type) - vol * np.sqrt(t)
23
53
 
24
54
 
25
55
  @catch_exception
56
+ @vectorize_inputs
26
57
  def bs(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
27
58
  if vol <= 0 or t <= 0:
28
59
  # Intrinsic value at expiry
@@ -41,6 +72,7 @@ def bs(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'c
41
72
 
42
73
 
43
74
  @catch_exception
75
+ @vectorize_inputs
44
76
  def delta(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
45
77
  if vol <= 0 or t <= 0:
46
78
  # At expiry, delta is either 0 or 1 for call, 0 or -1 for put
@@ -58,6 +90,7 @@ def delta(s: float, k: float, r: float, vol: float, t: float, option_type: str =
58
90
 
59
91
 
60
92
  @catch_exception
93
+ @vectorize_inputs
61
94
  def gamma(s: float, k: float, r: float, vol: float, t: float) -> float:
62
95
  if vol <= 0 or t <= 0:
63
96
  return 0.0
@@ -67,6 +100,7 @@ def gamma(s: float, k: float, r: float, vol: float, t: float) -> float:
67
100
 
68
101
 
69
102
  @catch_exception
103
+ @vectorize_inputs
70
104
  def vega(s: float, k: float, r: float, vol: float, t: float) -> float:
71
105
  if vol <= 0 or t <= 0:
72
106
  return 0.0
@@ -76,6 +110,7 @@ def vega(s: float, k: float, r: float, vol: float, t: float) -> float:
76
110
 
77
111
 
78
112
  @catch_exception
113
+ @vectorize_inputs
79
114
  def theta(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
80
115
  if vol <= 0 or t <= 0:
81
116
  return 0.0
@@ -97,6 +132,7 @@ def theta(s: float, k: float, r: float, vol: float, t: float, option_type: str =
97
132
 
98
133
 
99
134
  @catch_exception
135
+ @vectorize_inputs
100
136
  def rho(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
101
137
  if vol <= 0 or t <= 0:
102
138
  return 0.0
@@ -110,6 +146,7 @@ def rho(s: float, k: float, r: float, vol: float, t: float, option_type: str = '
110
146
 
111
147
 
112
148
  @catch_exception
149
+ @vectorize_inputs
113
150
  def vanna(s: float, k: float, r: float, vol: float, t: float) -> float:
114
151
  if vol <= 0 or t <= 0:
115
152
  return 0.0
@@ -121,6 +158,7 @@ def vanna(s: float, k: float, r: float, vol: float, t: float) -> float:
121
158
 
122
159
 
123
160
  @catch_exception
161
+ @vectorize_inputs
124
162
  def volga(s: float, k: float, r: float, vol: float, t: float) -> float:
125
163
  if vol <= 0 or t <= 0:
126
164
  return 0.0
@@ -132,6 +170,7 @@ def volga(s: float, k: float, r: float, vol: float, t: float) -> float:
132
170
 
133
171
 
134
172
  @catch_exception
173
+ @vectorize_inputs
135
174
  def charm(s: float, k: float, r: float, vol: float, t: float, option_type: str = 'call') -> float:
136
175
  if vol <= 0 or t <= 0:
137
176
  return 0.0
@@ -153,6 +192,7 @@ def charm(s: float, k: float, r: float, vol: float, t: float, option_type: str =
153
192
 
154
193
 
155
194
  @catch_exception
195
+ @vectorize_inputs
156
196
  def greeks(s: float, k: float, r: float, vol: float, t: float,
157
197
  option_type: str = 'call') -> Dict[str, float]:
158
198
  return {
@@ -169,6 +209,7 @@ def greeks(s: float, k: float, r: float, vol: float, t: float,
169
209
 
170
210
 
171
211
  @catch_exception
212
+ @vectorize_inputs
172
213
  def iv(option_price: float, s: float, k: float, r: float, t: float,
173
214
  option_type: str = 'call', precision: float = 1e-8,
174
215
  max_iterations: int = 100) -> float:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: voly
3
- Version: 0.0.42
3
+ Version: 0.0.44
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
File without changes