payoff scripting for Monte Carlo in Quantlib
Posted: May 21st, 2015, 2:48 pm
by ishakh
Hi,Does any one have experience with payoff scripting using the Monte Carlo (MC) engine from an Open Source library such as Quantlib? Here are a few references I've found using Scala and R as scripting languages..
https://hpcquantlib.wordpress.com/2011/ ... deren.pdfI am wondering how viable this technique is to develop prototype code for risk modeling purposes, e.g. VaR/ES, IRC, etc. (for small portfolios)Thanks in advance.
payoff scripting for Monte Carlo in Quantlib
Posted: May 21st, 2015, 11:33 pm
by studenttt
You don't have to do that. There's RQuantLib for you already....
payoff scripting for Monte Carlo in Quantlib
Posted: May 22nd, 2015, 1:10 pm
by ishakh
Thanks. In your experience, what are the limitations of this (e.g. speed, for high quantile calc on portfolios) compared to other scripting tools that yoy may have tested out?
payoff scripting for Monte Carlo in Quantlib
Posted: May 23rd, 2015, 11:22 am
by studenttt
I haven't used other scripting tools. However, the exact language is unimportant, you'll just need to choose your favourite language. R is a very powerful platform for quantitative finance, it lets you do all the crazy stats things for free. R has a larger community than Scala. Having said that, RQuantLib is very limited in what it can do because there was nobody working on it. I'm trying to extend RQuantLib but it'll take time. If you just want to script off Monte-Carlo, RQuantLib is enough for you.
payoff scripting for Monte Carlo in Quantlib
Posted: May 23rd, 2015, 1:50 pm
by studenttt
This is the code in R that I use to script European options from QuantLib. You can do something like that with Monte-Carlo.## Generate random outputs for unit-testing. The script saves outputs into CSV files that can be# parsed by testing code.## Number of test casesN = 10library('RQuantLib')# European Option with the Black-Scholesf <- file("european.csv")o <- c()for (i in 1:N){ c = ifelse(runif(1,min=0,max=1.0) <= 0.5, 'call', 'put') s = runif(1,min=1,max=1000) k = runif(1,min=1,max=1000) r = runif(1,min=0,max=5.0) d = runif(1,min=0,max=5.0) t = runif(1,min=0,max=10.0) v = runif(1,min=0,max=5.0) e <- EuropeanOption(type=c, underlying=s, strike=k, dividendYield=d, riskFreeRate=r, maturity=t, volatility=v) o <- c(o, c(paste('<-Test', toString(i)), toString(c), toString(s), toString(k), toString(r), toString(d), toString(t), toString(v), toString(e$value), toString(e$delta), toString(e$gamma), toString(e$vega), toString(e$theta), toString(e$rho), toString(e$divRho), '\n'))}writeLines(o, f)close(f)
payoff scripting for Monte Carlo in Quantlib
Posted: May 27th, 2015, 4:48 pm
by ishakh
Thanks. I think the RInside package allows payoff scripting (per the second link I'd included) - I will playwith that. I'd think the scripting language is important insofar as the speed (in-memory access) and flexibility (e.g. handling array objects) matter.I found an old thread on payoff scripting too (but no follow up!)
http://quantlib.10058.n7.nabble.com/scr ... d8099.html