option-prices 0.1.0__py3-none-any.whl → 0.1.1__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.
@@ -0,0 +1,2 @@
1
+ from .bsm import bsm
2
+ from .binomial import binomial
@@ -0,0 +1,64 @@
1
+ import numpy as np
2
+ import scipy as sc
3
+
4
+
5
+ def __moves__(sigma,time_step):
6
+ u=np.exp(sigma*np.sqrt(time_step))
7
+ d=np.exp(np.negative(sigma)*np.sqrt(time_step))
8
+ return [u,d]
9
+
10
+
11
+
12
+
13
+ def binomial(S:int,K:int,r:int,T:int,time_step:int,u:int=None,d:int=None,sigma:int=None,time_scale:str="year",option_type:str="call"):
14
+ r = r/100
15
+ if time_scale=="month":
16
+ T_years=T/12
17
+ time_step=time_step/12
18
+ elif time_scale == "day":
19
+ T_years = T / 365
20
+ time_step = time_step / 365
21
+ if u!=None and d!=None:
22
+ pass
23
+ elif sigma!=None:
24
+ move=__moves__(sigma,time_step)
25
+ u=move[0]
26
+ d=move[1]
27
+ n_steps = int(T/time_step)
28
+
29
+
30
+ #price tree
31
+ prob = (np.exp(r*time_step)-d)/(u-d)
32
+ nodes = np.zeros([n_steps+1,n_steps+1])
33
+ nodes[0][0]=S
34
+ for i in range(1,n_steps+1):
35
+ nodes[i][0]=nodes[i-1][0]*u
36
+ nodes[i, 1:i+1] = nodes[i-1, 0:i] * d
37
+
38
+
39
+
40
+ #terminal node calculation
41
+ for i in range(n_steps+1):
42
+ if option_type=="call":
43
+ nodes[-1,i]=max(nodes[-1,i]-K,0)
44
+ elif option_type=="put":
45
+ nodes[-1,i]=max(K-nodes[-1,i],0)
46
+
47
+
48
+
49
+ #reverse calculation
50
+ copy=np.copy(nodes)
51
+ for i in reversed(range(1,n_steps+1)):
52
+ for j in range(i):
53
+ nodes[i-1][j]=np.exp(-r * time_step) * (prob * nodes[i, j] + (1 - prob) * nodes[i, j+1])
54
+
55
+
56
+ return round(nodes[0,0],2)
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
@@ -6,9 +6,11 @@ N= norm.cdf
6
6
  #d₁ = [ln(S₀/K) + (r + σ²/2)t] / (σ√t)
7
7
  #d₂ = d₁ - σ√t
8
8
 
9
- def bsm(S,K,T,r,sigma,option_type="call",time_scale="Year"):
10
- if time_scale == "Month":
9
+ def bsm(S,K,T,r,sigma,option_type="call",time_scale="year"):
10
+ if time_scale == "month":
11
11
  T = T/12
12
+ elif time_scale != "month" or time_scale != "year":
13
+ "plz enter month or year as you time scale"
12
14
  r = r/100
13
15
  sigma = sigma/100
14
16
  denominator = (sigma*np.sqrt(T))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
- Name: option_prices
3
- Version: 0.1.0
2
+ Name: option-prices
3
+ Version: 0.1.1
4
4
  Summary: Option pricing using the Black Scholes Model
5
5
  Author-email: Shreenivas Dani <shreenivasdani@gmail.com>
6
6
  License: MIT
@@ -11,13 +11,13 @@ Requires-Dist: numpy
11
11
  Requires-Dist: scipy
12
12
  Dynamic: license-file
13
13
 
14
- # BSM
14
+ # Option-prices
15
15
 
16
- This package is to be used for option price calculation using the Black Scholes Model
16
+ This package is to be used for option price calculation using the Black Scholes Model and binomial model
17
17
 
18
18
  ## Description
19
19
 
20
- This package provides a simple and easy-to-use implementation of the Black Scholes Model for calculating European call and put option prices. It is designed for students, traders, and developers who want a lightweight and reliable tool for option pricing without the complexity of larger libraries.
20
+ This package provides a simple and easy-to-use implementation of the Black Scholes Model and binomial model for calculating European call and put option prices. It is designed for students, traders, and developers who want a lightweight and reliable tool for option pricing without the complexity of larger libraries.
21
21
 
