public void Should_Return_CurrentPrice_When_FutureDateIsActualDate() { var futureDate = TODAY; var result = _pricer.GetPriceFor(TODAY, futureDate, CURRENT_PRICE, CURRENT_VOLATILITY); Assert.AreEqual(CURRENT_PRICE, result); }
public void Should_apply_one_time_by_days_the_volatility_on_price_(int numberOfDays, double expectedPrice) { var callCount = 0; Func <double, double> getVolatilityTestWapper = d => { callCount++; return(CURRENT_VOLATILITY); }; _pricer = new Pricer(Pricer.IsWeekEndDayOffChecker, getVolatilityTestWapper); var futureDate = TODAY.AddDays(numberOfDays); var result = _pricer.GetPriceFor(TODAY, futureDate, CURRENT_PRICE, CURRENT_VOLATILITY); Assert.AreEqual(expectedPrice, result, 0.0000000001); Assert.AreEqual(numberOfDays, callCount); }
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"); }
[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); }
public void Should_not_apply_volatility_on_price_day_off() { var dayOff = new[] { TODAY.AddDays(1), TODAY.AddDays(3), TODAY.AddDays(4) }; var callCount = 0; Func <double, double> getVolatilityTestWapper = d => { callCount++; return(CURRENT_VOLATILITY); }; Func <DateTime, bool> isDayOffTestWrapper = date => dayOff.Contains(date); _pricer = new Pricer(isDayOffTestWrapper, getVolatilityTestWapper); var newPrice = _pricer.GetPriceFor(TODAY, dayOff.Last(), CURRENT_PRICE, CURRENT_VOLATILITY); Assert.AreEqual(120.0, newPrice, 0.0000000001); Assert.AreEqual(1, callCount); }