-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpricing.R
96 lines (78 loc) · 2.39 KB
/
pricing.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Black-Scholes formula for the price of european options without dividends
BS_Price <-function(data, K, Sigma, r, div, opt_type)
{
S0 = data['Var2']
Maturity = data['Var1']
d1 <- (log(S0/K)+(r - div + 0.5*Sigma^2)*Maturity)/(Sigma*sqrt(Maturity))
d2 <- d1 - Sigma*sqrt(Maturity)
if(opt_type == 'c')
{
return(S0*exp(-div*Maturity)*pnorm(d1, 0, 1) - K*exp(-r*Maturity)*pnorm(d2, 0, 1))
}
else
{
return(-S0*exp(-div*Maturity)*pnorm(-d1, 0, 1) + K*exp(-r*Maturity)*pnorm(-d2, 0, 1))
}
}
Delta <- function(data, K, Sigma, r, div, opt_type)
{
S0 = data['Var2']
Maturity = data['Var1']
d1 <- (log(S0/K)+(r - div + 0.5*Sigma^2)*Maturity)/(Sigma*sqrt(Maturity))
if(opt_type == 'c')
{
return(exp(-div*Maturity)*pnorm(d1, 0, 1))
}
else
{
return(exp(-div*Maturity)*(pnorm(d1, 0, 1)-1))
}
}
Gamma <- function(data, K, Sigma, r, div, opt_type)
{
S0 = data['Var2']
Maturity = data['Var1']
d1 <- (log(S0/K)+(r - div + 0.5*Sigma^2)*Maturity)/(Sigma*sqrt(Maturity))
return(exp(-div*Maturity)*dnorm(d1, 0, 1)/(S0*Sigma*sqrt(Maturity)))
}
Theta <- function(data, K, Sigma, r, div, opt_type)
{
S0 = data['Var2']
Maturity = data['Var1']
d1 <- (log(S0/K)+(r - div + 0.5*Sigma^2)*Maturity)/(Sigma*sqrt(Maturity))
d2 <- d1 - Sigma*sqrt(Maturity)
if(opt_type == 'c')
{
return(-S0*exp(-div*Maturity)*dnorm(d1, 0, 1)*Sigma/(2*sqrt(Maturity))
+div*S0*exp(-div*Maturity)*pnorm(d1, 0, 1)
-r*K*exp(-r*Maturity)*pnorm(d2, 0, 1))
}
else
{
return(-S0*exp(-div*Maturity)*dnorm(d1, 0, 1)*Sigma/(2*sqrt(Maturity))
-div*S0*exp(-div*Maturity)*pnorm(-d1, 0, 1)
+r*K*exp(-r*Maturity)*pnorm(-d2, 0, 1))
}
}
Vega <- function(data, K, Sigma, r, div, opt_type)
{
S0 = data['Var2']
Maturity = data['Var1']
d1 <- (log(S0/K)+(r - div + 0.5*Sigma^2)*Maturity)/(Sigma*sqrt(Maturity))
return(S0*exp(-div*Maturity)*sqrt(Maturity)*dnorm(d1, 0, 1))
}
Rho <- function(data, K, Sigma, r, div, opt_type)
{
S0 = data['Var2']
Maturity = data['Var1']
d1 <- (log(S0/K)+(r - div + 0.5*Sigma^2)*Maturity)/(Sigma*sqrt(Maturity))
d2 <- d1 - Sigma*sqrt(Maturity)
if(opt_type == 'c')
{
return(K*Maturity*exp(-r*Maturity)*pnorm(d2, 0, 1))
}
else
{
return(-K*Maturity*exp(-r*Maturity)*pnorm(-d2, 0, 1))
}
}