在r

时间:2019-09-12 13:28:32

标签: r plot

我试图在绘制欧洲看涨期权的同一张图中绘制Black&Scholes欧洲看涨期权价格。

不幸的是,我的代码无法正常工作。

#plot the call payoff
payoff.call <- function(S) sapply(S, function(S) max(c(S-K,0))) #payoff 

K <- 50 #set the strike price

curve(payoff.call, 0, 100, main = "Long Call Option Payoff function", 
      col = "blue", lty = 1, lwd = 1,xlab = "S", ylab = expression(f(S))) 

#plot the B&S prices on the same graph
fair_value <- function(S) sapply(S, function(S) S*pnorm((log(S/K) + (r + 0.5*sigma^2)*tau)/(sigma*sqrt(tau))) - K*exp(-r*(tau))*pnorm((log(S/K) + (r + 0.5*sigma^2)*tau)/(sigma*sqrt(tau)))- sigma*sqrt(tau))

tau <- 1/360 #set the time to maturity
r <- 0.12 #set the interest rate
sigma <- 0.3 #set the vola

curve(fair_value, 0, 100, col = "black", add= TRUE)   

我得到的是一张图表,其中收益显示为预期,但我看不到B&S价格的曲线。

0 个答案:

没有答案