public void DiscountFactorsTest() { string matrixId = _id; string[] expiry = _expiry; string[] volType = _type; decimal[][] vols = _vols; decimal[] strikes = _strike; DateTime valueDate = _valdate; DateTime[] discountFactorDates = _factorDates; decimal[] discountFactors = _factors; try { CapFloorVolatilityMatrix target = new CapFloorVolatilityMatrix(matrixId, expiry, volType, vols, strikes, discountFactorDates, discountFactors); Assert.IsNotNull(target); DateTime expectedDate = DateTime.Parse("30-Aug-17"); decimal expectedDF = 0.520110M; SortedList <DateTime, decimal> actual = target.DiscountFactors(); Assert.AreEqual(true, actual.ContainsValue(expectedDF)); Assert.AreEqual(true, actual.ContainsKey(expectedDate)); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void StrikesTest() { string matrixId = _id; string[] expiry = _expiry; string[] volType = _type; decimal[][] vols = _vols; decimal[] strikes = _strike; DateTime valueDate = _valdate; DateTime[] discountFactorDates = _factorDates; decimal[] discountFactors = _factors; try { CapFloorVolatilityMatrix target = new CapFloorVolatilityMatrix(matrixId, expiry, volType, vols, strikes, discountFactorDates, discountFactors); Assert.IsNotNull(target); int i = 0; decimal[] actual = target.Strikes(); foreach (decimal element in actual) { Assert.AreEqual(strikes[i++], element); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void CapFloorLoadTest() { Assembly assembly = Assembly.GetExecutingAssembly(); string expectedXml = ResourceHelper.GetResourceWithPartialName(assembly, _testFile); // Load as a full CapFloor Matrix CapFloorVolatilityMatrix cfMatrix = XmlSerializerHelper.DeserializeFromString <CapFloorVolatilityMatrix>(expectedXml); Assert.IsNotNull(cfMatrix); }
public void CapVolatilitiesTest1() { CapFloorVolatilityMatrix target = new CapFloorVolatilityMatrix(_id, _expiry, _type, _ATMVols, null, _factorDates, _factors); Assert.IsNotNull(target); decimal[] expectedVolatilities = new decimal[] { 0, 0, 0, 0, 0, 18.16M, 17.94M, 17.62M, 17.09M, 15.77M, 14.21M }; int[] term = new int[] { 0, 8, 99, 190, 281, 2, 3, 4, 5, 7, 10 }; int i = 0; List <CapVolatilityDataElement <int> > actual = target.CapVolatilities(); foreach (CapVolatilityDataElement <int> element in actual) { Assert.AreEqual(expectedVolatilities[i], element.Volatility); Assert.AreEqual(term[i++], element.Expiry); } }
public void CapVolatilitiesTest() { string matrixId = _id; string[] expiry = _expiry; string[] volType = _type; decimal[][] vols = _vols; decimal[] strikes = _strike; DateTime valueDate = _valdate; DateTime[] discountFactorDates = _factorDates; decimal[] discountFactors = _factors; try { CapFloorVolatilityMatrix target = new CapFloorVolatilityMatrix(matrixId, expiry, volType, vols, strikes, discountFactorDates, discountFactors); Assert.IsNotNull(target); decimal strike = 7.5m; decimal[] expectedVolatilities = new decimal[] { 8.82m, 8.82m, 9.12m, 9.43m, 9.71m, 10.34m, 10.75m, 10.84m, 10.93m, 10.95m, 10.99m }; int[] term = new int[] { 0, 8, 99, 190, 281, 2, 3, 4, 5, 7, 10 }; int i = 0; List <CapVolatilityDataElement <int> > actual = target.CapVolatilities(strike); foreach (CapVolatilityDataElement <int> element in actual) { Assert.AreEqual(expectedVolatilities[i], element.Volatility); Assert.AreEqual(term[i++], element.Expiry); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
/// <summary> /// Create a Sortedlist of bootstrap engines from the data matrix /// </summary> /// <param name="logger">The logger</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace"></param> /// <param name="engineHandle">The engine collection name</param> /// <param name="matrix">The internal data structure used in conversion</param> /// <param name="properties">The properties object to use</param> /// <returns></returns> private static SortedList <decimal, CapVolatilityCurve> CreateEngines(ILogger logger, ICoreCache cache, string nameSpace, string engineHandle, CapFloorVolatilityMatrix matrix, NamedValueSet properties) { var engines = new SortedList <decimal, CapVolatilityCurve>(); // Check there is a valid settings object if (properties == null) { return(null); } var currency = properties.GetString("Currency", true); var baseDate = properties.GetValue("Calculation Date", DateTime.MinValue); properties.Set("EngineHandle", engineHandle); matrix.ValuationDate = baseDate; var valuationDate = properties.GetValue("ValuationDate", DateTime.MinValue); if (valuationDate == DateTime.MinValue) { properties.Set("ValuationDate", baseDate); } properties.Set("PricingStructureType", PricingStructureTypeEnum.CapVolatilityCurve.ToString()); var strikeQuoteUnits = properties.GetString("StrikeQuoteUnits", null); if (strikeQuoteUnits == null) { properties.Set("StrikeQuoteUnits", StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString()); } var measureType = properties.GetString("MeasureType", null); if (measureType == null) { properties.Set("MeasureType", MeasureTypesEnum.Volatility.ToString()); } var quoteUnits = properties.GetString("QuoteUnits", null); if (quoteUnits == null) { properties.Set("QuoteUnits", QuoteUnitsEnum.LogNormalVolatility.ToString()); } var algorithm = properties.GetString("Algorithm", null); if (algorithm == null) { properties.Set("Algorithm", "Default"); } InterpolationMethod interp = InterpolationMethodHelper.Parse("LogLinearInterpolation"); var dfs = matrix.DiscountFactorsAsDoubles(); // Check there are valid strikes IRateCurve discountCurve = new SimpleDiscountFactorCurve(baseDate, interp, true, dfs); //TODO //The quoted asset set var volTypes = matrix.CapVolatilities(); var instruments = new List <string>(); var volatilties = new List <decimal>(); foreach (var volType in volTypes) { string tempName; string tenor; var type = volType.VolatilityType; if (type == VolatilityDataType.ETO) { tempName = currency + "-Caplet-"; tenor = volType.Expiry + "D-90D"; } else { tempName = currency + "-IRCap-"; tenor = volType.Expiry + "Y"; } instruments.Add(tempName + tenor); volatilties.Add(volType.Volatility); } var qas = AssetHelper.Parse(instruments.ToArray(), volatilties.ToArray()); //The volatilities // Create a new ATM CapletBootstrap engine. The default decimal should be 0 var engine = new CapVolatilityCurve(logger, cache, nameSpace, properties, qas, discountCurve, discountCurve, null, null); // Add engine engines.Add(0, engine); return(engines); }
/// <summary> /// Process a CapFloor ATM parvVols structure. /// The process Bootstraps the parVols using the supplied ratecurve /// </summary> /// <param name="logger">The logger</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace"></param> /// <param name="rateCurve"></param> /// <param name="capFloor"></param> /// <returns></returns> private static Market ProcessCapFloorATM(ILogger logger, ICoreCache cache, string nameSpace, Market rateCurve, CapFloorATMMatrix capFloor) { var id = capFloor.id; var expiry = capFloor.GetExpiries(); var vols = capFloor.GetVolatilities(); var mkt = rateCurve; var curve = new SimpleRateCurve(mkt); var discountFactorDates = curve.GetDiscountFactorDates(); var discountFactors = curve.GetDiscountFactors(); var volType = capFloor.GetVolatilityTypes(); var atmVols = new Dictionary <string, decimal>(); var settings = CreateCapFloorProperties(capFloor.GetVolatilitySettings()); // Create an internal matrix object from the raw data var matrix = new CapFloorVolatilityMatrix(id, expiry, volType, vols, null, discountFactorDates, ArrayUtilities.ArrayToDecimal(discountFactors)); // Create an ATM engine from the matrix var engines = CreateEngines(logger, cache, nameSpace, id, matrix, settings); // Add the default interpolation to use const ExpiryInterpolationType volatilityInterpolation = ExpiryInterpolationType.Linear; if (engines != null) { var vol = new CapletExpiryInterpolatedVolatility(engines[0], volatilityInterpolation); // List the values so we can build our ATM vols var keys = ExpiryKeys.Split(','); // Create a calendar to use to modify the date var businessCalendar = settings.GetValue("BusinessCalendar", "AUSY"); var bc = BusinessCenterHelper.ToBusinessCalendar(cache, new[] { businessCalendar }, nameSpace); // Use some logic to get the spot date to use // LPM Spot lag is 2 days (modfollowing) var spotDate = curve.GetSpotDate(); var rollConvention = settings.GetValue("RollConvention", BusinessDayConventionEnum.FOLLOWING); spotDate = spotDate == curve.GetBaseDate() ? bc.Roll(spotDate.Add(new TimeSpan(2, 0, 0, 0)), rollConvention) : spotDate; //// Extract each surface and build an ATM engine therefrom //// Build a list of all possible engines foreach (var key in keys) { // Calculate the volatility for each target key var tv = PeriodHelper.Parse(key); var target = tv.period == PeriodEnum.D ? bc.Roll(spotDate.AddDays(Convert.ToInt32(tv.periodMultiplier)), rollConvention) : bc.Roll(spotDate.AddMonths(Convert.ToInt32(tv.periodMultiplier)), rollConvention); atmVols.Add(key, vol.ComputeCapletVolatility(target)); } } var outputVols = new object[atmVols.Count + 1, 2]; var i = 1; //Expiry 0 outputVols[0, 0] = "Expiry"; outputVols[0, 1] = "0"; foreach (var key in atmVols.Keys) { outputVols[i, 0] = key; outputVols[i, 1] = atmVols[key]; i++; } DateTime buildDateTime = rateCurve.Items1[0].buildDateTime; var volSurface = new VolatilitySurface(outputVols, new VolatilitySurfaceIdentifier(id), curve.BaseDate, buildDateTime); return(CreateMarketDocument(volSurface.GetFpMLData())); }