Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Implied Volatility Surface
K<-c(7000,7500,8000,8500,9000,9250,9500,9750,10000,10250,10500,10750,11000,11500,12000) P<-c(2364.10,1881.80,1411.59,949.73,540.84,375.43,225.80,171.91,115.22,71.55,50.18,42.75,34.42,20.47,14.89) S<-9292 T<-3.75 SL <- function(x,v) { (x<=0)*((1+v)*exp((1-v)*x)/2)+(x>0)*(1-(1-v)*exp(-(1+v)*x)/2) } call <- function(S,vol,K,T) { d1 <- (log(S/K)+vol^2*T/2)/(vol*sqrt(T)) d2 <- (log(S/K)-vol^2*T/2)/(vol*sqrt(T)) S*pnorm(d1)-K*pnorm(d2) } call2 <- function(S,vol,K,T) { b <- vol/sqrt(2) d <- (log(S/K)+log(1-b^2*T))/(b*sqrt(T)) S*SL(d,b*sqrt(T))-K*SL(d,0) } solvevol <- function(P,S,vol,K,T) { (call(S,vol,K,T)-P)^2 } solvevol2 <- function(P,S,vol,K,T) { (call2(S,sqrt(2/T)*tanh(vol),K,T)-P)^2 } vol <- c() vol2 <- c() for (ell in 1:length(K)){ res<-nlm(solvevol,p=0.05,S=S,K=K[ell],P=P[ell],T=T) vol<-c(vol,res$estimate) res<-nlm(solvevol2,p=0.05,S=S,K=K[ell],P=P[ell],T=T) vol2<-c(vol2,res$estimate) } atanh(vol2*sqrt(T/2))/vol matplot(K,cbind(vol*sqrt(365),sqrt(365)*atanh(vol2*sqrt(T/2))),type='l',col=c('blue','red'),main='Implied Volatility Surface') #vol<-sqrt(2/T)*ppoints(200) #for (ell in 1:length(K)) { #plot(vol,call2(S,vol,K[ell],T),type='l') #abline(P[ell],0) # }
run
|
edit
|
history
|
help
0
R
Variance Gamme process 2
Exintegral-19-03-2021
R1
09-09-2020GramSchmdit
Basic Programming
ExDecaiEulerMin23-02-21
ax² + bx + c = 0 (Solução e gráfico com as raízes)
Regra-trapezio
Sample