// this is a workaround for CuriouslyRecurringTemplate of TreeLattice // recheck it /* public override TreeLattice2D impl() { return this; } */ public TreeLattice2D(TrinomialTree tree1, TrinomialTree tree2, double correlation) : base(tree1.timeGrid(), (int)Branches.branches * (int)Branches.branches) { tree1_ = (Tl)tree1; //le cast à voir!! tree2_ = (Tl)tree2; //le cast à voir!! m_ = new Matrix((int)Branches.branches, (int)Branches.branches); rho_ = Math.Abs(correlation); // what happens here? if (correlation < 0.0 && (int)Branches.branches == 3) { m_[0, 0] = -1.0; m_[0, 1] = -4.0; m_[0, 2] = 5.0; m_[1, 0] = -4.0; m_[1, 1] = 8.0; m_[1, 2] = -4.0; m_[2, 0] = 5.0; m_[2, 1] = -4.0; m_[2, 2] = -1.0; } else { m_[0, 0] = 5.0; m_[0, 1] = -4.0; m_[0, 2] = -1.0; m_[1, 0] = -4.0; m_[1, 1] = 8.0; m_[1, 2] = -4.0; m_[2, 0] = -1.0; m_[2, 1] = -4.0; m_[2, 2] = 5.0; } }
public override Lattice tree(TimeGrid grid) { TermStructureFittingParameter phi = new TermStructureFittingParameter(termStructure()); ShortRateDynamics numericDynamics = new Dynamics(phi, a(), sigma()); TrinomialTree trinomial = new TrinomialTree(numericDynamics.process(), grid); ShortRateTree numericTree = new ShortRateTree(trinomial, numericDynamics, grid); TermStructureFittingParameter.NumericalImpl impl = (TermStructureFittingParameter.NumericalImpl)phi.implementation(); impl.reset(); double value = 1.0; double vMin = -50.0; double vMax = 50.0; for (int i = 0; i < (grid.size() - 1); i++) { double discountBond = termStructure().link.discount(grid[i + 1]); double xMin = trinomial.underlying(i, 0); double dx = trinomial.dx(i); Helper finder = new Helper(i, xMin, dx, discountBond, numericTree); Brent s1d = new Brent(); s1d.setMaxEvaluations(1000); value = s1d.solve(finder, 1e-7, value, vMin, vMax); impl.setvalue(grid[i], value); } return(numericTree); }
public override Lattice tree(TimeGrid grid) { TermStructureFittingParameter phi = new TermStructureFittingParameter(termStructure()); ShortRateDynamics numericDynamics = new Dynamics(phi, a(), sigma()); TrinomialTree trinomial = new TrinomialTree(numericDynamics.process(), grid); ShortRateTree numericTree = new ShortRateTree(trinomial, numericDynamics, grid); TermStructureFittingParameter.NumericalImpl impl = (TermStructureFittingParameter.NumericalImpl)phi.implementation(); impl.reset(); for (int i = 0; i < (grid.size() - 1); i++) { double discountBond = termStructure().link.discount(grid[i + 1]); Vector statePrices = numericTree.statePrices(i); int size = numericTree.size(i); double dt = numericTree.timeGrid().dt(i); double dx = trinomial.dx(i); double x = trinomial.underlying(i, 0); double value = 0.0; for (int j = 0; j < size; j++) { value += statePrices[j] * Math.Exp(-x * dt); x += dx; } value = Math.Log(value / discountBond) / dt; impl.setvalue(grid[i], value); } return(numericTree); }
//! Tree build-up + numerical fitting to term-structure public ShortRateTree(TrinomialTree tree, ShortRateDynamics dynamics, TermStructureFittingParameter.NumericalImpl theta, TimeGrid timeGrid) : base(timeGrid, tree.size(1)) { tree_ = tree; dynamics_ = dynamics; theta.reset(); double value = 1.0; double vMin = -100.0; double vMax = 100.0; for (int i = 0; i < (timeGrid.size() - 1); i++) { double discountBond = theta.termStructure().link.discount(t_[i + 1]); Helper finder = new Helper(i, discountBond, theta, this); Brent s1d = new Brent(); s1d.setMaxEvaluations(1000); value = s1d.solve(finder, 1e-7, value, vMin, vMax); // vMin = value - 1.0; // vMax = value + 1.0; theta.change(value); } }
//! Return by default a trinomial recombining tree public override Lattice tree(TimeGrid grid) { //throw new NotImplementedException(); TrinomialTree trinomial = new TrinomialTree(dynamics().process(), grid); return(new ShortRateTree(trinomial, dynamics(), grid)); }
//! Plain tree build-up from short-rate dynamics public ShortRateTree(TrinomialTree tree, ShortRateDynamics dynamics, TimeGrid timeGrid) : base(timeGrid, tree.size(1)) { tree_ = tree; dynamics_ = dynamics; }
public override Lattice tree(TimeGrid grid) { ShortRateDynamics dyn = dynamics(); TrinomialTree tree1 = new TrinomialTree(dyn.xProcess(), grid); TrinomialTree tree2 = new TrinomialTree(dyn.yProcess(), grid); return((Lattice)(new ShortRateTree(tree1, tree2, dyn))); }
public override Lattice tree(TimeGrid grid) { TrinomialTree trinomial = new TrinomialTree(dynamics().process(), grid, true); return(new ShortRateTree(trinomial, dynamics(), grid)); }