Пример #1
0
        public double HW_CAP_CM(double t0, double tAlpha, double[] taoArray, double x, double n, int num)
        {
            // 3.37
            Func <double, double> alphaFunc = t => MarketF(t) +
                                              Pow(this.Sigma(), 2) / (2 * Pow(this.A(), 2)) *
                                              Pow(1 - Exp(-this.A() * t), 2);
            var mu = MarketF(0) * Exp(-this.A() * t0) + alphaFunc(t0) -
                     alphaFunc(0) * Exp(-this.A() * t0);
            var sigma = Pow(this.Sigma(), 2) / (2 * Pow(this.A(), 2)) *
                        Pow(1 - Exp(-2 * this.A() * t0), 2);
            var sampleFunc = MonteCarloSimulation.GenerateSamples(
                num, 0.Wrap(), (t, rt) => HW_Caps(t0, tAlpha, taoArray, x, n, rt), mu.Wrap(), sigma.Wrap());
            var samples = sampleFunc();

            return(samples.Average());
        }
Пример #2
0
        private double[] HW_R_CM(double s, double rs, double t0, int n)
        {
            // 3.37
            if (t0 == s)
            {
                return new[] { rs }
            }
            ;
            var sigma = this.Sigma();
            var a     = this.A();

            double AlphaFunc(double t) => MarketF(t) +
            Pow(sigma, 2) / (2 * Pow(a, 2)) * Pow(1 - Exp(-a * t), 2);

            var mu = rs * Exp(-a * (t0 - s)) + AlphaFunc(t0) -
                     AlphaFunc(s) * Exp(-a * (t0 - s));
            var stdvar = Pow(sigma, 2) / (2 * Pow(a, 2)) *
                         Pow(1 - Exp(-2 * a * (t0 - s)), 2);
            var sampleFunc = MonteCarloSimulation.GenerateSamples(
                n, 0.Wrap(), (t, x) => x, mu.Wrap(), stdvar.Wrap());
            var samples = sampleFunc();

            return(samples);
        }