Example #1
0
        public void Should_get_correct_price_range_When_apply_monte_carlo()
        {
            var date        = D20190505;
            var nextDate    = date.AddDays(1);
            int largeNumber = 10000;

            int randomingCount = 0;
            Func <Volatility, Volatility> producer = d =>
            {
                var volatilityRandomizer = new VolatilityRandomizer();
                Interlocked.Increment(ref randomingCount);
                return(volatilityRandomizer.Randomrize(Volatility));
            };

            var monteCarlo = new MonteCarloVolatilityRandomizer(largeNumber, Volatility, producer);

            var pricer = new MiniPricer(new Price(date, InitialPrice), Volatility, new JoursFeriesProvider(), monteCarlo);

            var priceOfNextDay = pricer.GetPriceOf(Instrument, nextDate);

            Check.That(randomingCount).IsEqualTo(largeNumber);
            Check.That(priceOfNextDay.Date).IsEqualTo(nextDate);
            Check.That(priceOfNextDay.Value).IsStrictlyLessThan(120);
            Check.That(priceOfNextDay.Value).IsStrictlyGreaterThan(80);
        }
        public Volatility Randomrize(Volatility volatility)
        {
            var randomrizedVolatility = _innerRandomrizer.Randomrize(volatility);

            _volatilities.Add(randomrizedVolatility.Value);

            return(volatility);
        }