TwoStateMarkovChainDensity { PDEFullResults1D[] solve(final PDEGrid1D grid) { final BoundaryCondition lower = new NeumannBoundaryCondition(0.0, grid.getSpaceNode(0), true); final BoundaryCondition upper = new DirichletBoundaryCondition(0.0, grid.getSpaceNode(grid.getNumSpaceNodes() - 1)); CoupledPDEDataBundle d1 = new CoupledPDEDataBundle(_data1, _initCon11, lower, upper, grid); CoupledPDEDataBundle d2 = new CoupledPDEDataBundle(_data2, _initCon12, lower, upper, grid); final CoupledFiniteDifference solver = new CoupledFiniteDifference(THETA, true); final PDEResults1D[] res = solver.solve(d1, d2); final PDEFullResults1D res1 = (PDEFullResults1D) res[0]; final PDEFullResults1D res2 = (PDEFullResults1D) res[1]; return new PDEFullResults1D[] {res1, res2 }; } TwoStateMarkovChainDensity(final ForwardCurve forward, final double vol1, final double deltaVol, final double lambda12, final double lambda21, final double probS1, final double beta1,
      final double beta2);  TwoStateMarkovChainDensity(final ForwardCurve forward, final TwoStateMarkovChainDataBundle data);   }
@Test(enabled = false) public void test() { int tNodes = 100; int xNodes = 200; MeshingFunction timeMesh = new ExponentialMeshing(0, T, tNodes, 5.0); MeshingFunction spaceMesh = new HyperbolicMeshing(-0.0 * FORWARD.getForward(T), 6.0 * FORWARD.getForward(T), FORWARD.getSpot(), xNodes, 0.01); PDEGrid1D grid = new PDEGrid1D(timeMesh, spaceMesh); PDEFullResults1D[] res = DENSITY_CAL.solve(grid); PDEUtilityTools.printSurface("state 1 density", res[0]); PDEUtilityTools.printSurface("state 2 density", res[1]); }
@Test public void degenerateTest() { int tNodes = 20; int xNodes = 100; MeshingFunction timeMesh = new ExponentialMeshing(0, T, tNodes, 5.0); MeshingFunction spaceMesh = new HyperbolicMeshing(-0.0 * FORWARD.getForward(T), 6.0 * FORWARD.getForward(T), FORWARD.getSpot(), xNodes, 0.01); PDEGrid1D grid = new PDEGrid1D(timeMesh, spaceMesh); double l12 = 0.3; double l21 = 2.0; double pi1 = l21 / (l12 + l21); TwoStateMarkovChainDataBundle data = new TwoStateMarkovChainDataBundle(0.2, 0.2, l12, l21, pi1, 0.5, 0.5); TwoStateMarkovChainDensity cal = new TwoStateMarkovChainDensity(FORWARD, data); PDEFullResults1D[] res = cal.solve(grid); for (int i = 0; i < xNodes; i++) { assertEquals(res[0].getFunctionValue(i, tNodes - 1) / pi1, res[1].getFunctionValue(i, tNodes - 1) / (1 - pi1), 1e-6); } }