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 ProcessPathFlowGenerator(BrownianBridge brownianBridge,
                                        IProcessPathGenerator processPathGen,
                                        IPathFlowCalculator <TFlow, TLabel> flowPathCalculator)
        {
            this.brownianBridge     = brownianBridge;
            this.processPathGen     = processPathGen;
            this.flowPathCalculator = flowPathCalculator;

            dWs = ArrayUtils.CreateJaggedArray <double>(brownianBridge.Dates.Length, 1);
        }
Exemple #3
0
 public McModel(IFactorModelRepresentation factorRepresentation,
                DateTime[] simulatedDates,
                IRandomGenerator randomGenerator,
                BrownianBridge brownianBridge,
                IProcessPathGenerator processPathGen,
                PaymentInfo probaMeasure, double numeraire0)
 {
     Numeraire0           = numeraire0;
     ProbaMeasure         = probaMeasure;
     ProcessPathGen       = processPathGen;
     RandomGenerator      = randomGenerator;
     BrownianBridge       = brownianBridge;
     SimulatedDates       = simulatedDates;
     FactorRepresentation = factorRepresentation;
 }
Exemple #4
0
        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));
        }
Exemple #6
0
        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]));
                }
            }
        }
Exemple #7
0
 private static double[] PathInc1D(BrownianBridge bridge, double[] x)
 {
     return(bridge.PathIncrements(x, 1).Map(v => v[0]));
 }
Exemple #8
0
 private double[] BrownianPath1d(BrownianBridge bbridge, double[] x)
 {
     return(bbridge.Path(x, 1).Map(v => v[0]));
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BrownianBridge obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }