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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
|
/*
Copyright (C) 2004, 2005, 2007, 2008 StatPro Italia srl
Copyright (C) 2010 Klaus Spanderen
Copyright (C) 2015 Matthias Groncki
Copyright (C) 2018, 2019 Matthias Lungwitz
Copyright (C) 2019 Pedro Coelho
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
<quantlib-dev@lists.sf.net>. The license is also available online at
<https://www.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_stochastic_process_i
#define quantlib_stochastic_process_i
%include marketelements.i
%include termstructures.i
%include volatilities.i
%include observer.i
%{
using QuantLib::StochasticProcess;
%}
%shared_ptr(StochasticProcess)
class StochasticProcess : public Observable {
private:
StochasticProcess();
public:
Size size() const;
Size factors() const;
Array initialValues() const;
Array drift(Time t, const Array& x) const;
Matrix diffusion(Time t, const Array& x) const;
Array expectation(Time t0, const Array& x0, Time dt) const;
Matrix stdDeviation(Time t0, const Array& x0, Time dt) const;
Matrix covariance(Time t0, const Array& x0, Time dt) const;
Array evolve(Time t0, const Array& x0,
Time dt, const Array& dw) const;
};
#if defined(SWIGCSHARP)
SWIG_STD_VECTOR_ENHANCED( ext::shared_ptr<StochasticProcess> )
#endif
%template(StochasticProcessVector)
std::vector<ext::shared_ptr<StochasticProcess> >;
%{
using QuantLib::StochasticProcess1D;
%}
%shared_ptr(StochasticProcess1D)
class StochasticProcess1D
: public StochasticProcess {
public:
Real x0() const;
Real drift(Time t, Real x) const;
Real diffusion(Time t, Real x) const;
Real expectation(Time t0, Real x0, Time dt) const;
Real stdDeviation(Time t0, Real x0, Time dt) const;
Real variance(Time t0, Real x0, Time dt) const;
Real evolve(Time t0, Real x0, Time dt, Real dw) const;
Real apply(Real x0, Real dx) const;
};
#if defined(SWIGCSHARP)
SWIG_STD_VECTOR_ENHANCED( ext::shared_ptr<StochasticProcess1D> )
#endif
%template(StochasticProcess1DVector)
std::vector<ext::shared_ptr<StochasticProcess1D> >;
%{
using QuantLib::GeneralizedBlackScholesProcess;
%}
%shared_ptr(GeneralizedBlackScholesProcess)
class GeneralizedBlackScholesProcess : public StochasticProcess1D {
public:
GeneralizedBlackScholesProcess(
const Handle<Quote>& s0,
const Handle<YieldTermStructure>& dividendTS,
const Handle<YieldTermStructure>& riskFreeTS,
const Handle<BlackVolTermStructure>& volTS);
GeneralizedBlackScholesProcess(
const Handle<Quote>& x0,
const Handle<YieldTermStructure>& dividendTS,
const Handle<YieldTermStructure>& riskFreeTS,
const Handle<BlackVolTermStructure>& blackVolTS,
const Handle<LocalVolTermStructure>& localVolTS);
Handle<Quote> stateVariable();
Handle<YieldTermStructure> dividendYield();
Handle<YieldTermStructure> riskFreeRate();
Handle<BlackVolTermStructure> blackVolatility();
Handle<LocalVolTermStructure> localVolatility();
};
%{
using QuantLib::BlackScholesProcess;
%}
%shared_ptr(BlackScholesProcess)
class BlackScholesProcess : public GeneralizedBlackScholesProcess {
public:
BlackScholesProcess(const Handle<Quote>& s0,
const Handle<YieldTermStructure>& riskFreeTS,
const Handle<BlackVolTermStructure>& volTS);
};
%{
using QuantLib::BlackScholesMertonProcess;
%}
%shared_ptr(BlackScholesMertonProcess)
class BlackScholesMertonProcess : public GeneralizedBlackScholesProcess {
public:
BlackScholesMertonProcess(
const Handle<Quote>& s0,
const Handle<YieldTermStructure>& dividendTS,
const Handle<YieldTermStructure>& riskFreeTS,
const Handle<BlackVolTermStructure>& volTS);
};
%{
using QuantLib::BlackProcess;
%}
%shared_ptr(BlackProcess)
class BlackProcess : public GeneralizedBlackScholesProcess {
public:
BlackProcess(const Handle<Quote>& s0,
const Handle<YieldTermStructure>& riskFreeTS,
const Handle<BlackVolTermStructure>& volTS);
};
%{
using QuantLib::GarmanKohlagenProcess;
%}
%shared_ptr(GarmanKohlagenProcess)
class GarmanKohlagenProcess : public GeneralizedBlackScholesProcess {
public:
GarmanKohlagenProcess(
const Handle<Quote>& s0,
const Handle<YieldTermStructure>& foreignRiskFreeTS,
const Handle<YieldTermStructure>& domesticRiskFreeTS,
const Handle<BlackVolTermStructure>& volTS);
};
%{
using QuantLib::Merton76Process;
%}
%shared_ptr(Merton76Process)
class Merton76Process : public StochasticProcess1D {
public:
Merton76Process(const Handle<Quote>& stateVariable,
const Handle<YieldTermStructure>& dividendTS,
const Handle<YieldTermStructure>& riskFreeTS,
const Handle<BlackVolTermStructure>& volTS,
const Handle<Quote>& jumpIntensity,
const Handle<Quote>& meanLogJump,
const Handle<Quote>& jumpVolatility);
};
%{
using QuantLib::StochasticProcessArray;
%}
%shared_ptr(StochasticProcessArray)
class StochasticProcessArray : public StochasticProcess {
public:
StochasticProcessArray(
const std::vector<ext::shared_ptr<StochasticProcess1D> >&array,
const Matrix &correlation);
};
%{
using QuantLib::GeometricBrownianMotionProcess;
%}
%shared_ptr(GeometricBrownianMotionProcess)
class GeometricBrownianMotionProcess : public StochasticProcess1D {
public:
GeometricBrownianMotionProcess(Real initialValue,
Real mu,
Real sigma);
};
%{
using QuantLib::VarianceGammaProcess;
%}
%shared_ptr(VarianceGammaProcess)
class VarianceGammaProcess : public StochasticProcess1D {
public:
VarianceGammaProcess(const Handle<Quote>& s0,
const Handle<YieldTermStructure>& dividendYield,
const Handle<YieldTermStructure>& riskFreeRate,
Real sigma, Real nu, Real theta);
};
%{
using QuantLib::HestonProcess;
%}
%shared_ptr(HestonProcess)
class HestonProcess : public StochasticProcess {
public:
enum Discretization { PartialTruncation,
FullTruncation,
Reflection,
NonCentralChiSquareVariance,
QuadraticExponential,
QuadraticExponentialMartingale,
BroadieKayaExactSchemeLobatto,
BroadieKayaExactSchemeLaguerre,
BroadieKayaExactSchemeTrapezoidal };
HestonProcess(const Handle<YieldTermStructure>& riskFreeTS,
const Handle<YieldTermStructure>& dividendTS,
const Handle<Quote>& s0,
Real v0, Real kappa,
Real theta, Real sigma, Real rho,
Discretization d = QuadraticExponentialMartingale);
Handle<Quote> s0();
Handle<YieldTermStructure> dividendYield();
Handle<YieldTermStructure> riskFreeRate();
};
%{
using QuantLib::BatesProcess;
%}
%shared_ptr(BatesProcess)
class BatesProcess : public HestonProcess {
public:
BatesProcess(const Handle<YieldTermStructure>& riskFreeRate,
const Handle<YieldTermStructure>& dividendYield,
const Handle<Quote>& s0,
Real v0, Real kappa,
Real theta, Real sigma, Real rho,
Real lambda, Real nu, Real delta);
};
%{
using QuantLib::HullWhiteProcess;
%}
%shared_ptr(HullWhiteProcess)
class HullWhiteProcess : public StochasticProcess1D {
public:
HullWhiteProcess(const Handle<YieldTermStructure>& riskFreeTS,
Real a, Real sigma);
};
%{
using QuantLib::HullWhiteForwardProcess;
%}
%shared_ptr(HullWhiteForwardProcess)
class HullWhiteForwardProcess : public StochasticProcess1D {
public:
HullWhiteForwardProcess(const Handle<YieldTermStructure>& riskFreeTS,
Real a,
Real sigma);
Real alpha(Time t) const;
Real M_T(Real s, Real t, Real T) const;
Real B(Time t, Time T) const;
void setForwardMeasureTime(Time t);
};
%{
using QuantLib::G2Process;
%}
%shared_ptr(G2Process)
class G2Process : public StochasticProcess {
public:
G2Process(Real a, Real sigma, Real b, Real eta, Real rho);
};
%{
using QuantLib::G2ForwardProcess;
%}
%shared_ptr(G2ForwardProcess)
class G2ForwardProcess : public StochasticProcess {
public:
G2ForwardProcess(Real a, Real sigma, Real b, Real eta, Real rho);
void setForwardMeasureTime(Time t);
};
%{
using QuantLib::GsrProcess;
%}
%shared_ptr(GsrProcess)
class GsrProcess : public StochasticProcess1D {
public:
GsrProcess(const Array ×, const Array &vols,
const Array &reversions, const Real T = 60.0);
Real sigma(Time t);
Real reversion(Time t);
Real y(Time t);
Real G(Time t, Time T, Real x);
void setForwardMeasureTime(Time t);
};
%inline %{
const ext::shared_ptr<GsrProcess> as_gsr_process(
const ext::shared_ptr<StochasticProcess>& proc) {
return ext::dynamic_pointer_cast<GsrProcess>(proc);
}
%}
%{
using QuantLib::OrnsteinUhlenbeckProcess;
%}
%shared_ptr(OrnsteinUhlenbeckProcess)
class OrnsteinUhlenbeckProcess : public StochasticProcess1D {
public:
OrnsteinUhlenbeckProcess(
Real speed, Volatility vol, Real x0 = 0.0, Real level = 0.0);
Real speed() const;
Real volatility() const;
Real level() const;
};
%{
using QuantLib::KlugeExtOUProcess;
using QuantLib::ExtendedOrnsteinUhlenbeckProcess;
using QuantLib::ExtOUWithJumpsProcess;
%}
%shared_ptr(ExtendedOrnsteinUhlenbeckProcess)
class ExtendedOrnsteinUhlenbeckProcess : public StochasticProcess1D {
public:
enum Discretization { MidPoint, Trapezodial, GaussLobatto };
%extend{
#if defined(SWIGPYTHON)
ExtendedOrnsteinUhlenbeckProcess(
Real speed, Volatility sigma, Real x0,
PyObject* function,
Real intEps = 1e-4) {
const UnaryFunction f(function);
return new ExtendedOrnsteinUhlenbeckProcess(
speed, sigma, x0, f,
ExtendedOrnsteinUhlenbeckProcess::MidPoint, intEps);
}
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
ExtendedOrnsteinUhlenbeckProcess(
Real speed, Volatility sigma, Real x0,
UnaryFunctionDelegate* function,
Real intEps = 1e-4) {
const UnaryFunction f(function);
return new ExtendedOrnsteinUhlenbeckProcess(
speed, sigma, x0, f,
ExtendedOrnsteinUhlenbeckProcess::MidPoint, intEps);
}
#endif
}
};
%shared_ptr(ExtOUWithJumpsProcess)
class ExtOUWithJumpsProcess : public StochasticProcess {
public:
ExtOUWithJumpsProcess(
const ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess>& process,
Real Y0, Real beta, Real jumpIntensity, Real eta);
};
%shared_ptr(KlugeExtOUProcess)
class KlugeExtOUProcess : public StochasticProcess {
public:
KlugeExtOUProcess(
Real rho,
const ext::shared_ptr<ExtOUWithJumpsProcess>& kluge,
const ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess>& extOU);
};
%{
using QuantLib::GJRGARCHProcess;
%}
%shared_ptr(GJRGARCHProcess)
class GJRGARCHProcess : public StochasticProcess {
public:
enum Discretization { PartialTruncation, FullTruncation, Reflection};
GJRGARCHProcess(const Handle<YieldTermStructure>& riskFreeRate,
const Handle<YieldTermStructure>& dividendYield,
const Handle<Quote>& s0,
Real v0, Real omega, Real alpha, Real beta,
Real gamma, Real lambda, Real daysPerYear = 252.0,
Discretization d = FullTruncation);
Handle<Quote> s0();
Handle<YieldTermStructure> dividendYield();
Handle<YieldTermStructure> riskFreeRate();
};
#endif
|