Skip to content

Commit

Permalink
added nterest-rate term structure in g2process constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Hrushi20 <hrushikesh20thegreat@gmail.com>
  • Loading branch information
Hrushi20 committed Mar 29, 2024
1 parent 9ff0542 commit 7a21fd8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
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

0 comments on commit 7a21fd8

Please sign in to comment.