jeudi 23 mars 2017

if argument is not interpretable as logical in R

I'm trying to check for no arbitrage opportunity in a set of option derivarives.

this is the main function

mertConst <- function (PriceOpt, S, K, r, Tt, TypeCall){
  TimeToMat <- Tt
  resCheck <- logical (length(PriceOpt))
  for(i in c(1:length(PriceOpt))){
    if(TypeCall[i]){
     cond <- PriceOpt[i] >= max(S[i] - K[i]*exp(-r[i]*Tt[i]), 0)
     resCheck[i] <- cond
    }else{
    cond <- PriceOpt[i] >= max(K[i]*exp(-r[i]*Tt[i]) - S[i], 0)
    resCheck[i] <- cond
    }
  }
  return(resCheck)
}

but when I try to run the code to test the condition that I previously set

checkMerton <- mertConst(PriceOpt = PriceOpt, S = S, K = K, r = r, Tt = Tt, TypeCall = TypeCall)

I get this error

 Error in if (TypeCall[i]) { : argument is not interpretable as logical

any suggestions?

Aucun commentaire:

Enregistrer un commentaire