File: graph.R

package info (click to toggle)
quantlib-swig 1.40-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,276 kB
  • sloc: python: 6,024; java: 1,552; cs: 774; makefile: 309; sh: 22
file content (24 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

suppressMessages(library(QuantLib))

quote <- function(x) { sapply(x, function(x1) {
    todaysDate <- Date(15, "May", 1998)
    Settings_instance()$setEvaluationDate(d=todaysDate)
    settlementDate <- Date(17, "May", 1998)
    riskFreeRate <- FlatForward(settlementDate, 0.05, Actual365Fixed())
    exercise <- EuropeanExercise(Date(17, "May", 1999))
    payoff <- PlainVanillaPayoff("Call", 8.0)
    underlying <- SimpleQuote(x1)
    volatility <- BlackConstantVol(todaysDate, TARGET(), 0.10, Actual365Fixed())
    dividendYield <- FlatForward(settlementDate, 0.05, Actual365Fixed())
    process <- BlackScholesMertonProcess(QuoteHandle(underlying),
                                         YieldTermStructureHandle(dividendYield),
                                         YieldTermStructureHandle(riskFreeRate),
                                         BlackVolTermStructureHandle(volatility))
    option <- VanillaOption(payoff, exercise)
    Instrument_setPricingEngine(option, s_arg2=AnalyticEuropeanEngine(process))
    value <- option$NPV()
    value
})}

curve(quote,xlim=c(1,20))