-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.R
36 lines (34 loc) · 1.14 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(shiny)
library(ggplot2)
source("SABR.R")
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
x <- calculateIV()
print(ggplot(data=x$data, aes(x=Strike, y=IV, colour=Tag))
+ geom_point(size=4)+geom_line(size=1) + theme_grey(base_size=24))
})
calculateIV <- reactive({
forward <- input$forward
maturity <- input$maturity
x <- input$marketData
# convert string(ex:"12,0.346\n15,0.28\n17,0.243...") to data.frame
x <- t(sapply(unlist(strsplit(x, "\n")), function(x) as.numeric(unlist(strsplit(x, ",")))))
strike <- x[,1]
iv.market <- x[,2]
SABR.parameter <- SABR.calibration(maturity, forward, strike, iv.market)
iv.model <- SABR.BSIV(
maturity, forward, strike, SABR.parameter[1], SABR.parameter[2], SABR.parameter[3], SABR.parameter[4])
#
list(
parameter=SABR.parameter,
data=rbind(
data.frame(Strike=strike, IV=iv.model, Tag="SABR"),
data.frame(Strike=strike, IV=iv.market, Tag="Market")
)
)
})
output$summary <- renderPrint({
x <- calculateIV()
print(x$parameter)
})
})