Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Interest-rate term structure in g2process constructor #1937

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions ql/processes/g2process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

namespace QuantLib {

G2Process::G2Process(Real a, Real sigma, Real b, Real eta, Real rho)
G2Process::G2Process(const Handle<YieldTermStructure>& h, Real a, Real sigma, Real b, Real eta, Real rho)
: a_(a), sigma_(sigma), b_(b), eta_(eta), rho_(rho),
xProcess_(new QuantLib::OrnsteinUhlenbeckProcess(a, sigma, 0.0)),
yProcess_(new QuantLib::OrnsteinUhlenbeckProcess(b, eta, 0.0)) {}
yProcess_(new QuantLib::OrnsteinUhlenbeckProcess(b, eta, 0.0)), h_(h) {}

Size G2Process::size() const {
return 2;
Expand All @@ -36,9 +36,16 @@ namespace QuantLib {
}

Array G2Process::drift(Time t, const Array& x) const {
Real alpha_drift = sigma_*sigma_/(2*a_)*(1-std::exp(-2*a_*t));
Real shift = 0.0001;
Real f = h_->forwardRate(t, t, Continuous, NoFrequency);
Real fup = h_->forwardRate(t+shift, t+shift, Continuous, NoFrequency);
Real f_prime = (fup-f)/shift;
alpha_drift += a_*f+f_prime;

return {
xProcess_->drift(t, x[0]),
yProcess_->drift(t, x[1])
xProcess_->drift(t, x[0]) + alpha_drift,
yProcess_->drift(t, x[1]) + alpha_drift
};
}

Expand Down Expand Up @@ -124,10 +131,10 @@ namespace QuantLib {
}


G2ForwardProcess::G2ForwardProcess(Real a, Real sigma, Real b, Real eta, Real rho)
G2ForwardProcess::G2ForwardProcess(const Handle<YieldTermStructure>& h, Real a, Real sigma, Real b, Real eta, Real rho)
: a_(a), sigma_(sigma), b_(b), eta_(eta), rho_(rho),
xProcess_(new QuantLib::OrnsteinUhlenbeckProcess(a, sigma, 0.0)),
yProcess_(new QuantLib::OrnsteinUhlenbeckProcess(b, eta, 0.0)) {}
yProcess_(new QuantLib::OrnsteinUhlenbeckProcess(b, eta, 0.0)),h_(h) {}

Size G2ForwardProcess::size() const {
return 2;
Expand Down
7 changes: 5 additions & 2 deletions ql/processes/g2process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@

#include <ql/processes/forwardmeasureprocess.hpp>
#include <ql/processes/ornsteinuhlenbeckprocess.hpp>
#include <ql/termstructures/yieldtermstructure.hpp>

namespace QuantLib {

//! %G2 stochastic process
/*! \ingroup processes */
class G2Process : public StochasticProcess {
public:
G2Process(Real a, Real sigma, Real b, Real eta, Real rho);
G2Process(const Handle<YieldTermStructure>& h, Real a, Real sigma, Real b, Real eta, Real rho);
//! \name StochasticProcess interface
//@{
Size size() const override;
Expand All @@ -55,13 +56,14 @@ namespace QuantLib {
Real x0_ = 0.0, y0_ = 0.0, a_, sigma_, b_, eta_, rho_;
ext::shared_ptr<QuantLib::OrnsteinUhlenbeckProcess> xProcess_;
ext::shared_ptr<QuantLib::OrnsteinUhlenbeckProcess> yProcess_;
Handle<YieldTermStructure> h_;
};

//! %Forward %G2 stochastic process
/*! \ingroup processes */
class G2ForwardProcess : public ForwardMeasureProcess {
public:
G2ForwardProcess(Real a, Real sigma, Real b, Real eta, Real rho);
G2ForwardProcess(const Handle<YieldTermStructure>& h, Real a, Real sigma, Real b, Real eta, Real rho);
//! \name StochasticProcess interface
//@{
Size size() const override;
Expand All @@ -80,6 +82,7 @@ namespace QuantLib {
Real yForwardDrift(Time t, Time T) const;
Real Mx_T(Real s, Real t, Real T) const;
Real My_T(Real s, Real t, Real T) const;
Handle<YieldTermStructure> h_;
};

}
Expand Down
Loading