22
22
  ## Getting Started
23
23
 
@@ -27,15 +27,33 @@ Numpy,Scipy
27
27
 
28
28
  ### Installing
29
29
 
30
- pip install bsm
30
+ pip install option-prices
31
31
 
32
32
  ### Executing program
33
33
 
34
- from bsm import bsm
34
+ import option_pricings
35
+ from option_pricings import bsm
36
+ from option_pricings import binomial
35
37
 
36
38
  ## example when time scale is in year
37
39
  price=bsm(S=50,K=50,T=1,r=6,sigma=25,option_type = "call",time_scale="Year")
38
40
  print(price)
41
+
42
+ price = binomial(S=30,K=40,r=6,T=2,time_step = 1,u=1.2,d=0.8)
43
+ print(price)
44
+
45
+ # using sigma parameter instead of u and d
46
+ price = binomial(S=30,K=40,r=6,T=2,time_step = 1,sigma = 25)
47
+ print(price)
48
+
49
+ # put option
50
+ price = binomial(S=30,K=40,r=6,T=2,time_step = 1,u=1.2,d=0.8,option_type="put")
51
+ print(price)
52
+
53
+ # changing time scale to month
54
+ price = binomial(S=30,K=40,r=6,T=24,time_step = 12,u=1.2,d=0.8,time_scale = "month")
55
+ print(price)
56
+
39
57
  ## example when time scale is in month
40
58
  price = bsm(S=50,K=50,T=6,r=6,sigma=25,option_type = "call",time_scale="Month")
41
59
  print(price)
@@ -43,6 +61,7 @@ print(price)
43
61
  Note:
44
62
  When time_scale="Year", enter T in years.
45
63
  When time_scale="Month", enter T in months.
64
+ same thing applies for binomial
46
65
  ## Authors
47
66
 
48
67
  Shreenivas Dani
@@ -0,0 +1,8 @@
1
+ option_prices/__init__.py,sha256=w6qucgi5Z3s8ApEKrqj8m91n_mjzk_g33OwYzYSBH7Q,52
2
+ option_prices/binomial.py,sha256=pGJK4KKPC1VsJUV1h38CkGMBJYV-qTG8wa-OIHbxS9Y,1435
3
+ option_prices/bsm.py,sha256=_2z8WNm-df_gBeBSbEJqnrIarQsoWSLwQvDwuiIqG5I,962
4
+ option_prices-0.1.1.dist-info/licenses/LICENSE,sha256=S_fbX1OLfL7GYfxafKhn4E6-9cDMpbxy3-OgQisZr5A,1087
5
+ option_prices-0.1.1.dist-info/METADATA,sha256=W7XE8n3PsTMUd_zBrp0N4nzfOqXrmYbl-I_t2F1CTYc,2093
6
+ option_prices-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
7
+ option_prices-0.1.1.dist-info/top_level.txt,sha256=CLxae_Bn0E67xofN4II5QBo1FnoTGrq7pU0Qeh4rH4g,14
8
+ option_prices-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.10.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1 @@
1
+ option_prices
@@ -1,7 +0,0 @@
1
- option_prices-0.1.0.dist-info/licenses/LICENSE,sha256=S_fbX1OLfL7GYfxafKhn4E6-9cDMpbxy3-OgQisZr5A,1087
2
- option_pricings/__init__.py,sha256=BxB2eTmLv0SnZmRQvBPxsAMjxGi9IzUybs13ydxrBKA,20
3
- option_pricings/bsm.py,sha256=XpJwqKC1K8KKNaDZmwiIyNUaCyGsqwQWdew3elvw-2Y,852
4
- option_prices-0.1.0.dist-info/METADATA,sha256=J78QP_UejtnQLRYNzIwqOSV-uMkq09AXPee8ZzYRC3U,1480
5
- option_prices-0.1.0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
6
- option_prices-0.1.0.dist-info/top_level.txt,sha256=l0EOs-Inr3wtGhBYn7jleXhMdO3ieLmttoU5twwomAE,16
7
- option_prices-0.1.0.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- option_pricings
@@ -1 +0,0 @@
1
- from .bsm import bsm