public void TryGetValue_StraddleTestCase_BenchmarkVolatility(ConstantVolatilityStandardEuropeanOptionConfiguration optionSpecification, double optionValue)
        {
            double tolerance;
            var    objectUnderTest = GetStraddleOptionImpliedVolatilityApproach(out tolerance);

            Assume.That(objectUnderTest, Is.Not.Null);

            double actual;
            var    actualState = objectUnderTest.TryGetValue(optionSpecification.Strike, optionSpecification.Forward, optionSpecification.TimeToExpiry, optionValue / optionSpecification.DiscountFactor, out actual);

            Assert.That(actual, Is.EqualTo(optionSpecification.Volatility).Within(tolerance));
            Assert.That(actualState, Is.EqualTo(ImpliedCalculationResultState.ProperResult));
        }
        public void TryGetValue_PutTestCase_BenchmarkVolatility(ConstantVolatilityStandardEuropeanOptionConfiguration optionSpecification, double optionValue)
        {
            double tolerance;
            Func <ConstantVolatilityStandardEuropeanOptionConfiguration, double, ToleranceLevel> testLevel;

            var objectUnderTest = GetPutOptionImpliedVolatilityApproach(out tolerance, out testLevel);

            Assume.That(objectUnderTest, Is.Not.Null, "Object under test does not support the specific option type.");

            double actual;
            var    actualState = objectUnderTest.TryGetValue(optionSpecification.Strike, optionSpecification.Forward, optionSpecification.TimeToExpiry, optionValue / optionSpecification.DiscountFactor, out actual);

            if (testLevel != null)
            {
                var toleranceLevel = testLevel(optionSpecification, optionValue);
                if (toleranceLevel == ToleranceLevel.IgnoreTestIfUnsuitableProblem)
                {
                    Assume.That(actualState, Is.EqualTo(ImpliedCalculationResultState.ProperResult) | Is.EqualTo(ImpliedCalculationResultState.InputError), "Algorithm does not support the implied volatility calculation of the specific option! The algorithm is somehow restricted!");
                }
            }
            Assert.That(actual, Is.EqualTo(optionSpecification.Volatility).Within(tolerance));
            Assert.That(actualState, Is.EqualTo(ImpliedCalculationResultState.ProperResult));
        }
예제 #3
0
 /// <summary>Gets the price of the specific option.
 /// </summary>
 /// <param name="optionSpecification">The specification of the option.</param>
 /// <returns>The value of the specific option.</returns>
 private static double GetCalllValue(ConstantVolatilityStandardEuropeanOptionConfiguration optionSpecification)
 {
     return(new BlackEuropeanCall(optionSpecification.Strike, optionSpecification.Forward, optionSpecification.TimeToExpiry, optionSpecification.DiscountFactor).GetValue(optionSpecification.Volatility));
 }