谁能帮我修复这个 R 代码?

anyone can help me to fix this R code?

这是我的复合期权代码R 为什么我在 R 中找不到函数 'pbivnorm'? 那是因为我的R?或者是什么? 请帮我 谢谢

#Compound Option
> PoC<-function(Sbtg,St,K1,K2,S,r,t1,t2){
+ D2=((log(St/K2))+((r-(0.5*(S^2)))*(t2/365)))/(S*sqrt(t2/365))
+ D2btg=((log(St/Sbtg))+((r-(0.5*(S^2)))*(t1/365)))/(S*sqrt(t1/365))
+ D1=D2+(S*sqrt(t2/365))
+ D1btg=D2btg+(S*sqrt(t1/365))
+ rho=sqrt(t1/t2)
+ N1=pnorm(-D2btg)
+ N2=pbivnorm(-D2btg,D2,-rho)
+ N3=pbivnorm(-D1btg,D1,-rho)
+ poc=(K2*exp(-r*(t2/365))*N2)-(St*N3)+(K1*exp(-r*(t1/365))*N1)
+ cat("       Valuasi Compound Option Put on Call Saham Facebook    ","\n")
+ cat("========================================================================","\n")
+ cat("Harga Pasar Saham AAPL (ST1)           = ",St,"\n")
+ cat("Harga Saham Pada saat T1 dan K1 (S*)   = ",Sbtg,"\n")
+ cat("Harga Pelaksanaan Compound Option (K1) = ",K1,"\n")
+ cat("Harga Pelaksanaan Opsi Put (K2)        = ",K2,"\n")
+ cat("Exercise date pertama (T1)            =  28 Maret 2014 ","\n")
+ cat("Exercise date kedua (T2)               =  14 Mei 2014 ","\n")
+ cat("Sisa Usia Compound Option              = ",t1," hari","\n")
+ cat("Sisa Usia Opsi Put                     = ",t2," hari","\n")
+ cat("Volatilitas Harga saham                = ",S,"\n")
+ cat("Tingkat bunga bebas risiko             = ",r,"\n")
+ cat("========================================================================","\n")
+ cat("Harga Compound Option Put on Call       = ",poc,"\n")
+ }
> PoC(157.4808243,77.48,77.5,80,0.253941089,0.0025,14,49)
Error in PoC(157.4808243, 77.48, 77.5, 80, 0.253941089, 0.0025, 14, 49) : 
  could not find function "pbivnorm"
> 

您缺少对 library() 的调用以确保 pbivnorm() 附加到命名空间。

library(pbivnorm)

PoC <- function(Sbtg, St, K1, K2, S, r, t1, t2) {
    D2 <- ((log(St/K2))+((r-(0.5*(S^2)))*(t2/365))) / (S*sqrt(t2/365))
    D2btg <- ((log(St/Sbtg))+((r-(0.5*(S^2)))*(t1/365)))/(S*sqrt(t1/365))
    D1 <- D2 + (S*sqrt(t2/365))
    D1btg <- D2btg + (S*sqrt(t1/365))
    rho <- sqrt(t1/t2)
    N1 <- pnorm(-D2btg)
    N2 <- pbivnorm(-D2btg, D2, -rho)
    N3 <- pbivnorm(-D1btg, D1, -rho)
    poc <- (K2*exp(-r*(t2/365))*N2) - (St*N3) + (K1*exp(-r*(t1/365))*N1)
    cat("       Valuasi Compound Option Put on Call Saham Facebook    ","\n")
    cat("========================================================================","\n")
    cat("Harga Pasar Saham AAPL (ST1)           = ",St,"\n")
    cat("Harga Saham Pada saat T1 dan K1 (S*)   = ",Sbtg,"\n")
    cat("Harga Pelaksanaan Compound Option (K1) = ",K1,"\n")
    cat("Harga Pelaksanaan Opsi Put (K2)        = ",K2,"\n")
    cat("Exercise date pertama (T1)             =  28 Maret 2014 ","\n")
    cat("Exercise date kedua (T2)               =  14 Mei 2014 ","\n")
    cat("Sisa Usia Compound Option              = ",t1," hari","\n")
    cat("Sisa Usia Opsi Put                     = ",t2," hari","\n")
    cat("Volatilitas Harga saham                = ",S,"\n")
    cat("Tingkat bunga bebas risiko             = ",r,"\n")
    cat("========================================================================","\n")
    cat("Harga Compound Option Put on Call       = ",poc,"\n")
}

PoC(157.4808243, 77.48, 77.5, 80, 0.253941089, 0.0025, 14, 49)