public void ProbaMeasure(double lambda, RrFunction sigma, Duration probaMaturity, Duration simulationMaturity, int quadratureNbPoints, double precision) { var refDate = DateTime.Parse("07/06/2009"); var hw1 = new Hw1Model(TimeMeasure.Act365(refDate), Currency.Eur, lambda, sigma); var probaMeasure = new PaymentInfo(hw1.Currency, refDate + probaMaturity); var t = refDate + simulationMaturity; var hw1PathGen = new Hw1ModelPathGeneratorFactory().Build(hw1, null, probaMeasure, new[] { t }); var brownianBridge = BrownianBridge.Create(hw1PathGen.AllSimulatedDates); var hw1Zc = new Hw1ModelZcRepresentation(hw1); var numeraireZc = hw1Zc.Zc(t, probaMeasure.Date, 1.0); Assert.AreEqual(hw1PathGen.AllSimulatedDates.Length, 1); double[] x, w; GaussHermite.GetQuadrature(quadratureNbPoints, out x, out w); double flow = 0.0; for (int i = 0; i < x.Length; i++) { var dw = brownianBridge.PathIncrements(new[] { x[i] }, 1); var ornstein = hw1PathGen.Path(dw).GetProcessValue(0); flow += w[i] * 1.0 / numeraireZc.Eval(ornstein); } var error = Math.Abs(flow - 1.0); Assert.LessOrEqual(error, precision); }
public void SinglePathCovariance(double[] dates, double epsilon, double precision) { var brownian = BrownianBridge.Create(dates); var dim = brownian.GaussianSize(1); var jacobian = FiniteDifferenceUtils.CenteredJacobian(x => BrownianPath1d(brownian, x), dim, new double[dim], epsilon); var covariance = jacobian.Prod(jacobian.Tranpose()); for (int i = 0; i < dates.Length; i++) { for (int j = 0; j < dates.Length; j++) { var cov_ij = Math.Min(dates[i], dates[j]); var error = Math.Abs(cov_ij - covariance[i, j]); Assert.LessOrEqual(error, precision); } } }
public McModel Build(IModel model, Market market, DateTime[] simulatedDates) { PaymentInfo probaMeasure = ProbaMeasure(simulatedDates, model); var factorRepresentationFactory = FactorRepresentationFactories.For(model); IFactorModelRepresentation factorRepresentation = factorRepresentationFactory.Build(model, market, probaMeasure); var modelPathGenFactory = ModelPathGeneratorFactories.For(model, mcConfig); IProcessPathGenerator processPathGenerator = modelPathGenFactory.Build(model, market, probaMeasure, simulatedDates); BrownianBridge brownianBridge = BrownianBridge.Create(processPathGenerator.AllSimulatedDates); int randomDim = brownianBridge.GaussianSize(processPathGenerator.ProcessDim); IRandomGenerator randomGenerator = mcConfig.RandomGenerator.Build(randomDim); double numeraire0 = market.DiscountCurve(probaMeasure.Financing).Zc(probaMeasure.Date); return(new McModel(factorRepresentation, simulatedDates, randomGenerator, brownianBridge, processPathGenerator, probaMeasure, numeraire0)); }
public void SinglePathIncrementCovariance(double[] dates, double epsilon, double precision) { var brownian = BrownianBridge.Create(dates); var dim = brownian.GaussianSize(1); var jacobian = FiniteDifferenceUtils.CenteredJacobian(x => PathInc1D(brownian, x), dim, new double[dim], epsilon); var covariance = jacobian.Prod(jacobian.Tranpose()); for (int i = 0; i < dates.Length; i++) { var error = Math.Abs(covariance[i, i] - (i == 0 ? dates[0] : dates[i] - dates[i - 1])); Assert.LessOrEqual(error, precision); for (int j = 0; j < i; j++) { var errorij = Math.Abs(covariance[i, j]); Assert.LessOrEqual(errorij, precision); Assert.IsTrue(DoubleUtils.MachineEquality(covariance[i, j], covariance[j, i])); } } }