comparison fbs/helpers.py @ 1:b853194dc28b

add methods for eu call option
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Mon, 15 Nov 2021 23:14:41 +0100
parents
children
comparison
equal deleted inserted replaced
0:e5f3f855e6f9 1:b853194dc28b
1 """
2 Helper methods
3 """
4
5 import math
6 import numpy as np
7 from scipy.stats import norm
8
9
10 class Option:
11 def __init__(self, spot_price, exercise_price, risk_free_rate, std, expiration):
12 """
13 :param spot_price: spot price of the underlying asset at t0, float, required
14 :param exercise_price: exercise price of the option, float, required
15 :param risk_free_rate: float, required
16 :param std: standard deviation of the return rate of P, float, required
17 :param expiration: time to expiration, float, required
18 :return: None
19 """
20
21 self.s = spot_price
22 self.k = exercise_price
23 self.r = risk_free_rate
24 self.std = std
25 self.t = expiration
26
27 def compute_eu_call_price(self):
28 """
29 Determine the value of an European call option
30 :return:
31 """
32
33 d1 = self.compute_d1()
34 d2 = self.compute_d2()
35
36 price = self.s * norm.cdf(d1) - self.k * math.exp(- self.r * self.t) * norm.cdf(d2)
37
38 return price
39
40 def compute_d1(self):
41 """
42 Determine d1 coefficient
43 :return: float
44 """
45
46 numerator = (np.log(self.s / self.k) + (self.r + (self.std**2 / 2)) * self.t)
47 denominator = self.std * np.sqrt(self.t)
48
49 d1 = numerator / denominator
50
51 return d1
52
53 def compute_d2(self):
54 """
55 Determine d2 coefficient
56 :return: float
57 """
58
59 d1 = self.compute_d1()
60 d2 = d1 - self.std * np.sqrt(self.t)
61
62 return d2