public FdmHestonEquityPart(FdmMesher mesher, YieldTermStructure rTS, YieldTermStructure qTS, FdmQuantoHelper quantoHelper = null, LocalVolTermStructure leverageFct = null) { varianceValues_ = new Vector(0.5 * mesher.locations(1)); dxMap_ = new FirstDerivativeOp(0, mesher); dxxMap_ = new SecondDerivativeOp(0, mesher).mult(0.5 * mesher.locations(1)); mapT_ = new TripleBandLinearOp(0, mesher); mesher_ = mesher; rTS_ = rTS; qTS_ = qTS; quantoHelper_ = quantoHelper; leverageFct_ = leverageFct; // on the boundary s_min and s_max the second derivative // d^2V/dS^2 is zero and due to Ito's Lemma the variance term // in the drift should vanish. FdmLinearOpLayout layout = mesher_.layout(); FdmLinearOpIterator endIter = layout.end(); for (FdmLinearOpIterator iter = layout.begin(); iter != endIter; ++iter) { if (iter.coordinates()[0] == 0 || iter.coordinates()[0] == layout.dim()[0] - 1) { varianceValues_[iter.index()] = 0.0; } } volatilityValues_ = Vector.Sqrt(2 * varianceValues_); }
public FdmHestonVariancePart( FdmMesher mesher, YieldTermStructure rTS, double sigma, double kappa, double theta) { dyMap_ = new SecondDerivativeOp(1, mesher) .mult(0.5 * sigma * sigma * mesher.locations(1)) .add(new FirstDerivativeOp(1, mesher) .mult(kappa * (theta - mesher.locations(1)))); mapT_ = new TripleBandLinearOp(1, mesher); rTS_ = rTS; }
public FdmDividendHandler(DividendSchedule schedule, FdmMesher mesher, Date referenceDate, DayCounter dayCounter, int equityDirection) { x_ = new Vector(mesher.layout().dim()[equityDirection]); mesher_ = mesher; equityDirection_ = equityDirection; dividends_ = new List <double>(); dividendDates_ = new List <Date>(); dividendTimes_ = new List <double>(); foreach (Dividend iter in schedule) { dividends_.Add(iter.amount()); dividendDates_.Add(iter.date()); dividendTimes_.Add( dayCounter.yearFraction(referenceDate, iter.date())); } Vector tmp = mesher_.locations(equityDirection); int spacing = mesher_.layout().spacing()[equityDirection]; for (int i = 0; i < x_.size(); ++i) { x_[i] = Math.Exp(tmp[i * spacing]); } }
public FdmDirichletBoundary(FdmMesher mesher, double valueOnBoundary, int direction, Side side) { side_ = side; valueOnBoundary_ = valueOnBoundary; indices_ = new FdmIndicesOnBoundary(mesher.layout(), direction, side).getIndices(); if (side_ == Side.Lower) { xExtreme_ = mesher.locations(direction)[0]; } else if (side_ == Side.Upper) { xExtreme_ = mesher .locations(direction)[mesher.layout().dim()[direction] - 1]; } else { Utils.QL_FAIL("internal error"); } }
public FdmHullWhiteOp(FdmMesher mesher, HullWhite model, int direction) { x_ = mesher.locations(direction); dzMap_ = new TripleBandLinearOp(new FirstDerivativeOp(direction, mesher).mult(-1.0 * x_ * model.a()).add( new SecondDerivativeOp(direction, mesher).mult(0.5 * model.sigma() * model.sigma() * new Vector(mesher.layout().size(), 1.0)))); mapT_ = new TripleBandLinearOp(direction, mesher); direction_ = direction; model_ = model; }
public FdmHestonOp(FdmMesher mesher, HestonProcess hestonProcess, FdmQuantoHelper quantoHelper = null, LocalVolTermStructure leverageFct = null) { correlationMap_ = new SecondOrderMixedDerivativeOp(0, 1, mesher) .mult(hestonProcess.rho() * hestonProcess.sigma() * mesher.locations(1)); dyMap_ = new FdmHestonVariancePart(mesher, hestonProcess.riskFreeRate().currentLink(), hestonProcess.sigma(), hestonProcess.kappa(), hestonProcess.theta()); dxMap_ = new FdmHestonEquityPart(mesher, hestonProcess.riskFreeRate().currentLink(), hestonProcess.dividendYield().currentLink(), quantoHelper, leverageFct); }
public FdmBlackScholesOp(FdmMesher mesher, GeneralizedBlackScholesProcess bsProcess, double strike, bool localVol = false, double?illegalLocalVolOverwrite = null, int direction = 0, FdmQuantoHelper quantoHelper = null) { mesher_ = mesher; rTS_ = bsProcess.riskFreeRate().currentLink(); qTS_ = bsProcess.dividendYield().currentLink(); volTS_ = bsProcess.blackVolatility().currentLink(); localVol_ = (localVol) ? bsProcess.localVolatility().currentLink() : null; x_ = (localVol) ? new Vector(Vector.Exp(mesher.locations(direction))) : null; dxMap_ = new FirstDerivativeOp(direction, mesher); dxxMap_ = new SecondDerivativeOp(direction, mesher); mapT_ = new TripleBandLinearOp(direction, mesher); strike_ = strike; illegalLocalVolOverwrite_ = illegalLocalVolOverwrite; direction_ = direction; quantoHelper_ = quantoHelper; }