/// <summary> /// Compute the SABR implied volatility at a user defined asset price, /// exercise time and strike. /// </summary> /// <param name="assetPrice">Price of the relevant asset. /// Precondition: assetPrice > 0.0.</param> /// <param name="exerciseTime">Time to option exercise. /// Precondition: exerciseTime > 0.0.</param> /// <param name="strike">Option strike price. /// Precondition: strike > 0.0.</param> /// <param name="errorMessage">Container for any possible error /// message.</param> /// <param name="result">Container to store the result(SABR implied /// volatility.</param> /// <param name="checkImpliedVolParameters">If set to <c>true</c> then /// a check of the implied volatility parameters is performed.</param> /// <returns> /// True if SABR implied volatility computed, else /// false. /// </returns> public bool SABRInterpolatedVolatility(double assetPrice, double exerciseTime, double strike, ref string errorMessage, ref double result, bool checkImpliedVolParameters) { // Declare and initialise the return variable. var success = false; // Ensure that asset parameters are checked only if required. var areAssetParametersValid = true; if (checkImpliedVolParameters) { areAssetParametersValid = ImpliedVolatilityParameters.CheckImpliedVolatilityParameters( assetPrice, exerciseTime, strike, ref errorMessage); } if (areAssetParametersValid) { // Valid asset parameters: compute the SABR interpolated // volatility. var z = ComputeZ(assetPrice, strike); var x = ComputeX(z); result = ComputeSigma(assetPrice, exerciseTime, strike, x, z); // Update the return variable to indicate successful completion. success = true; errorMessage = ""; } return(success); }
/// <summary> /// Tests the static method CheckExerciseTime. /// </summary> public void TestCheckExerciseTime() { _exerciseTime = -5.0d; _isValidImpliedVolatilityParameter = ImpliedVolatilityParameters.CheckExerciseTime(_exerciseTime, ref _errorMessage); const string expected = "Exercise time cannot be negative."; Assert.IsFalse(_isValidImpliedVolatilityParameter); Assert.AreEqual(expected, _errorMessage); }
public void TestCheckStrike() { _strike = 0.0d; _isValidImpliedVolatilityParameter = ImpliedVolatilityParameters.CheckStrike(_strike, ref _errorMessage); const string expected = "Strike must be positive."; Assert.IsFalse(_isValidImpliedVolatilityParameter); Assert.AreEqual(expected, _errorMessage); }
public void TestCheckAssetPrice() { _assetPrice = -3.98d / 100.0d; _isValidImpliedVolatilityParameter = ImpliedVolatilityParameters.CheckAssetPrice(_assetPrice, ref _errorMessage); const string expected = "Asset price must be positive."; Assert.IsFalse(_isValidImpliedVolatilityParameter); Assert.AreEqual(expected, _errorMessage); }