Beispiel #1
0
        public void Should_apply_PositiveNegativeOrNone_Volitility_each_day_randomly()
        {
            var volatilities = new List <double>();

            Func <double, double> getVolatilityTestWapper = currentVolatility =>
            {
                var nextVolatility = Pricer.GetNextRandomVolatility(currentVolatility);
                volatilities.Add(nextVolatility);
                return(nextVolatility);
            };

            var pricer = new Pricer(Pricer.IsWeekEndDayOffChecker, getVolatilityTestWapper);

            pricer.GetPriceFor(TODAY, TODAY.AddDays(10000), CURRENT_PRICE, CURRENT_VOLATILITY);

            Assert.IsTrue(volatilities.Any(v => v < 0), "Some volatilities are positive");
            Assert.IsTrue(volatilities.Any(v => Math.Abs(v) < 0.00000000001), "Some volatilities are null");
            Assert.IsTrue(volatilities.Any(v => v > 0), "Some volatilities are negative");
        }
Beispiel #2
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);
        }