Ejemplo n.º 1
0
        [Test] public void Should_Return_many_time_volatility_calculation_When_use_MonteCarlo_as_Volatility_average()
        {
            var volatilities = new List <double>();

            var callCount = 0;
            Func <double, double> getVolatilityTestWapper = d =>
            {
                Interlocked.Increment(ref callCount);
                return(Pricer.GetNextRandomVolatility(d));
            };

            Func <double, double> monteCarloFor1000Shot = Pricer.GetMonteCarloVolatilityFor(1000, getVolatilityTestWapper);

            var pricer = new Pricer(Pricer.IsWeekEndDayOffChecker, monteCarloFor1000Shot);
            var result = pricer.GetPriceFor(TODAY, TOMOROW, CURRENT_PRICE, CURRENT_VOLATILITY);

            Assert.AreEqual(1000, callCount);
            Assert.GreaterOrEqual(120.00, result);
            Assert.LessOrEqual(80.00, result);
        }
Ejemplo n.º 2
0
        public void Should_Return_average_volatility_calculation_When_use_MonteCarlo_()
        {
            //var volatilities = new List<double> {20.0, 4, 30.0};

            var volatilities = new Stack <double>();

            volatilities.Push(20);
            volatilities.Push(4);
            volatilities.Push(30);

            Func <double, double> getVolatilityTestWapper = d =>
            {
                return(volatilities.Pop());
            };

            Func <double, double> monteCarloTest = Pricer.GetMonteCarloVolatilityFor(volatilities.Count, getVolatilityTestWapper);

            var result = monteCarloTest(Double.NaN);

            Assert.AreEqual(18, result, 0.0000000001);
        }