voly 0.0.42__py3-none-any.whl → 0.0.44__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 +44 -3
 - {voly-0.0.42.dist-info → voly-0.0.44.dist-info}/METADATA +1 -1
 - {voly-0.0.42.dist-info → voly-0.0.44.dist-info}/RECORD +6 -6
 - {voly-0.0.42.dist-info → voly-0.0.44.dist-info}/LICENSE +0 -0
 - {voly-0.0.42.dist-info → voly-0.0.44.dist-info}/WHEEL +0 -0
 - {voly-0.0.42.dist-info → voly-0.0.44.dist-info}/top_level.txt +0 -0
 
    
        voly/formulas.py
    CHANGED
    
    | 
         @@ -10,19 +10,50 @@ from voly.models import SVIModel 
     | 
|
| 
       10 
10 
     | 
    
         
             
            from math import exp
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            voly/__init__.py,sha256=8xyDk7rFCn_MOD5hxuv5cxxKZvBVRiSIM7TgaMPpwpw,211
         
     | 
| 
       2 
2 
     | 
    
         
             
            voly/client.py,sha256=8nBT2cbjSCYn9Qf1xEFMifmlggkg7BI9ANFVNhHYKUI,19171
         
     | 
| 
       3 
3 
     | 
    
         
             
            voly/exceptions.py,sha256=PBsbn1vNMvKcCJwwJ4lBO6glD85jo1h2qiEmD7ArAjs,92
         
     | 
| 
       4 
     | 
    
         
            -
            voly/formulas.py,sha256= 
     | 
| 
      
 4 
     | 
    
         
            +
            voly/formulas.py,sha256=vk00FVVtdxPz2sL89fK-6q9WW-rqyjVhwbPPLiZGaIU,8541
         
     | 
| 
       5 
5 
     | 
    
         
             
            voly/models.py,sha256=YJ12aamLz_-aOni4Qm0_XV9u4bjKK3vfJz0J2gc1h0o,3565
         
     | 
| 
       6 
6 
     | 
    
         
             
            voly/core/__init__.py,sha256=bu6fS2I1Pj9fPPnl-zY3L7NqrZSY5Zy6NY2uMUvdhKs,183
         
     | 
| 
       7 
7 
     | 
    
         
             
            voly/core/charts.py,sha256=T8cogkiHj8NcFxfARumNvAjLJUAxsMlHUOVgshwjye8,26474
         
     | 
| 
         @@ -11,8 +11,8 @@ voly/core/interpolate.py,sha256=ztVIePJZOh-CIbn69wkh1JW2rKywNe2FEewRN0zcSAo,8185 
     | 
|
| 
       11 
11 
     | 
    
         
             
            voly/core/rnd.py,sha256=8FTU-Qp9epW9yE4XSOdiFGIRXrGyXqF6mVgZn1NMvxk,11813
         
     | 
| 
       12 
12 
     | 
    
         
             
            voly/utils/__init__.py,sha256=E05mWatyC-PDOsCxQV1p5Xi1IgpOomxrNURyCx_gB-w,200
         
     | 
| 
       13 
13 
     | 
    
         
             
            voly/utils/logger.py,sha256=4-_2bVJmq17Q0d7Rd2mPg1AeR8gxv6EPvcmBDMFWcSM,1744
         
     | 
| 
       14 
     | 
    
         
            -
            voly-0.0. 
     | 
| 
       15 
     | 
    
         
            -
            voly-0.0. 
     | 
| 
       16 
     | 
    
         
            -
            voly-0.0. 
     | 
| 
       17 
     | 
    
         
            -
            voly-0.0. 
     | 
| 
       18 
     | 
    
         
            -
            voly-0.0. 
     | 
| 
      
 14 
     | 
    
         
            +
            voly-0.0.44.dist-info/LICENSE,sha256=wcHIVbE12jfcBOai_wqBKY6xvNQU5E909xL1zZNq_2Q,1065
         
     | 
| 
      
 15 
     | 
    
         
            +
            voly-0.0.44.dist-info/METADATA,sha256=hKSBZrDxJeHiUbguAQ0Bmq98DXwUc-SE5a3TVPs8HQo,4092
         
     | 
| 
      
 16 
     | 
    
         
            +
            voly-0.0.44.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
         
     | 
| 
      
 17 
     | 
    
         
            +
            voly-0.0.44.dist-info/top_level.txt,sha256=ZfLw2sSxF-LrKAkgGjOmeTcw6_gD-30zvtdEY5W4B7c,5
         
     | 
| 
      
 18 
     | 
    
         
            +
            voly-0.0.44.dist-info/RECORD,,
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     |