2016-10-08 139 views
1

這是函數聲明(fOptions::GBSGreeks)我想要的清單適用於:如何使用此功能?

function (Selection = c("Delta", "Theta", "Vega", "Rho", "Lambda", 
    "Gamma", "CofC"), TypeFlag = c("c", "p"), S, X, Time, r, 
    b, sigma) 

我想嘗試不同的Selection同時固定所有其它參數。我想:

library(fOptions) 

greeks <- lapply(Selection=list('Delta', 'Gamma', 'Vega', 'Theta', 'Rho'), 
      FUN=fOptions::GBSGreeks, TypeFlag='p', S=100.0, X=100.0, Time=1.0, r=0.05, b=0, sigma=0.05) 

但結果只是一個單一的元素:

[[1]] 
[1] -0.4661285 

Q:如何在我的例子lapply呢?

回答

1

嘗試

greeks <- lapply(list('Delta', 'Gamma', 'Vega', 'Theta', 'Rho'), 
      function(a) GBSGreeks(Selection = a, 
            TypeFlag='p', 
            S=100.0, X=100.0, 
            Time=1.0, r=0.05, b=0, sigma=0.05))