0
爲什麼會不斷出現:使用閃亮創建一個期權定價的應用程序,它爲什麼一直顯示「未subsettable類型的對象‘關閉’」
「類型的對象‘關閉’不是subsettable」
library(shiny)
ui<-fluidPage(
numericInput(inputId = "S0",label = "price at time 0",value = 20),
numericInput(inputId = "k",label = "exercise price",value = 20),
numericInput(inputId = "N",label = "steps",value = 50),
numericInput(inputId = "r",label = "riskfree rate",value = 0.03),
numericInput(inputId = "t",label = "time to exercise data",value = 1),
plotOutput(outputId = "v")
)
server<-function(input,output)
{
for(i in 2:246) # 246 days data
zsp$r[i]=log(zsp$ZSP[i]/zsp$ZSP[i-1])
bzc=sd(zsp$r)
sigma=bzc*sqrt(246)#volatility
ve<-reactive({vector(mode="numeric",length=input$N+1)})
u<-reactive({exp(sigma*sqrt(input$t/input$N)) })
d<-reactive({1/u})
p<-reactive({(exp(input$r*input$t/input$N)-d)/(u-d)})
ve<-reactive({rep(input$N,9)})
for(i in 1:51) #origin vector for options at time 1
{
ve[i]<-reactive({max(0,(input$S0*d^(i-1)*u^(input$N-i+1)-input$k))})
}
for(m in 50:1)
{
for(j in 1:m)
{
ve[j]<-reactive({(ve[j]*p+ve[j+1]*(1-p))*exp(-input$r*input$t/input$N)})
}
}
output$v<-renderPlot({plot(ve())})
}
shinyApp(ui=ui,server=server)
由於U&d的reactives用(使用它們)爲使它們時表達式,如分配d&p時的u()&d()。這是我立即注意到的,也許還有一些額外的問題... –
謝謝你的建議,我做了改變,仍然得到錯誤,也許這是循環? – Lee