You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(17) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(23) |
| 2002 |
Jan
(18) |
Feb
(20) |
Mar
(22) |
Apr
(41) |
May
(28) |
Jun
(25) |
Jul
(10) |
Aug
(7) |
Sep
(5) |
Oct
(20) |
Nov
(13) |
Dec
(11) |
| 2003 |
Jan
(28) |
Feb
(5) |
Mar
(6) |
Apr
(5) |
May
(17) |
Jun
(6) |
Jul
(45) |
Aug
(35) |
Sep
(24) |
Oct
(50) |
Nov
(53) |
Dec
(6) |
| 2004 |
Jan
(4) |
Feb
(10) |
Mar
(52) |
Apr
(46) |
May
(8) |
Jun
(25) |
Jul
(12) |
Aug
(6) |
Sep
(8) |
Oct
(8) |
Nov
(9) |
Dec
(7) |
| 2005 |
Jan
(18) |
Feb
(60) |
Mar
(19) |
Apr
(26) |
May
(14) |
Jun
(27) |
Jul
(8) |
Aug
(15) |
Sep
(19) |
Oct
(53) |
Nov
(20) |
Dec
(23) |
| 2006 |
Jan
(16) |
Feb
(27) |
Mar
(33) |
Apr
(51) |
May
(36) |
Jun
(25) |
Jul
(54) |
Aug
(30) |
Sep
(25) |
Oct
(67) |
Nov
(43) |
Dec
(13) |
| 2007 |
Jan
(23) |
Feb
(27) |
Mar
(55) |
Apr
(79) |
May
(60) |
Jun
(66) |
Jul
(46) |
Aug
(30) |
Sep
(90) |
Oct
(49) |
Nov
(85) |
Dec
(74) |
| 2008 |
Jan
(68) |
Feb
(59) |
Mar
(64) |
Apr
(28) |
May
(66) |
Jun
(35) |
Jul
(73) |
Aug
(76) |
Sep
(65) |
Oct
(46) |
Nov
(41) |
Dec
(19) |
| 2009 |
Jan
(46) |
Feb
(90) |
Mar
(51) |
Apr
(104) |
May
(13) |
Jun
(24) |
Jul
(20) |
Aug
(39) |
Sep
(109) |
Oct
(101) |
Nov
(117) |
Dec
(57) |
| 2010 |
Jan
(55) |
Feb
(42) |
Mar
(39) |
Apr
(22) |
May
(33) |
Jun
(41) |
Jul
(25) |
Aug
(52) |
Sep
(75) |
Oct
(60) |
Nov
(62) |
Dec
(52) |
| 2011 |
Jan
(70) |
Feb
(31) |
Mar
(26) |
Apr
(28) |
May
(17) |
Jun
(38) |
Jul
(51) |
Aug
(35) |
Sep
(27) |
Oct
(35) |
Nov
(10) |
Dec
(20) |
| 2012 |
Jan
(21) |
Feb
(29) |
Mar
(13) |
Apr
(37) |
May
(33) |
Jun
(12) |
Jul
(34) |
Aug
(27) |
Sep
(29) |
Oct
(35) |
Nov
(58) |
Dec
(27) |
| 2013 |
Jan
(27) |
Feb
(16) |
Mar
(40) |
Apr
(16) |
May
(34) |
Jun
(37) |
Jul
(6) |
Aug
(3) |
Sep
(4) |
Oct
(49) |
Nov
(13) |
Dec
(12) |
| 2014 |
Jan
(15) |
Feb
(21) |
Mar
(11) |
Apr
(13) |
May
(27) |
Jun
(60) |
Jul
(19) |
Aug
(29) |
Sep
(20) |
Oct
(28) |
Nov
(41) |
Dec
(15) |
| 2015 |
Jan
(33) |
Feb
(29) |
Mar
(26) |
Apr
(17) |
May
(2) |
Jun
(13) |
Jul
(21) |
Aug
(30) |
Sep
(22) |
Oct
(15) |
Nov
(46) |
Dec
(20) |
| 2016 |
Jan
(6) |
Feb
(5) |
Mar
(9) |
Apr
(15) |
May
(9) |
Jun
(4) |
Jul
(3) |
Aug
(4) |
Sep
(39) |
Oct
(8) |
Nov
(5) |
Dec
(8) |
| 2017 |
Jan
(4) |
Feb
(14) |
Mar
(4) |
Apr
(16) |
May
(5) |
Jun
(10) |
Jul
(25) |
Aug
(2) |
Sep
(5) |
Oct
(11) |
Nov
(8) |
Dec
(11) |
| 2018 |
Jan
(7) |
Feb
(4) |
Mar
|
Apr
(1) |
May
(4) |
Jun
(21) |
Jul
(8) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(1) |
Dec
|
| 2019 |
Jan
(1) |
Feb
(5) |
Mar
(18) |
Apr
(9) |
May
(5) |
Jun
(21) |
Jul
(25) |
Aug
(25) |
Sep
(4) |
Oct
(2) |
Nov
(2) |
Dec
(5) |
| 2020 |
Jan
|
Feb
|
Mar
(3) |
Apr
|
May
(2) |
Jun
(2) |
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(2) |
Nov
(6) |
Dec
|
| 2021 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
(1) |
May
(4) |
Jun
|
Jul
(1) |
Aug
|
Sep
(2) |
Oct
(9) |
Nov
(1) |
Dec
(5) |
| 2022 |
Jan
(7) |
Feb
(3) |
Mar
|
Apr
(2) |
May
(5) |
Jun
(3) |
Jul
(3) |
Aug
(3) |
Sep
(3) |
Oct
(14) |
Nov
|
Dec
(1) |
| 2023 |
Jan
(10) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
(2) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(5) |
Nov
|
Dec
|
| 2024 |
Jan
(8) |
Feb
|
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(4) |
Aug
(5) |
Sep
|
Oct
(4) |
Nov
(1) |
Dec
(1) |
| 2025 |
Jan
(3) |
Feb
(2) |
Mar
(2) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2026 |
Jan
(1) |
Feb
(12) |
Mar
|
Apr
(2) |
May
(8) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: SourceForge.net <no...@so...> - 2007-12-27 17:25:51
|
Bugs item #1859014, was opened at 2007-12-27 17:25 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112740&aid=1859014&group_id=12740 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: xinc (gigifaye29) Assigned to: Nobody/Anonymous (nobody) Summary: daycounters Initial Comment: Several daycounter functions under \QuantLib-0.8.1\ql\time\daycounters use "swith" without a "break;" under each condition. For example, the following one: Thirty360::implementation(Thirty360::Convention c) { switch (c) { case USA: case BondBasis: return boost::shared_ptr<DayCounter::Impl>(new US_Impl); case European: case EurobondBasis: return boost::shared_ptr<DayCounter::Impl>(new EU_Impl); case Italian: return boost::shared_ptr<DayCounter::Impl>(new IT_Impl); default: QL_FAIL("unknown 30/360 convention"); } } I believe there should be a "break;" ending each case. Otherwise the code actually implements each line till the end(default:...) regardless what 'c' is. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112740&aid=1859014&group_id=12740 |
|
From: Tito I. <tit...@ya...> - 2007-12-27 02:40:05
|
Hi,
I managed to answer my own questions. Instead of calling back into java from c++, I instead pulled the MonteCarloModel into java which ennabled me to implement a pathPricer in java. The cost is a bit high - this impl is something like 3 times slower than the pure c++ version - but it's not so bad that it becomes unusable for my purposes.
Below you'll find a complete working version of the DiscreteHedging implementation in Java. I've also enclosed the modifications I made to the montecarlo.i and options.i SWIG interfaces. Luigi & team could you add to the repository if you find appropriate as others might find them useful? Thanks and regards,
Tito.
Tito Ingargiola <tit...@ya...> wrote:
Hi,
I've been using quantlib through swig in java for several months and,
once past the initial difficulties, it has been working very well.
Up until now, I've only been using the option pricing functionality
but would like to use the monte carlo functionality as well. To get
rolling, I've been looking at the DiscreteHedging example with an eye
towards implementing in java to get used to what's involved.
I've been able to expose and use the relevant bits of BlackCalculator
but am now stuck on the implementation of a PathPricer. My hope is
to implement the logic of the path pricer within java, but this
doesn't seem terribly easy as the path pricer is essentially a
callback which, if exposed through SWIG, would need quantlib to call
into java (or whatever other language). To do this, I believe I'd
have to implement a custom c++ PathPricer which somehow gets a hold
of a reference to a java object which implements the path pricer. I
don't see any examples in QuantLib-SWIG which seem to do a similar
trick which leads me to believe that it is not particularly easy and
that people are thus not using the MC model in any very interesting
way in other languages.
My questions:
- Am I missing something obvious here? Are people really not using
MC from swig?
- Does anyone have an example of a pathpricer or similar
functionality which is called through swig from quantlib?
- Any ideas on how one might design an amendment to quantlib's
existing MC functionality such that it could be more readily
accessed/extended from external languages?
Thanks in advance for any insights or suggestions and best wishes to
all for happy holidays and new year.
Tito.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
QuantLib-dev mailing list
Qua...@li...
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
--- DiscreteHedging.java ---
package examples;
import org.quantlib.Actual365Fixed;
import org.quantlib.BlackCalculator;
import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Calendar;
import org.quantlib.Date;
import org.quantlib.DayCounter;
import org.quantlib.FlatForward;
import org.quantlib.GaussianLowDiscrepancySequenceGenerator;
import org.quantlib.GaussianPathGenerator;
import org.quantlib.GaussianRandomSequenceGenerator;
import org.quantlib.GaussianSobolPathGenerator;
import org.quantlib.Option;
import org.quantlib.Path;
import org.quantlib.PlainVanillaPayoff;
import org.quantlib.QuoteHandle;
import org.quantlib.SamplePath;
import org.quantlib.SimpleQuote;
import org.quantlib.Statistics;
import org.quantlib.TARGET;
import org.quantlib.UniformLowDiscrepancySequenceGenerator;
import org.quantlib.UniformRandomGenerator;
import org.quantlib.UniformRandomSequenceGenerator;
import org.quantlib.YieldTermStructureHandle;
/**
* DiscreteHedging Test app - java version of QuantLib/Examples/DiscreteHedging
* to illustrate use of Quantlib's MonteCarlo functionality through supplied
* SWIG interfaces.
*
* You need to run this with a correctly set library path and something like:
*
* -Djava.library.path=/usr/local/lib
*
* @author Tito Ingargiola
**/
public class DiscreteHedging {
static { // Load QuantLib
try { System.loadLibrary("QuantLibJNI"); }
catch (RuntimeException e) { e.printStackTrace(); }
}
public static void main(String[] args) throws Exception {
long begin = System.currentTimeMillis();
double maturity = 1.0/12.0; // 1 month
double strike = 100;
double underlying = 100;
double volatility = 0.20; // 20%
double riskFreeRate = 0.05; // 5%
ReplicationError rp = new ReplicationError(Option.Type.Call, maturity,
strike, underlying, volatility, riskFreeRate);
long scenarios = 50000;
long hedgesNum = 21;
rp.compute(hedgesNum, scenarios);
hedgesNum = 84;
rp.compute(hedgesNum, scenarios);
long msecs = (System.currentTimeMillis()-begin);
System.out.println("\nRun completed in "+msecs+" ms.");
}
/**
* The ReplicationError class carries out Monte Carlo simulations to
* evaluate the outcome (the replication error) of the discrete hedging
* strategy over different, randomly generated scenarios of future stock
* price evolution.
**/
public static class ReplicationError {
public ReplicationError(Option.Type type, double maturity,
double strike, double s0, double sigma, double r ) {
type_ = type;
maturity_ = maturity;
strike_ = strike;
s0_ = s0;
sigma_ = sigma;
r_ = r;
// value of the option
double rDiscount = Math.exp(-r_ * maturity_);
double qDiscount = 1.0;
double forward = s0_ * qDiscount/rDiscount;
double stdDev = Math.sqrt(sigma_*sigma_*maturity);
BlackCalculator black = new BlackCalculator
(new PlainVanillaPayoff(type,strike),forward,stdDev,rDiscount);
System.out.printf("Option value: %2.5f \n\n",black.value());
// store option's vega, since Derman and Kamal's formula needs it
vega_ = black.vega(maturity_);
String fmt ="%-8s | %-8s | %-8s | %-8s | %-12s | %-8s | %-8s \n";
System.out.printf
(fmt, " ", " ", "P&L", "P&L", "Derman&Kamal", "P&L","P&L" );
System.out.printf(fmt, " samples", "trades", "mean", "std.dev",
"formula", "skewness","kurtosis" );
for (int i = 0; i < 78; i++) System.out.print("-");
System.out.println("-");
}
void compute(long nTimeSteps, long nSamples) {
assert nTimeSteps>0 : "the number of steps must be > 0";
/* Black-Scholes framework: the underlying stock price evolves
lognormally with a fixed known volatility that stays constant
throughout time. */
Calendar calendar = new TARGET();
Date today = Date.todaysDate();
DayCounter dayCounter = new Actual365Fixed();
QuoteHandle stateVariable = new QuoteHandle(new SimpleQuote(s0_));
YieldTermStructureHandle riskFreeRate =
new YieldTermStructureHandle
(new FlatForward(today, r_, dayCounter));
YieldTermStructureHandle dividendYield =
new YieldTermStructureHandle
(new FlatForward(today, 0.0, dayCounter));
BlackVolTermStructureHandle volatility =
new BlackVolTermStructureHandle(
new BlackConstantVol(today, calendar, sigma_, dayCounter));
BlackScholesMertonProcess diffusion =
new BlackScholesMertonProcess
(stateVariable,dividendYield, riskFreeRate, volatility);
// Black Scholes equation rules the path generator:
// at each step the log of the stock
// will have drift and sigma^2 variance
boolean brownianBridge = false;
GaussianRandomSequenceGenerator rsg =
new GaussianRandomSequenceGenerator
(new UniformRandomSequenceGenerator
(nTimeSteps,new UniformRandomGenerator(0)));
GaussianPathGenerator myPathGenerator =
new GaussianPathGenerator
(diffusion,maturity_,nTimeSteps,rsg, brownianBridge);
/* Alternately you can modify the MonteCarloModel to take a
* GaussianSobolPathGenerator and uncomment these lines and
* comment those just above
*
GaussianLowDiscrepancySequenceGenerator rsg =
new GaussianLowDiscrepancySequenceGenerator
(new UniformLowDiscrepancySequenceGenerator
(nTimeSteps));
GaussianSobolPathGenerator myPathGenerator =
new GaussianSobolPathGenerator
(diffusion,maturity_,nTimeSteps,rsg, brownianBridge);*/
ReplicationPathPricer myPathPricer = new ReplicationPathPricer
(type_,strike_, r_, maturity_, sigma_);
MonteCarloModel mcSimulation = new MonteCarloModel
(myPathGenerator, myPathPricer);
mcSimulation.addSamples(nSamples);
// the sampleAccumulator method
// gives access to all the methods of statisticsAccumulator
double PLMean = mcSimulation.sampleAccumulator().mean();
double PLStDev =
mcSimulation.sampleAccumulator().standardDeviation();
double PLSkew = mcSimulation.sampleAccumulator().skewness();
double PLKurt = mcSimulation.sampleAccumulator().kurtosis();
// Derman and Kamal's formula
double theorStD = Math.sqrt(Math.PI/4/nTimeSteps)*vega_*sigma_;
String fmt =
"%-8d | %-8d | %-8.3f | %-8.2f | %-12.2f | %-8.2f | %-8.2f \n";
System.out.printf(fmt, nSamples, nTimeSteps, PLMean, PLStDev,
theorStD, PLSkew, PLKurt );
}
double maturity_;
Option.Type type_;
double strike_;
double s0_;
double sigma_;
double r_;
double vega_;
}
/**
* We pull the interface for a PathPricer into Java so we can
* support its implementation in Java while still relying upon QuantLib's
* powerful RNGs.
*/
public static interface JPathPricer {
public double price(Path path);
}
// The key for the MonteCarlo simulation is to have a PathPricer that
// implements a value(const Path& path) method.
// This method prices the portfolio for each Path of the random variable
public static class ReplicationPathPricer implements JPathPricer {
public ReplicationPathPricer(Option.Type type, double strike,
double r, double maturity, double sigma) {
assert strike > 0 : "Strike must be positive!";
assert maturity > 0 : "Risk free rate must be positive!";
assert r >= 0 : "Risk free rate must be positive or Zero!";
assert sigma >= 0 : "Volatility must be positive or Zero!";
type_ = type;
strike_ = strike;
r_ = r;
maturity_ = maturity;
sigma_ = sigma;
}
public double price(Path path) {
long n = path.length() - 1;
assert n > 0 : "The path can't be empty!";
// discrete hedging interval
double dt = maturity_ / ((double)n);
// For simplicity, we assume the stock pays no dividends.
double stockDividendYield = 0.0;
// let's start
double t = 0;
// stock value at t=0
double stock = path.front();
// money account at t=0
double money_account = 0.0;
/************************/
/*** the initial deal ***/
/************************/
// option fair price (Black-Scholes) at t=0
double rDiscount = Math.exp(-r_*maturity_);
double qDiscount = Math.exp(-stockDividendYield*maturity_);
double forward = stock*qDiscount/rDiscount;
double stdDev = Math.sqrt(sigma_*sigma_*maturity_);
PlainVanillaPayoff payoff = new PlainVanillaPayoff(type_,strike_);
BlackCalculator black = new BlackCalculator
(payoff,forward,stdDev,rDiscount);
// sell the option, cash in its premium
money_account += black.value();
// compute delta
double delta = black.delta(stock);
// delta-hedge the option buying stock
double stockAmount = delta;
money_account -= stockAmount*stock;
/**********************************/
/*** hedging during option life ***/
/**********************************/
for (long step = 0; step < n-1; step++){
// time flows
t += dt;
// accruing on the money account
money_account *= Math.exp( r_*dt );
// stock growth:
stock = path.value(step+1);
// recalculate option value at the current stock value,
// and the current time to maturity
rDiscount = Math.exp(-r_*(maturity_-t));
qDiscount = Math.exp(-stockDividendYield*(maturity_-t));
forward = stock*(qDiscount/rDiscount);
stdDev = Math.sqrt(sigma_*sigma_*(maturity_-t));
black = new BlackCalculator
(new PlainVanillaPayoff(type_,strike_),forward,stdDev,rDiscount);
// recalculate delta
delta = black.delta(stock);
// re-hedging
money_account -= (delta - stockAmount)*stock;
stockAmount = delta;
}
/*************************/
/*** option expiration ***/
/*************************/
// last accrual on my money account
money_account *= Math.exp( r_*dt );
// last stock growth
stock = path.value(n);
// the hedger delivers the option payoff to the option holder
double optionPayoff =
(new PlainVanillaPayoff(type_, strike_)).getValue(stock);
money_account -= optionPayoff;
// and unwinds the hedge selling his stock position
money_account += stockAmount*stock;
// final Profit&Loss
return money_account;
}
double maturity_;
Option.Type type_;
double strike_;
double sigma_;
double r_;
}
/**
* We pull the MonteCarloModel into Java so that we can enable the
* implementation in java of our PathPricer
*/
public static class MonteCarloModel {
/** convenience ctor **/
public MonteCarloModel
(GaussianPathGenerator gpg, JPathPricer pathpricer) {
this(gpg,pathpricer,false, null);
}
/** complete ctor **/
public MonteCarloModel(GaussianPathGenerator gpg,
JPathPricer pathpricer, boolean antitheticVariate,
Statistics stats ) {
assert gpg != null : "PathGenerator must not be null!";
assert pathpricer != null : "PathPricer must not be null!";
gpg_ = gpg;
ppricer_ = pathpricer;
stats_ = (stats==null) ? new Statistics() : stats;
av_ = antitheticVariate;
}
public Statistics sampleAccumulator () { return stats_; }
public void addSamples( long samples ) {
for(long j = 0; j < samples; j++) {
SamplePath path = gpg_.next();
double price = ppricer_.price(path.value());
if ( av_ ) {
path = gpg_.antithetic();
double price2 = ppricer_.price(path.value());
stats_.add((price+price2)/2.0, path.weight());
} else {
stats_.add(price, path.weight());
}
}
}
final boolean av_;
final GaussianPathGenerator gpg_;
final JPathPricer ppricer_;
final Statistics stats_;
}
}
----- options.i ----
/*
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
Copyright (C) 2005 Dominic Thuillier
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<qua...@li...>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#ifndef quantlib_options_i
#define quantlib_options_i
%include common.i
%include exercise.i
%include stochasticprocess.i
%include instruments.i
%include stl.i
%include linearalgebra.i
// option and barrier types
%{
using QuantLib::Option;
using QuantLib::Barrier;
%}
// declared out of its hierarchy just to export the inner enumeration
class Option {
public:
enum Type { Put = -1, Call = 1};
private:
Option();
};
struct Barrier {
enum Type { DownIn, UpIn, DownOut, UpOut };
};
// payoff
%{
using QuantLib::Payoff;
using QuantLib::StrikedTypePayoff;
%}
%ignore Payoff;
class Payoff {
#if defined(SWIGMZSCHEME) || defined(SWIGGUILE) \
|| defined(SWIGCSHARP) || defined(SWIGPERL)
%rename(call) operator();
#endif
public:
Real operator()(Real price) const;
};
%template(Payoff) boost::shared_ptr<Payoff>;
#if defined(SWIGR)
%Rruntime %{
setMethod("summary", "_p_VanillaOptionPtr",
function(object) {object$freeze()
ans <- c(value=object$NPV(), delta=object$delta(),
gamma=object$gamma(), vega=object$vega(),
theta=object$theta(), rho=object$rho(),
divRho=object$dividendRho())
object$unfreeze()
ans
})
setMethod("summary", "_p_DividendVanillaOptionPtr",
function(object) {object$freeze()
ans <- c(value=object$NPV(), delta=object$delta(),
gamma=object$gamma(), vega=object$vega(),
theta=object$theta(), rho=object$rho(),
divRho=object$dividendRho())
object$unfreeze()
ans
})
%}
#endif
// plain option and engines
%{
using QuantLib::VanillaOption;
using QuantLib::ForwardVanillaOption;
using QuantLib::BlackCalculator;
typedef boost::shared_ptr<Instrument> VanillaOptionPtr;
typedef boost::shared_ptr<Instrument> MultiAssetOptionPtr;
%}
%rename(VanillaOption) VanillaOptionPtr;
class VanillaOptionPtr : public boost::shared_ptr<Instrument> {
#if defined(SWIGMZSCHEME) || defined(SWIGGUILE)
%rename("dividend-rho") dividendRho;
%rename("implied-volatility") impliedVolatility;
#endif
public:
%extend {
VanillaOptionPtr(
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new VanillaOptionPtr(new VanillaOption(stPayoff,exercise));
}
Real delta() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)->delta();
}
Real gamma() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)->gamma();
}
Real theta() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)->theta();
}
Real thetaPerDay() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)
->thetaPerDay();
}
Real vega() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)->vega();
}
Real rho() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)->rho();
}
Real dividendRho() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)
->dividendRho();
}
Real strikeSensitivity() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)
->strikeSensitivity();
}
SampledCurve priceCurve() {
return boost::dynamic_pointer_cast<VanillaOption>(*self)
->result<SampledCurve>("priceCurve");
}
Volatility impliedVolatility(
Real targetValue,
const GeneralizedBlackScholesProcessPtr& process,
Real accuracy = 1.0e-4,
Size maxEvaluations = 100,
Volatility minVol = 1.0e-4,
Volatility maxVol = 4.0) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return boost::dynamic_pointer_cast<VanillaOption>(*self)
->impliedVolatility(targetValue, bsProcess, accuracy,
maxEvaluations, minVol, maxVol);
}
}
};
%{
using QuantLib::EuropeanOption;
typedef boost::shared_ptr<Instrument> EuropeanOptionPtr;
%}
%rename(EuropeanOption) EuropeanOptionPtr;
class EuropeanOptionPtr : public VanillaOptionPtr {
public:
%extend {
EuropeanOptionPtr(
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new EuropeanOptionPtr(new EuropeanOption(stPayoff,exercise));
}
}
};
// ForwardVanillaOption
%{
using QuantLib::ForwardVanillaOption;
typedef boost::shared_ptr<Instrument> ForwardVanillaOptionPtr;
%}
%rename(ForwardVanillaOption) ForwardVanillaOptionPtr;
class ForwardVanillaOptionPtr : public VanillaOptionPtr {
public:
%extend {
ForwardVanillaOptionPtr(
Real moneyness,
Date resetDate,
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new ForwardVanillaOptionPtr(
new ForwardVanillaOption(moneyness, resetDate,
stPayoff, exercise));
}
}
};
// QuantoVanillaOption
%{
using QuantLib::QuantoVanillaOption;
typedef boost::shared_ptr<Instrument> QuantoVanillaOptionPtr;
%}
%rename(QuantoVanillaOption) QuantoVanillaOptionPtr;
class QuantoVanillaOptionPtr : public VanillaOptionPtr {
public:
%extend {
QuantoVanillaOptionPtr(
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new QuantoVanillaOptionPtr(
new QuantoVanillaOption(stPayoff, exercise));
}
Real qvega() {
return boost::dynamic_pointer_cast<QuantoVanillaOption>(*self)
->qvega();
}
Real qrho() {
return boost::dynamic_pointer_cast<QuantoVanillaOption>(*self)
->qrho();
}
Real qlambda() {
return boost::dynamic_pointer_cast<QuantoVanillaOption>(*self)
->qlambda();
}
}
};
%{
using QuantLib::QuantoForwardVanillaOption;
typedef boost::shared_ptr<Instrument> QuantoForwardVanillaOptionPtr;
%}
%rename(QuantoForwardVanillaOption) QuantoForwardVanillaOptionPtr;
class QuantoForwardVanillaOptionPtr : public QuantoVanillaOptionPtr {
public:
%extend {
QuantoForwardVanillaOptionPtr(
Real moneyness,
Date resetDate,
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new QuantoForwardVanillaOptionPtr(
new QuantoForwardVanillaOption(moneyness, resetDate,
stPayoff, exercise));
}
}
};
%{
using QuantLib::MultiAssetOption;
%}
%rename(MultiAssetOption) MultiAssetOptionPtr;
class MultiAssetOptionPtr : public boost::shared_ptr<Instrument> {
public:
%extend {
Real delta() {
return boost::dynamic_pointer_cast<MultiAssetOption>(*self)
->delta();
}
Real gamma() {
return boost::dynamic_pointer_cast<MultiAssetOption>(*self)
->gamma();
}
Real theta() {
return boost::dynamic_pointer_cast<MultiAssetOption>(*self)
->theta();
}
Real vega() {
return boost::dynamic_pointer_cast<MultiAssetOption>(*self)->vega();
}
Real rho() {
return boost::dynamic_pointer_cast<MultiAssetOption>(*self)->rho();
}
Real dividendRho() {
return boost::dynamic_pointer_cast<MultiAssetOption>(*self)
->dividendRho();
}
}
};
// European engines
%{
using QuantLib::AnalyticEuropeanEngine;
typedef boost::shared_ptr<PricingEngine> AnalyticEuropeanEnginePtr;
%}
%rename(AnalyticEuropeanEngine) AnalyticEuropeanEnginePtr;
class AnalyticEuropeanEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
AnalyticEuropeanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new AnalyticEuropeanEnginePtr(
new AnalyticEuropeanEngine(bsProcess));
}
}
};
%{
using QuantLib::IntegralEngine;
typedef boost::shared_ptr<PricingEngine> IntegralEnginePtr;
%}
%rename(IntegralEngine) IntegralEnginePtr;
class IntegralEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
IntegralEnginePtr(const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new IntegralEnginePtr(new IntegralEngine(bsProcess));
}
}
};
%{
using QuantLib::FDBermudanEngine;
typedef boost::shared_ptr<PricingEngine> FDBermudanEnginePtr;
%}
%rename(FDBermudanEngine) FDBermudanEnginePtr;
class FDBermudanEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
FDBermudanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
Size timeSteps = 100, Size gridPoints = 100,
bool timeDependent = false) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new FDBermudanEnginePtr(
new FDBermudanEngine(bsProcess,timeSteps,
gridPoints,timeDependent));
}
}
};
%{
using QuantLib::FDEuropeanEngine;
typedef boost::shared_ptr<PricingEngine> FDEuropeanEnginePtr;
%}
%rename(FDEuropeanEngine) FDEuropeanEnginePtr;
class FDEuropeanEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
FDEuropeanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
Size timeSteps = 100, Size gridPoints = 100,
bool timeDependent = false) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new FDEuropeanEnginePtr(
new FDEuropeanEngine(bsProcess,timeSteps,
gridPoints,timeDependent));
}
}
};
%{
using QuantLib::BinomialVanillaEngine;
using QuantLib::CoxRossRubinstein;
using QuantLib::JarrowRudd;
using QuantLib::AdditiveEQPBinomialTree;
using QuantLib::Trigeorgis;
using QuantLib::Tian;
using QuantLib::LeisenReimer;
using QuantLib::Joshi4;
typedef boost::shared_ptr<PricingEngine> BinomialVanillaEnginePtr;
%}
%rename(BinomialVanillaEngine) BinomialVanillaEnginePtr;
class BinomialVanillaEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
BinomialVanillaEnginePtr(
const GeneralizedBlackScholesProcessPtr& process,
const std::string& type,
Size steps) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
std::string s = boost::algorithm::to_lower_copy(type);
if (s == "crr" || s == "coxrossrubinstein")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<CoxRossRubinstein>(
bsProcess,steps));
else if (s == "jr" || s == "jarrowrudd")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<JarrowRudd>(bsProcess,steps));
else if (s == "eqp" || s == "additiveeqpbinomialtree")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<AdditiveEQPBinomialTree>(
bsProcess,steps));
else if (s == "trigeorgis")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<Trigeorgis>(bsProcess,steps));
else if (s == "tian")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<Tian>(bsProcess,steps));
else if (s == "lr" || s == "leisenreimer")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<LeisenReimer>(bsProcess,steps));
else if (s == "j4" || s == "joshi4")
return new BinomialVanillaEnginePtr(
new BinomialVanillaEngine<Joshi4>(bsProcess,steps));
else
QL_FAIL("unknown binomial engine type: "+s);
}
}
};
%{
using QuantLib::MCEuropeanEngine;
using QuantLib::PseudoRandom;
using QuantLib::LowDiscrepancy;
typedef boost::shared_ptr<PricingEngine> MCEuropeanEnginePtr;
%}
%rename(MCEuropeanEngine) MCEuropeanEnginePtr;
class MCEuropeanEnginePtr : public boost::shared_ptr<PricingEngine> {
%feature("kwargs") MCEuropeanEnginePtr;
public:
%extend {
MCEuropeanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
const std::string& traits,
intOrNull timeSteps = Null<Size>(),
intOrNull timeStepsPerYear = Null<Size>(),
bool brownianBridge = false,
bool antitheticVariate = false,
bool controlVariate = false,
intOrNull requiredSamples = Null<Size>(),
doubleOrNull requiredTolerance = Null<Real>(),
intOrNull maxSamples = Null<Size>(),
BigInteger seed = 0) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
std::string s = boost::algorithm::to_lower_copy(traits);
QL_REQUIRE(Size(timeSteps) != Null<Size>() ||
Size(timeStepsPerYear) != Null<Size>(),
"number of steps not specified");
if (s == "pseudorandom" || s == "pr")
return new MCEuropeanEnginePtr(
new MCEuropeanEngine<PseudoRandom>(bsProcess,
timeSteps,
timeStepsPerYear,
brownianBridge,
antitheticVariate,
controlVariate,
requiredSamples,
requiredTolerance,
maxSamples,
seed));
else if (s == "lowdiscrepancy" || s == "ld")
return new MCEuropeanEnginePtr(
new MCEuropeanEngine<LowDiscrepancy>(bsProcess,
timeSteps,
timeStepsPerYear,
brownianBridge,
antitheticVariate,
controlVariate,
requiredSamples,
requiredTolerance,
maxSamples,
seed));
else
QL_FAIL("unknown Monte Carlo engine type: "+s);
}
}
};
// American engines
%{
using QuantLib::FDAmericanEngine;
using QuantLib::FDShoutEngine;
typedef boost::shared_ptr<PricingEngine> FDAmericanEnginePtr;
typedef boost::shared_ptr<PricingEngine> FDShoutEnginePtr;
%}
%rename(FDAmericanEngine) FDAmericanEnginePtr;
class FDAmericanEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
FDAmericanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
Size timeSteps = 100, Size gridPoints = 100,
bool timeDependent = false) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new FDAmericanEnginePtr(
new FDAmericanEngine(bsProcess,timeSteps,
gridPoints,timeDependent));
}
}
};
%rename(FDShoutEngine) FDShoutEnginePtr;
class FDShoutEnginePtr : public boost::shared_ptr<PricingEngine> {
public:
%extend {
FDShoutEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
Size timeSteps = 100, Size gridPoints = 100,
bool timeDependent = false) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new FDShoutEnginePtr(
new FDShoutEngine(bsProcess,timeSteps,
gridPoints,timeDependent));
}
}
};
%{
using QuantLib::BaroneAdesiWhaleyApproximationEngine;
typedef boost::shared_ptr<PricingEngine>
BaroneAdesiWhaleyApproximationEnginePtr;
%}
%rename(BaroneAdesiWhaleyEngine) BaroneAdesiWhaleyApproximationEnginePtr;
class BaroneAdesiWhaleyApproximationEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
BaroneAdesiWhaleyApproximationEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new BaroneAdesiWhaleyApproximationEnginePtr(
new BaroneAdesiWhaleyApproximationEngine(bsProcess));
}
}
};
%{
using QuantLib::BjerksundStenslandApproximationEngine;
typedef boost::shared_ptr<PricingEngine>
BjerksundStenslandApproximationEnginePtr;
%}
%rename(BjerksundStenslandEngine) BjerksundStenslandApproximationEnginePtr;
class BjerksundStenslandApproximationEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
BjerksundStenslandApproximationEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new BjerksundStenslandApproximationEnginePtr(
new BjerksundStenslandApproximationEngine(bsProcess));
}
}
};
%{
using QuantLib::AnalyticDigitalAmericanEngine;
typedef boost::shared_ptr<PricingEngine> AnalyticDigitalAmericanEnginePtr;
%}
%rename(AnalyticDigitalAmericanEngine) AnalyticDigitalAmericanEnginePtr;
class AnalyticDigitalAmericanEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
AnalyticDigitalAmericanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new AnalyticDigitalAmericanEnginePtr(
new AnalyticDigitalAmericanEngine(bsProcess));
}
}
};
// Dividend option
%{
using QuantLib::DividendVanillaOption;
typedef boost::shared_ptr<Instrument> DividendVanillaOptionPtr;
%}
%rename(DividendVanillaOption) DividendVanillaOptionPtr;
class DividendVanillaOptionPtr : public boost::shared_ptr<Instrument> {
#if defined(SWIGMZSCHEME) || defined(SWIGGUILE)
%rename("dividend-rho") dividendRho;
%rename("implied-volatility") impliedVolatility;
#endif
public:
%extend {
DividendVanillaOptionPtr(
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise,
const std::vector<Date>& dividendDates,
const std::vector<Real>& dividends) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new DividendVanillaOptionPtr(
new DividendVanillaOption(stPayoff,exercise,
dividendDates,dividends));
}
Real delta() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->delta();
}
Real gamma() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->gamma();
}
Real theta() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->theta();
}
Real vega() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->vega();
}
Real rho() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->rho();
}
Real dividendRho() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->dividendRho();
}
Real strikeSensitivity() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->strikeSensitivity();
}
SampledCurve priceCurve() {
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->result<SampledCurve>("priceCurve");
}
Volatility impliedVolatility(
Real targetValue,
const GeneralizedBlackScholesProcessPtr& process,
Real accuracy = 1.0e-4,
Size maxEvaluations = 100,
Volatility minVol = 1.0e-4,
Volatility maxVol = 4.0) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
->impliedVolatility(targetValue, bsProcess, accuracy,
maxEvaluations, minVol, maxVol);
}
}
};
%{
using QuantLib::AnalyticDividendEuropeanEngine;
typedef boost::shared_ptr<PricingEngine> AnalyticDividendEuropeanEnginePtr;
%}
%rename(AnalyticDividendEuropeanEngine) AnalyticDividendEuropeanEnginePtr;
class AnalyticDividendEuropeanEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
AnalyticDividendEuropeanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new AnalyticDividendEuropeanEnginePtr(
new AnalyticDividendEuropeanEngine(bsProcess));
}
}
};
%{
using QuantLib::FDDividendEuropeanEngine;
using QuantLib::FDDividendAmericanEngine;
typedef boost::shared_ptr<PricingEngine> FDDividendEuropeanEnginePtr;
typedef boost::shared_ptr<PricingEngine> FDDividendAmericanEnginePtr;
%}
%rename(FDDividendEuropeanEngine) FDDividendEuropeanEnginePtr;
class FDDividendEuropeanEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
FDDividendEuropeanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process,
Size timeSteps = 100,
Size gridPoints = 100,
bool timeDependent = false) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new FDDividendEuropeanEnginePtr(
new FDDividendEuropeanEngine(bsProcess,timeSteps,
gridPoints, timeDependent));
}
}
};
%rename(FDDividendAmericanEngine) FDDividendAmericanEnginePtr;
class FDDividendAmericanEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
FDDividendAmericanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process,
Size timeSteps = 100,
Size gridPoints = 100,
bool timeDependent = false) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new FDDividendAmericanEnginePtr(
new FDDividendAmericanEngine(bsProcess,timeSteps,
gridPoints, timeDependent));
}
}
};
// Barrier option
%{
using QuantLib::BarrierOption;
typedef boost::shared_ptr<Instrument> BarrierOptionPtr;
%}
%rename(BarrierOption) BarrierOptionPtr;
class BarrierOptionPtr : public boost::shared_ptr<Instrument> {
#if defined(SWIGMZSCHEME) || defined(SWIGGUILE)
%rename("dividend-rho") dividendRho;
%rename("implied-volatility") impliedVolatility;
#endif
public:
%extend {
BarrierOptionPtr(
Barrier::Type barrierType,
Real barrier,
Real rebate,
const boost::shared_ptr<Payoff>& payoff,
const boost::shared_ptr<Exercise>& exercise) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new BarrierOptionPtr(
new BarrierOption(barrierType, barrier, rebate,
stPayoff,exercise));
}
Real delta() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)->delta();
}
Real gamma() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)->gamma();
}
Real theta() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)->theta();
}
Real vega() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)->vega();
}
Real rho() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)->rho();
}
Real dividendRho() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)
->dividendRho();
}
Real strikeSensitivity() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)
->strikeSensitivity();
}
SampledCurve priceCurve() {
return boost::dynamic_pointer_cast<BarrierOption>(*self)
->result<SampledCurve>("priceCurve");
}
Volatility impliedVolatility(
Real targetValue,
const GeneralizedBlackScholesProcessPtr& process,
Real accuracy = 1.0e-4,
Size maxEvaluations = 100,
Volatility minVol = 1.0e-4,
Volatility maxVol = 4.0) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return boost::dynamic_pointer_cast<BarrierOption>(*self)
->impliedVolatility(targetValue, bsProcess, accuracy,
maxEvaluations, minVol, maxVol);
}
}
};
// Barrier engines
%{
using QuantLib::AnalyticBarrierEngine;
typedef boost::shared_ptr<PricingEngine> AnalyticBarrierEnginePtr;
%}
%rename(AnalyticBarrierEngine) AnalyticBarrierEnginePtr;
class AnalyticBarrierEnginePtr
: public boost::shared_ptr<PricingEngine> {
public:
%extend {
AnalyticBarrierEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new AnalyticBarrierEnginePtr(
new AnalyticBarrierEngine(bsProcess));
}
}
};
%{
using QuantLib::MCBarrierEngine;
typedef boost::shared_ptr<PricingEngine> MCBarrierEnginePtr;
%}
%rename(MCBarrierEngine) MCBarrierEnginePtr;
class MCBarrierEnginePtr : public boost::shared_ptr<PricingEngine> {
%feature("kwargs") MCBarrierEnginePtr;
public:
%extend {
MCBarrierEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
const std::string& traits,
Size timeStepsPerYear = Null<Size>(),
bool brownianBridge = false,
bool antitheticVariate = false,
bool controlVariate = false,
intOrNull requiredSamples = Null<Size>(),
doubleOrNull requiredTolerance = Null<Real>(),
intOrNull maxSamples = Null<Size>(),
bool isBiased = false,
BigInteger seed = 0) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
std::string s = boost::algorithm::to_lower_copy(traits);
if (s == "pseudorandom" || s == "pr")
return new MCBarrierEnginePtr(
new MCBarrierEngine<PseudoRandom>(bsProcess,
timeStepsPerYear,
brownianBridge,
antitheticVariate,
controlVariate,
requiredSamples,
requiredTolerance,
maxSamples,
isBiased,
seed));
else if (s == "lowdiscrepancy" || s == "ld")
return new MCBarrierEnginePtr(
new MCBarrierEngine<LowDiscrepancy>(bsProcess,
timeStepsPerYear,
brownianBridge,
antitheticVariate,
controlVariate,
requiredSamples,
requiredTolerance,
maxSamples,
isBiased,
seed));
else
QL_FAIL("unknown Monte Carlo engine type: "+s);
}
}
};
%{
using QuantLib::QuantoEngine;
using QuantLib::ForwardVanillaEngine;
typedef boost::shared_ptr<PricingEngine> ForwardEuropeanEnginePtr;
typedef boost::shared_ptr<PricingEngine> QuantoEuropeanEnginePtr;
typedef boost::shared_ptr<PricingEngine> QuantoForwardEuropeanEnginePtr;
%}
%rename(ForwardEuropeanEngine) ForwardEuropeanEnginePtr;
class ForwardEuropeanEnginePtr: public boost::shared_ptr<PricingEngine> {
public:
%extend {
ForwardEuropeanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new ForwardEuropeanEnginePtr(
new ForwardVanillaEngine<AnalyticEuropeanEngine>(bsProcess));
}
}
};
%rename(QuantoEuropeanEngine) QuantoEuropeanEnginePtr;
class QuantoEuropeanEnginePtr: public boost::shared_ptr<PricingEngine> {
public:
%extend {
QuantoEuropeanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process,
const Handle<YieldTermStructure>& foreignRiskFreeRate,
const Handle<BlackVolTermStructure>& exchangeRateVolatility,
const Handle<Quote>& correlation) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new QuantoEuropeanEnginePtr(
new QuantoEngine<VanillaOption,AnalyticEuropeanEngine>(
bsProcess,
foreignRiskFreeRate,
exchangeRateVolatility,
correlation));
}
}
};
%rename(QuantoForwardEuropeanEngine) QuantoForwardEuropeanEnginePtr;
class QuantoForwardEuropeanEnginePtr: public boost::shared_ptr<PricingEngine> {
public:
%extend {
QuantoForwardEuropeanEnginePtr(
const GeneralizedBlackScholesProcessPtr& process,
const Handle<YieldTermStructure>& foreignRiskFreeRate,
const Handle<BlackVolTermStructure>& exchangeRateVolatility,
const Handle<Quote>& correlation) {
boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
process);
QL_REQUIRE(bsProcess, "Black-Scholes process required");
return new QuantoForwardEuropeanEnginePtr(
new QuantoEngine<ForwardVanillaOption,AnalyticEuropeanEngine>(
bsProcess,
foreignRiskFreeRate,
exchangeRateVolatility,
correlation));
}
}
};
%{
using QuantLib::BlackCalculator;
%}
class BlackCalculator {
public:
Real value() const;
Real deltaForward() const;
virtual Real delta(Real spot) const;
Real elasticityForward() const;
virtual Real elasticity(Real spot) const;
Real gammaForward() const;
virtual Real gamma(Real spot) const;
virtual Real theta(Real spot, Time maturity) const;
virtual Real thetaPerDay(Real spot, Time maturity) const;
Real vega(Time maturity) const;
Real rho(Time maturity) const;
Real dividendRho(Time maturity) const;
Real itmCashProbability() const;
Real itmAssetProbability() const;
Real strikeSensitivity() const;
Real alpha() const;
Real beta() const;
%extend {
BlackCalculator (
const boost::shared_ptr<Payoff>& payoff,
Real forward,
Real stdDev,
Real discount = 1.0) {
boost::shared_ptr<StrikedTypePayoff> stPayoff =
boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
QL_REQUIRE(stPayoff, "wrong payoff given");
return new BlackCalculator(stPayoff,forward,stdDev,discount);
}
}
};
#endif
---- montecarlo.i ----
/*
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<qua...@li...>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#ifndef quantlib_montecarlo_tools_i
#define quantlib_montecarlo_tools_i
%include stochasticprocess.i
%include linearalgebra.i
%include randomnumbers.i
%include types.i
#if defined(SWIGMZSCHEME) || defined(SWIGGUILE)
%rename("get-covariance") getCovariance;
#endif
%inline %{
Matrix getCovariance(const Array& volatilities, const Matrix& correlations) {
return QuantLib::getCovariance(volatilities.begin(),
volatilities.end(),
correlations);
}
%}
%{
using QuantLib::Path;
%}
#if defined(SWIGRUBY)
%mixin Path "Enumerable";
#endif
class Path {
#if defined(SWIGPYTHON) || defined(SWIGRUBY)
%rename(__len__) length;
#endif
private:
Path();
public:
Size length() const;
Real value(Size i) const;
Real front() const;
Time time(Size i) const;
%extend {
#if defined(SWIGPYTHON) |...
[truncated message content] |
|
From: SourceForge.net <no...@so...> - 2007-12-24 14:14:32
|
Bugs item #1857551, was opened at 2007-12-24 06:12 Message generated for change (Comment added) made by nobody You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112740&aid=1857551&group_id=12740 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: quantlib 0.9.0 PiecewiseYieldCurveTest problem Initial Comment: Error 1 fatal error in "PiecewiseYieldCurveTest::testLogLinearDiscountConsistency": std::exception: negative time (-0.00277778) given unknown location Error 2 fatal error in "PiecewiseYieldCurveTest::testLinearDiscountConsistency": std::exception: negative time (-0.00277778) given unknown location Error 3 fatal error in "PiecewiseYieldCurveTest::testLogLinearZeroConsistency": std::exception: negative time (-0.00277778) given unknown location Error 4 fatal error in "PiecewiseYieldCurveTest::testLinearZeroConsistency": std::exception: negative time (-0.00277778) given unknown location Error 5 fatal error in "PiecewiseYieldCurveTest::testSplineZeroConsistency": std::exception: negative time (-0.00277778) given unknown location Error 6 fatal error in "PiecewiseYieldCurveTest::testLinearForwardConsistency": std::exception: negative time (-0.00277778) given unknown location Error 7 fatal error in "PiecewiseYieldCurveTest::testFlatForwardConsistency": std::exception: negative time (-0.00277778) given unknown location Got this when I tried to compile quantlib 0.9.0 on Visual Studio 2005. - John Maiden ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2007-12-24 06:14 Message: Logged In: NO Forgot to add that this compiled with Debug CRTDLL without problems, but this popped up for Release CRTDLL. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112740&aid=1857551&group_id=12740 |
|
From: SourceForge.net <no...@so...> - 2007-12-24 14:12:44
|
Bugs item #1857551, was opened at 2007-12-24 06:12 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112740&aid=1857551&group_id=12740 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: quantlib 0.9.0 PiecewiseYieldCurveTest problem Initial Comment: Error 1 fatal error in "PiecewiseYieldCurveTest::testLogLinearDiscountConsistency": std::exception: negative time (-0.00277778) given unknown location Error 2 fatal error in "PiecewiseYieldCurveTest::testLinearDiscountConsistency": std::exception: negative time (-0.00277778) given unknown location Error 3 fatal error in "PiecewiseYieldCurveTest::testLogLinearZeroConsistency": std::exception: negative time (-0.00277778) given unknown location Error 4 fatal error in "PiecewiseYieldCurveTest::testLinearZeroConsistency": std::exception: negative time (-0.00277778) given unknown location Error 5 fatal error in "PiecewiseYieldCurveTest::testSplineZeroConsistency": std::exception: negative time (-0.00277778) given unknown location Error 6 fatal error in "PiecewiseYieldCurveTest::testLinearForwardConsistency": std::exception: negative time (-0.00277778) given unknown location Error 7 fatal error in "PiecewiseYieldCurveTest::testFlatForwardConsistency": std::exception: negative time (-0.00277778) given unknown location Got this when I tried to compile quantlib 0.9.0 on Visual Studio 2005. - John Maiden ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112740&aid=1857551&group_id=12740 |
|
From: Luigi B. <lui...@gm...> - 2007-12-24 10:09:19
|
Ho, ho, ho! QuantLib is a cross-platform, free/open-source quantitative finance C++ library for modeling, pricing, trading, and risk management in real-life. Version 0.9.0 is coming to town and is available for download at <http://quantlib.org/download.shtml>. You better not cry and you better not pout, but please log any problems you have with this release in the SourceForge bug tracker at <http://sourceforge.net/tracker/?group_id=12740&atid=112740> specifying that you're using QuantLib 0.9.0. Merry Christmas, The QuantLib group |
|
From: Luigi B. <lui...@gm...> - 2007-12-23 21:46:52
|
On Dec 22, 2007, at 10:19 PM, Piter Dias wrote: > I had to make a spreadsheet using calendar but QuantLibAddin still > misses > Brazilian Exchange calendar. > > Could you please add the following lines in > QuantLibAddin\gensrc\metadata\Enumerations\enumeratedtypes.xml? Done, thanks for the heads-up. Luigi |
|
From: Tito I. <tit...@ya...> - 2007-12-23 19:24:25
|
Hi,
I've been using quantlib through swig in java for several months and,
once past the initial difficulties, it has been working very well.
Up until now, I've only been using the option pricing functionality
but would like to use the monte carlo functionality as well. To get
rolling, I've been looking at the DiscreteHedging example with an eye
towards implementing in java to get used to what's involved.
I've been able to expose and use the relevant bits of BlackCalculator
but am now stuck on the implementation of a PathPricer. My hope is
to implement the logic of the path pricer within java, but this
doesn't seem terribly easy as the path pricer is essentially a
callback which, if exposed through SWIG, would need quantlib to call
into java (or whatever other language). To do this, I believe I'd
have to implement a custom c++ PathPricer which somehow gets a hold
of a reference to a java object which implements the path pricer. I
don't see any examples in QuantLib-SWIG which seem to do a similar
trick which leads me to believe that it is not particularly easy and
that people are thus not using the MC model in any very interesting
way in other languages.
My questions:
- Am I missing something obvious here? Are people really not using
MC from swig?
- Does anyone have an example of a pathpricer or similar
functionality which is called through swig from quantlib?
- Any ideas on how one might design an amendment to quantlib's
existing MC functionality such that it could be more readily
accessed/extended from external languages?
Thanks in advance for any insights or suggestions and best wishes to
all for happy holidays and new year.
Tito.
|
|
From: Piter D. <pit...@ma...> - 2007-12-22 21:19:55
|
Guys,
I had to make a spreadsheet using calendar but QuantLibAddin still misses
Brazilian Exchange calendar.
Could you please add the following lines in
QuantLibAddin\gensrc\metadata\Enumerations\enumeratedtypes.xml?
Thanks in advance.
<EnumeratedType>
<string>Brazil::Settlement</string>
<value>QuantLib::Brazil(QuantLib::Brazil::Settlement)</value>
</EnumeratedType>
<EnumeratedType>
<string>Brazil::Exchange</string>
<value>QuantLib::Brazil(QuantLib::Brazil::Exchange)</value>
</EnumeratedType>
Piter Dias
pit...@ca...
|
|
From: Luigi B. <lui...@gm...> - 2007-12-22 21:18:51
|
On Dec 22, 2007, at 5:49 PM, na...@us... wrote: > Revision: 13872 > > http://quantlib.svn.sourceforge.net/quantlib/?rev=13872&view=rev > Author: nando > Date: 2007-12-22 08:49:11 -0800 (Sat, 22 Dec 2007) > > Log Message: > ----------- > switched signatures to Natural instead of Integer and const Date& > instead of Date Nando, in the function you modified, the Date was passed by value on purpose. That way, it could be modified: > Real CashFlows::npv(const Leg& cashflows, > const InterestRate& irr, > - Date settlementDate) { > - if (settlementDate == Date()) > - settlementDate = Settings::instance().evaluationDate(); whereas if you pass it by const reference, you have to introduce an additional object: > + Date refDate = settlDate; > + if (refDate == Date()) > + refDate = Settings::instance().evaluationDate(); Also, why "settlDate"? Looks less readable to me. Merry Christmas, Luigi |
|
From: Luigi B. <lui...@gm...> - 2007-12-22 21:14:32
|
On Dec 22, 2007, at 7:28 PM, Andrea wrote: > Thank you for your answer. I have started working on the > MCBasketEngine. > I will create a new Payoff implementing the methods I needs and we'll > see if it is any good. > > I think a product should > > 1) tell the engine on which dates it needs the values of how many > underlyings. True. This can be done in the setupArguments() method of the product by storing the relevant dates in the arguments structure contained in the engine (if you're not yet familiar with how the Instrument and PricingEngine class work together, look at the draft of chapter 2 available at <http://luigi.ballabio.googlepages.com/qlbook> > 2) the mc engine should generate a matrix of that many underlyings on > those dates (removing the extra timesteps simulated only for a > discretization schemes) and pass it to the product. Yes. For this, you can use the MultiPathGenerator class. Given the dates and the dynamics of the underlyings, it will generate a MultiPath instance containing the underlying values. However, you shouldn't pass it to the product, but rather to an instance of a class derived from PathPricer (which the product will instantiate.) > 3) the product should then return how much it pays on some final date. True, with 'product' replaced by 'path pricer'. Let me know how it goes. In the meantime, have a merry Christmas. Luigi |
|
From: Luigi B. <lui...@gm...> - 2007-12-22 20:39:47
|
On Dec 22, 2007, at 2:17 PM, Nasky wrote: > I'm a new user. I don't know how to compile a C++ program using > QuantLib on > Linux. > > And I compile with : g++ -o stuff stuff.cpp > > What should I add to my compilation line ? Something like "-lql" > doesn't > work. g++ -o stuff stuff.cpp -lQuantLib assuming you have installed QuantLib in the default location (i.e., if you didn't change it by explicitly adding a --prefix option to configure) Luigi |
|
From: Andrea <mar...@go...> - 2007-12-22 18:29:00
|
Luigi Ballabio wrote: > In the meantime, you can work your way around it. My suggestion is to > generalize the McBasket class as I sketched above, write the formulas > you need in your PathPricer, and disregard the payoff classes entirely. > To keep it cleaner, you might want to inherit your class(es) from > BasketOption so that their constructor don't take a payoff. Thank you for your answer. I have started working on the MCBasketEngine. I will create a new Payoff implementing the methods I needs and we'll see if it is any good. I think a product should 1) tell the engine on which dates it needs the values of how many underlyings. 2) the mc engine should generate a matrix of that many underlyings on those dates (removing the extra timesteps simulated only for a discretization schemes) and pass it to the product. 3) the product should then return how much it pays on some final date. alternatively one could add 1a) the product tells the engine on which dates it is going to make a payment 2a) add those dates to the dates of step 1) in order to remember a numeraire for each of the dates at step 1a) (those values will be used at step 3a). 3a) return a vector of payments, one for each date announced at step 1a). the engine will then discount those values using the numeraire at step 2a) One should ensure that a "dodgy" payoff is not allowed to see in the future, since it is given the whole path. Maybe it should only be given (for each of the payment dates) the path till there. So that it cannot see into the future. In an equity model where the numeraire is deterministic, maybe step 2a can be postponed at the end, only for non zero payments. As far as I understand, the Payoff is just the mathematical formula to compute the value paid, while the Option has a wider knowledge of dates and other financial matters. > > >> 2) MultiAssetOption has the following methods >> >> Real delta() const; >> Real gamma() const; >> Real vega() const; >> Real dividendRho() const; >> >> which in my opinion should return Arrays or Matrices > > I think so too. Hmm, it's a long time since I looked at this class... > whoever added these methods might have though of the greeks with respect > to the total basket value---whatever sense this may make. I'll have to > see if any engine provides these results. If not, they should probably > be redefined. I was not able to find an example of how those functions are used. I will keep working on it. andrea |
|
From: Yang Ye <lea...@ya...> - 2007-12-22 15:43:04
|
it shall also include the paths for include files and library files.
g++ -o stuff stuff.cpp -I/path/to/includefiles -L/path/to/libfiles -lql
Regards,
Yang Ye
Nasky wrote:
> Hi all,
>
> I'm a new user. I don't know how to compile a C++ program using QuantLib on
> Linux.
>
> My code is heavily simple.
>
> #include <ql/quantlib.hpp>
>
> int main() {
> QuantLib::Real stuff ;
> return 0;
> }
>
>
> And I compile with : g++ -o stuff stuff.cpp
> And I got lots of errors stating XXX cannot be found, not referenced, etc.
>
> What should I add to my compilation line ? Something like "-lql" doesn't
> work.
>
> Thanks
>
|
|
From: Nasky <nas...@gm...> - 2007-12-22 13:17:06
|
Hi all,
I'm a new user. I don't know how to compile a C++ program using QuantLib on
Linux.
My code is heavily simple.
#include <ql/quantlib.hpp>
int main() {
QuantLib::Real stuff ;
return 0;
}
And I compile with : g++ -o stuff stuff.cpp
And I got lots of errors stating XXX cannot be found, not referenced, etc.
What should I add to my compilation line ? Something like "-lql" doesn't
work.
Thanks
--
View this message in context: http://www.nabble.com/Compile-a-quantlib-C%2B%2B-program-tp14469162p14469162.html
Sent from the quantlib-dev mailing list archive at Nabble.com.
|
|
From: Luigi B. <lui...@gm...> - 2007-12-21 16:22:55
|
On Thu, 2007-12-06 at 08:32 -0800, vema wrote: > I have installed QuantLib-SWIG-0.8.0 on my machine and have been > experimenting around with it quite lately particulary with the bindings in > Python. I have observed that the interface files (*.i) do not expose all the > attributes and methods. Yes, QuantLib-SWIG is somewhat behind the C++ library. The declaration of the missing classes and methods should be added to the interface files in the distribution before regenerating the wrappers. Are you willing to work on this? Later, Luigi -- The economy depends about as much on economists as the weather does on weather forecasters. -- Jean-Paul Kauffmann |
|
From: Luigi B. <lui...@gm...> - 2007-12-21 15:24:37
|
Hi Andrea, here we are. Apologies for the delay. On Sun, 2007-12-09 at 20:14 +0000, Andrea wrote: > I have to confess that I am a new user of QuantLib and I would like to > write a "generic" MC engine to price "generic" product depending on > many fixings of many assets. > > I've found in QuantLib something that is almost what I want, and it is > the "mcbasketengine". > It lack only the ability to price path dependent options. But I don't > think it is complicated to add it. No, it's not. The problem is that at this time, the engine is not a generic MC basket engine---it's a European one. The pathPricer() and timeGrid() methods should be made abstract and their implementations moved to a McEuropeanBasketEngine class. Then you could inherit your engine from the (now truly generic) base engine, defining timeGrid() to return the relevant times for your pricing and pathPricer() to return a path-dependent pricer. Unfortunately, much of the BasketOption class seems to be based on the same assumptions (an European exercise, and a payoff depending on a single number, be it the average, the min, or the max of the underlying values) hence the problems you're having in fitting a generic payoff over it. We'll have to review it and try to generalize a bit. In the meantime, you can work your way around it. My suggestion is to generalize the McBasket class as I sketched above, write the formulas you need in your PathPricer, and disregard the payoff classes entirely. To keep it cleaner, you might want to inherit your class(es) from BasketOption so that their constructor don't take a payoff. > 2) MultiAssetOption has the following methods > > Real delta() const; > Real gamma() const; > Real vega() const; > Real dividendRho() const; > > which in my opinion should return Arrays or Matrices I think so too. Hmm, it's a long time since I looked at this class... whoever added these methods might have though of the greeks with respect to the total basket value---whatever sense this may make. I'll have to see if any engine provides these results. If not, they should probably be redefined. Later, Luigi -- These are my principles, and if you don't like them... Well, I have others. -- Groucho Marx |
|
From: Luigi B. <lui...@gm...> - 2007-12-21 15:18:18
|
On Sat, 2007-12-15 at 18:09 -0500, Dominick Samperi wrote:
> I commented out the friend part like this:
> class Tracing : public Singleton<Tracing> {
> // friend class Singleton<Tracing>;
> private:
> Tracing();
>
> Can somebody comment on why the friend declaration is
> needed here? Doesn't this permit an interface to access the internals
> of the logic that it is supposed to encapsulate/hide via the
> "curiously recurring pattern"?
There's not much to be done about it. On the one hand, the Tracing
constructor must be made private if this is to be a Singleton class. On
the other hand, the instance() method of the Singleton class template
must call it to create the unique instance.
However, Tracing and Singleton<Tracing> are very much tied together, so
it's not much of an encapsulation breach. True, the above might allow
one to create two Tracing instances, but it wouldn't be easy and should
be done on purpose.
> An unrelated question: how is QuantLib-0.9.0.tar.gz made from the SVN
> repository?
By running 'make dist'.
> I am seeing different behavior if I use the preliminary tarball vs
> download from the 090 SVN branch.
Strange. Maybe there were other changes in the branch after the tarball
was created?
Luigi
--
Better to have an approximate answer to the right question than a
precise answer to the wrong question.
-- John Tukey as quoted by John Chambers
|
|
From: Luigi B. <lui...@gm...> - 2007-12-20 22:12:18
|
On Dec 19, 2007, at 8:02 PM, na...@us... wrote: > Log Message: > ----------- > added default parameters > > @@ -45,8 +45,8 @@ > InterestRate(); > //! Standard constructor > InterestRate(Rate r, > - const DayCounter& dc, > - Compounding comp, > + const DayCounter& dc = Actual365Fixed(), > + Compounding comp = Continuous, > Frequency freq = Annual); > //@} > //! \name conversions Nando, somehow I can see that the compounding may default to Continuous, but why should the day-count convention default to actual/365? Later, Luigi |
|
From: Luigi B. <lui...@gm...> - 2007-12-20 07:57:35
|
On Wed, 2007-12-19 at 23:48 +0100, Georgy Jikia wrote: > compiled tarballs with Visual Studio 2003. Got 6 errors with > piecewiseyieldcurve.cpp. The errors are on the border of tolerance Yes, I saw them too. I've increased the tolerance a bit... Thanks, Luigi > -- It is always the best policy to tell the truth, unless, of course, you are an exceptionally good liar. -- Jerome K. Jerome |
|
From: Georgy J. <geo...@gm...> - 2007-12-19 22:48:56
|
Hello, compiled tarballs with Visual Studio 2003. Got 6 errors with piecewiseyieldcurve.cpp. The errors are on the border of tolerance, but there should be now errors with the testsuite, right? Regards, Georgy Testing consistency of piecewise-log-linear discount curve... ./piecewiseyieldcurve.cpp(449): error in "PiecewiseYieldCurveTest::testLogLinearDiscountConsistency": 1 year(s) BMA swap: estimated libor fraction: 0.67560104 expected libor fraction: 0.6756 error: 1.0393722e-006 tolerance: 1e-006 Testing consistency of piecewise-linear discount curve... Testing consistency of piecewise-log-linear zero-yield curve... ./piecewiseyieldcurve.cpp(449): error in "PiecewiseYieldCurveTest::testLogLinearZeroConsistency": 1 year(s) BMA swap: estimated libor fraction: 0.67560104 expected libor fraction: 0.6756 error: 1.0393708e-006 tolerance: 1e-006 Testing consistency of piecewise-linear zero-yield curve... ./piecewiseyieldcurve.cpp(449): error in "PiecewiseYieldCurveTest::testLinearZeroConsistency": 1 year(s) BMA swap: estimated libor fraction: 0.67560104 expected libor fraction: 0.6756 error: 1.0393708e-006 tolerance: 1e-006 Testing consistency of piecewise-spline zero-yield curve... ./piecewiseyieldcurve.cpp(449): error in "PiecewiseYieldCurveTest::testSplineZeroConsistency": 1 year(s) BMA swap: estimated libor fraction: 0.67560104 expected libor fraction: 0.6756 error: 1.0393708e-006 tolerance: 1e-006 Testing consistency of piecewise-linear forward-rate curve... ./piecewiseyieldcurve.cpp(449): error in "PiecewiseYieldCurveTest::testLinearForwardConsistency": 1 year(s) BMA swap: estimated libor fraction: 0.67560104 expected libor fraction: 0.6756 error: 1.0393708e-006 tolerance: 1e-006 Testing consistency of piecewise-flat forward-rate curve... ./piecewiseyieldcurve.cpp(449): error in "PiecewiseYieldCurveTest::testFlatForwardConsistency": 1 year(s) BMA swap: estimated libor fraction: 0.67560104 expected libor fraction: 0.6756 error: 1.0393708e-006 tolerance: 1e-006 |
|
From: Andrea <mar...@go...> - 2007-12-17 22:51:01
|
Luigi Ballabio wrote: > > On Dec 17, 2007, at 10:52 PM, Andrea wrote: >> I've written a few mails to this mailing list and I did not get any >> answer whatsoever. > > Andrea, > my apologies. Your posts are in my mailbox and are labelled "Answer > this". It's just that I've been busy preparing next release (not to > mention my real work...) and I've not yet found the time to sit down and > think of a reply. I'll try to do it in the next few days. > > Later, > Luigi > > Thanks for your answer. I look forward to your answer. Meanwhile I will keep working on it and finding my way through the code. Regards Andrea |
|
From: Luigi B. <lui...@gm...> - 2007-12-17 22:12:10
|
On Dec 17, 2007, at 10:52 PM, Andrea wrote: > I've written a few mails to this mailing list and I did not get any > answer whatsoever. Andrea, my apologies. Your posts are in my mailbox and are labelled "Answer this". It's just that I've been busy preparing next release (not to mention my real work...) and I've not yet found the time to sit down and think of a reply. I'll try to do it in the next few days. Later, Luigi |
|
From: Andrea <mar...@go...> - 2007-12-17 21:52:34
|
Hi, I've written a few mails to this mailing list and I did not get any answer whatsoever. http://sourceforge.net/mailarchive/forum.php?thread_name=475C4C8B.7030301%40googlemail.com&forum_name=quantlib-dev http://sourceforge.net/mailarchive/forum.php?thread_name=4753428A.5090505%40googlemail.com&forum_name=quantlib-users http://sourceforge.net/mailarchive/forum.php?thread_name=4755D80A.5040300%40googlemail.com&forum_name=quantlib-users They were all about multi sock montecarlo engine and how to extend the Basket payoff. I wonder whether I have used the wrong words or for some reason I sounded impolite. Or just that nobody is interested (which I find most strange), and the mailing lists are almost dead. Briefly, if I have done anything wrong, I'd like to present my apologies. I look forward to receiving comments on the subject. Andrea |
|
From: Luigi B. <lui...@gm...> - 2007-12-17 20:11:15
|
On Dec 17, 2007, at 6:50 PM, Dirk Eddelbuettel wrote: > Understood :) We don't plan to release that breaks -- so let me > rephrase: > What changed since the last candidates were released? I.e. if > everything > that changed pertains to VC$whatever I won't bother getting into this > as > Linux behaviour looked pretty spotless to me the last time around. There were a couple of bug fixes (you can look at the svn log if you're interested) which were present on all platforms, but for some reasons didn't manifest on Linux---for instance, there was an out-of-bound access in the FittedBondCurve example which the program survived unscathed. Needless to say, I'd advise including the fix in the package :) Luigi |
|
From: Dirk E. <ed...@de...> - 2007-12-17 17:50:22
|
On 17 December 2007 at 18:28, Luigi Ballabio wrote: | | On Mon, 2007-12-17 at 11:19 -0600, Dirk Eddelbuettel wrote: | > On 17 December 2007 at 17:48, Luigi Ballabio wrote: | > | candidate tarballs for the 0.9.0 release are available from | > | <http://quantlib.org/prerelease/>. If you have a few spare cycles, | > | please test them out---if no showstoppers are reported, they will be | > | released in time for Christmas. | > | > What types of issues are you expecting? | | None, I hope... Understood :) We don't plan to release that breaks -- so let me rephrase: What changed since the last candidates were released? I.e. if everything that changed pertains to VC$whatever I won't bother getting into this as Linux behaviour looked pretty spotless to me the last time around. Hope this makes more sense, Dirk -- Three out of two people have difficulties with fractions. |