예제 #1
0
        /// <summary>
        /// RNGs this instance.
        /// </summary>
        /// <returns></returns>
        private IContinuousRng Rng(int seed)
        {
            IBasicRng basRng = new MCG31vsl(seed);
            //IContinuousRng unifRng = new UniformRng(basRng,0,1);
            var lhs = new BoxMullerGaussianRng(basRng, 0, 1);

            return(lhs);
        }
예제 #2
0
        /// <summary>
        /// Run an Euler-like simulation to generate paths of the OU-process
        /// Evaluate function points using GetYValue()
        /// </summary>
        /// <param name="payoff"></param>
        /// <param name="ratedays"></param>
        /// <param name="rateamts"></param>
        /// <param name="divdays"></param>
        /// <param name="divamts"></param>
        /// <param name="volSurface"></param>
        /// <param name="spot"></param>
        /// <param name="callstrike"></param>
        /// <param name="putstrike"></param>
        /// <param name="maturity"></param>
        /// <param name="profiletimes"></param>
        /// <param name="kappa"></param>
        /// <param name="theta"></param>
        /// <param name="sigma"></param>
        /// <param name="tStepSize"></param>
        /// <param name="sims"></param>
        /// <returns></returns>
        private static List <RiskStatistics> Euler(string payoff,
                                                   int[] ratedays,
                                                   double[] rateamts,
                                                   int[] divdays,
                                                   double[] divamts,
                                                   List <OrcWingParameters> volSurface,
                                                   double spot,
                                                   double callstrike,
                                                   double putstrike,
                                                   double maturity,
                                                   double[] profiletimes,
                                                   double kappa,
                                                   double theta,
                                                   double sigma,
                                                   double confidence,
                                                   double tStepSize,
                                                   int sims,
                                                   int seed
                                                   )
        {
            double[]  times         = CreateTimeGrid(profiletimes, tStepSize);
            int       n             = times.Length;
            int       profilepoints = profiletimes.Length;
            double    lns0          = Math.Log(spot);
            IBasicRng basRng        = new MCG31vsl(seed);
            //IContinousRng unifRng = new UniformRng(basRng,0,1);
            BoxMullerGaussianRng gen = new BoxMullerGaussianRng(basRng, 0, 1);

            double[]              lns              = new double[n];
            double[]              results          = new double[profilepoints];
            List <double>         _profileTimeList = new List <double>(profiletimes);
            List <RiskStatistics> samples          = new List <RiskStatistics>(profilepoints);

            for (int idx = 0; idx < profilepoints; idx++)
            {
                samples.Add(new RiskStatistics());
            }

            for (int kdx = 0; kdx < sims; kdx++)
            {
                int    jdx = 0;
                double wdt = gen.NextDouble() * Math.Sqrt(times[0]);
                lns[0] = theta + Math.Exp(-kappa * times[0]) * (lns0 - theta) + sigma * wdt;
                for (int idx = 1; idx < n; idx++)
                {
                    double dt = times[idx] - times[idx - 1];
                    wdt      = gen.NextDouble() * Math.Sqrt(dt);
                    lns[idx] = theta + Math.Exp(-kappa * dt) * (lns[idx - 1] - theta) + sigma * wdt;

                    if (_profileTimeList.Contains(times[idx]))
                    {
                        double y = GetYValue(payoff, ratedays, rateamts, divdays, divamts, volSurface, spot, Math.Exp(lns[idx]), callstrike, putstrike, times[idx], maturity, confidence);
                        samples[jdx++].Add(y);
                    }
                }
            }
            return(samples);
        }