/// <summary> /// Creates a QuotedAssetSet from a set of instrument ids and sides, all with measureType set to MarketQuote /// and QuoteUnits set to DecimalRate (useful for building market data requests). /// </summary> /// <param name="instrIds">The (m) instrument ids.</param> /// <param name="sides">The (n) sides.</param> /// <returns>An M * N matrix of assets/quotes in a QuotedAssetSet</returns> public static QuotedAssetSet Parse(string[] instrIds, string[] sides) { var assetList = new List <Asset>(); var quoteList = new List <BasicAssetValuation>(); var types = new List <ItemsChoiceType19>(); foreach (string instrId in instrIds) { Asset asset = CreateAsset(instrId); assetList.Add(asset); quoteList.AddRange(sides.Select(side => BasicQuotationHelper.Create("MarketQuote", "DecimalRate", side)).Select(quote => new BasicAssetValuation { objectReference = new AnyAssetReference { href = asset.id }, quote = new[] { quote } })); var properties = new PriceableAssetProperties(asset.id); var assetTypeFpML = AssetTypeConvertor.ParseEnumStringToFpML(properties.AssetType.ToString()); types.Add(assetTypeFpML); } var instrumentSet = new InstrumentSet { Items = assetList.ToArray(), ItemsElementName = types.ToArray() }; return(new QuotedAssetSet { instrumentSet = instrumentSet, assetQuote = quoteList.ToArray() }); }
public QuotedAssetSet Create() { var result = new QuotedAssetSet(); var assets = new List <Asset>(); var quotes = new List <BasicAssetValuation>(); var types = new List <ItemsChoiceType19>(); foreach (Pair <Asset, BasicAssetValuation> assetAndQuote in _assetAndQuotes) { assets.Add(assetAndQuote.First); quotes.Add(assetAndQuote.Second); //Handles the case of tenor curves var id = assetAndQuote.First?.id ?? assetAndQuote.Second?.objectReference?.href; var properties = new PriceableAssetProperties(id); var assetTypeFpML = AssetTypeConvertor.ParseEnumStringToFpML(properties.AssetType.ToString()); types.Add(assetTypeFpML); } var instrumentSet = new InstrumentSet { Items = assets.ToArray(), ItemsElementName = types.ToArray() }; result.instrumentSet = instrumentSet; result.assetQuote = quotes.ToArray(); return(result); }
/// <summary> /// Creates a quoted asset set without the asset type specified. /// </summary> /// <param name="assetType">The asset Type to remove.</param> /// <param name="assetSet">The original assetSet</param> /// <returns></returns> public static QuotedAssetSet RemoveAssetsFromQuotedAssetSet(AssetTypesEnum assetType, QuotedAssetSet assetSet) { var assets = new List <Asset>(); var quotes = new List <BasicAssetValuation>(); var types = new List <ItemsChoiceType19>(); var index = 0; foreach (var asset in assetSet.instrumentSet.Items) { var tempAssetType = new PriceableAssetProperties(asset.id).AssetType; if (tempAssetType != assetType) { assets.Add(asset); quotes.Add(assetSet.assetQuote[index]); if (assetSet.instrumentSet.ItemsElementName != null) { types.Add(assetSet.instrumentSet.ItemsElementName[index]); } else { var assetTypeFpML = AssetTypeConvertor.ParseEnumStringToFpML(tempAssetType.ToString()); types.Add(assetTypeFpML); } } index++; } var instrumentSet = new InstrumentSet { Items = assets.ToArray(), ItemsElementName = types.ToArray() }; return(new QuotedAssetSet { instrumentSet = instrumentSet, assetQuote = quotes.ToArray() }); }
/// <summary> /// Maps from a list of asset pairs to a quoted asset set. /// </summary> /// <param name="assetPairs"></param> /// <returns></returns> internal static QuotedAssetSet MapFromAssetPairs(ICollection <Pair <Asset, BasicAssetValuation> > assetPairs) { var quotedAssetSet = new QuotedAssetSet(); var assets = new Asset[assetPairs.Count]; var basicAssetValuations = new BasicAssetValuation[assetPairs.Count]; var types = new List <ItemsChoiceType19>(); var index = 0; foreach (var pair in assetPairs) { assets[index] = pair.First; basicAssetValuations[index] = pair.Second; var properties = new PriceableAssetProperties(assets[index].id); var assetTypeFpML = AssetTypeConvertor.ParseEnumStringToFpML(properties.AssetType.ToString()); types.Add(assetTypeFpML); index++; } quotedAssetSet.assetQuote = basicAssetValuations; var instrumentSet = new InstrumentSet { Items = assets.ToArray(), ItemsElementName = types.ToArray() }; quotedAssetSet.instrumentSet = instrumentSet; return(quotedAssetSet); }
public RatesObj(Asset asset, BasicAssetValuation bav) { Created = DateTime.Now; Publisher = "Alex"; Instrument = asset.GetType().Name; var identifier = new PriceableAssetProperties(asset.id); if (asset is Deposit asset1) { var deposit = asset1; InstrumentId = deposit.id; Currency = identifier.Currency; Term = deposit.term.ToString(); } else { if (asset is SimpleIRSwap irSwap) { var swap = irSwap; InstrumentId = swap.id; Currency = identifier.Currency; Term = swap.term.ToString(); } else { if (asset is Future future1) { var future = future1; InstrumentId = future.id; Currency = identifier.Currency; Term = identifier.Term; } } } if (bav.quote.Length > 0) { Rate1 = bav.quote[0].value; if (bav.quote[0].quoteUnits != null) { Rate1Quotes = bav.quote[0].quoteUnits.Value; } if (bav.quote[0].measureType != null) { Rate1Measure = bav.quote[0].measureType.Value; } } if (bav.quote.Length > 1) { Rate2 = bav.quote[1].value; if (bav.quote[1].quoteUnits != null) { Rate2Quotes = bav.quote[1].quoteUnits.Value; } if (bav.quote[1].measureType != null) { Rate2Measure = bav.quote[1].measureType.Value; } } }
public FxRateSet CreateFxRateSet() { var result = new FxRateSet(); var assets = new List <Asset>(); var quotes = new List <BasicAssetValuation>(); var types = new List <ItemsChoiceType19>(); foreach (Pair <Asset, BasicAssetValuation> assetAndQuote in _assetAndQuotes) { assets.Add(assetAndQuote.First); quotes.Add(assetAndQuote.Second); var properties = new PriceableAssetProperties(assetAndQuote.First.id); var assetTypeFpML = AssetTypeConvertor.ParseEnumStringToFpML(properties.AssetType.ToString()); types.Add(assetTypeFpML); } var instrumentSet = new InstrumentSet { Items = assets.ToArray(), ItemsElementName = types.ToArray() }; result.instrumentSet = instrumentSet; result.assetQuote = quotes.ToArray(); return(result); }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="nameSpace"></param> /// <param name="properties"></param> /// <param name="expiries"></param> /// <param name="vols"></param> /// <param name="inputInstruments"></param> /// <param name="inputSwapRates"></param> /// <param name="inputBlackVolRates"></param> protected ExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, DateTime[] expiries, double[] vols, string[] inputInstruments, double[] inputSwapRates, double[] inputBlackVolRates) { Algorithm = PropertyHelper.ExtractAlgorithm(properties); PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties); var surfaceId = (VolatilitySurfaceIdentifier)PricingStructureIdentifier; var expiryLength = expiries.Length; var pointIndex = 0; var points = new PricingStructurePoint[expiryLength]; _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey()); for (var expiryIndex = 0; expiryIndex < expiryLength; expiryIndex++) { // extract the current expiry var expiryKeyPart = expiries[expiryIndex]; var key = new ExpiryTenorStrikeKey(expiryKeyPart.ToString(CultureInfo.InvariantCulture), 0); _matrixIndexHelper.Add(key, pointIndex); // Add the value to the points array (dataPoints entry in the matrix) var coordinates = new PricingDataPointCoordinate[1]; coordinates[0] = new PricingDataPointCoordinate { expiration = new TimeDimension[1] }; coordinates[0].expiration[0] = new TimeDimension { Items = new object[] { expiries[expiryIndex] } }; var pt = new PricingStructurePoint { value = (decimal)vols[expiryIndex], valueSpecified = true, coordinate = coordinates, }; points[pointIndex++] = pt; } // Record the row/column sizes of the inputs _matrixRowCount = expiries.Length; _matrixColumnCount = 1; PricingStructure = CreateVolatilityRepresentation(surfaceId); PricingStructureValuation = CreateDataPoints(points, surfaceId); if (inputInstruments != null) { int inputCount = inputInstruments.GetUpperBound(0); var assetQuotes = new List <BasicAssetValuation>(); var assetSet = new List <Asset>(); var itemsList = new List <ItemsChoiceType19>(); for (int i = 0; i <= inputCount; i++) { var assetProperties = new PriceableAssetProperties(inputInstruments[i]); assetSet.Add(new SimpleIRSwap { id = inputInstruments[i], term = assetProperties.TermTenor }); var rateQuote = BasicQuotationHelper.Create((decimal)inputSwapRates[i], AssetMeasureEnum.MarketQuote, PriceQuoteUnitsEnum.DecimalRate); var volQuote = BasicQuotationHelper.Create((decimal)inputBlackVolRates[i], AssetMeasureEnum.Volatility, PriceQuoteUnitsEnum.LogNormalVolatility); assetQuotes.Add(new BasicAssetValuation { objectReference = new AnyAssetReference { href = inputInstruments[i] }, definitionRef = assetProperties.TermTenor.ToString(), quote = new[] { rateQuote, volQuote } }); itemsList.Add(ItemsChoiceType19.simpleIrSwap);//TODO NOt actually correct. } var instrumentSet = new InstrumentSet { Items = assetSet.ToArray(), ItemsElementName = itemsList.ToArray() }; ((VolatilityMatrix)PricingStructureValuation).inputs = new QuotedAssetSet { assetQuote = assetQuotes.ToArray(), instrumentSet = instrumentSet }; } // Generate an interpolator to use double[] expiryTerms = expiries.Select(a => (surfaceId.BaseDate - a).TotalDays / 365d).ToArray(); var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm); var curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation")); Interpolator = new VolSurfaceInterpolator(expiryTerms, new double[] { 1 }, new Matrix(vols), curveInterpolationMethod, true); }
/// <summary> /// Parses the string info into an asset. /// </summary> /// <param name="instrumentId"></param> /// <param name="value"></param> /// <param name="adjustment"></param> /// <returns></returns> public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal?adjustment) { const string rateQuotationType = PriceableSimpleRateAsset.RateQuotationType; const string volatilityQuotationType = PriceableCapRateAsset.VolatilityQuotationType; Asset underlyingAsset; decimal additional = 0.0m; if (adjustment != null) { additional = (decimal)adjustment; } var listBasicQuotations = new List <BasicQuotation>(); var properties = new PriceableAssetProperties(instrumentId); switch (properties.AssetType) { //This is in place to handle volatility curves where the tenor is the expiry. case AssetTypesEnum.Period: { //There is no underlying asset. underlyingAsset = null; listBasicQuotations.Add(BasicQuotationHelper.Create(instrumentId, value, volatilityQuotationType, "LognormalVolatility")); break; } case AssetTypesEnum.ZeroRate: { underlyingAsset = new Cash { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.Xibor: case AssetTypesEnum.OIS: { underlyingAsset = new RateIndex { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.IRSwap: case AssetTypesEnum.ClearedIRSwap: case AssetTypesEnum.OISSwap: case AssetTypesEnum.XccySwap: case AssetTypesEnum.SimpleIRSwap: case AssetTypesEnum.XccyBasisSwap: case AssetTypesEnum.BasisSwap: case AssetTypesEnum.ResettableXccyBasisSwap: { underlyingAsset = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.Caplet: case AssetTypesEnum.Floorlet: case AssetTypesEnum.BillCaplet: case AssetTypesEnum.BillFloorlet: { underlyingAsset = new SimpleFra { id = instrumentId, startTerm = properties.TermTenor, endTerm = properties.TermTenor.Sum(properties.ForwardIndex) }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility")); if (adjustment != null) { listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate")); } break; } case AssetTypesEnum.Deposit: case AssetTypesEnum.SpreadDeposit: case AssetTypesEnum.XccyDepo: case AssetTypesEnum.BankBill: case AssetTypesEnum.Repo: case AssetTypesEnum.RepoSpread: { underlyingAsset = new Deposit { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.SimpleFra: case AssetTypesEnum.Fra: case AssetTypesEnum.BillFra: case AssetTypesEnum.SpreadFra: { underlyingAsset = new SimpleFra { id = instrumentId, startTerm = properties.TermTenor, endTerm = properties.TermTenor.Sum(properties.ForwardIndex) //TODO this restricts the perios to be the same!!! }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.Swaption: { underlyingAsset = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility")); if (adjustment != null) { listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate")); } break; } case AssetTypesEnum.IRFloor: case AssetTypesEnum.IRCap: { underlyingAsset = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility")); if (adjustment != null) { listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate")); } break; } case AssetTypesEnum.IRFutureOption: case AssetTypesEnum.IRCallFutureOption: case AssetTypesEnum.IRPutFutureOption: { underlyingAsset = new Future { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility")); if (adjustment != null) { listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate")); } break; } case AssetTypesEnum.IRFuture: { underlyingAsset = new Future { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); if (adjustment != null) { listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Volatility", "LognormalVolatility")); } break; } case AssetTypesEnum.CommodityFuture: case AssetTypesEnum.CommodityFutureSpread: { underlyingAsset = new Future { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.CPIndex: { underlyingAsset = new RateIndex { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.SimpleCPISwap: case AssetTypesEnum.CPISwap: case AssetTypesEnum.ZCCPISwap: { underlyingAsset = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate")); break; } case AssetTypesEnum.FxSpot: case AssetTypesEnum.FxForward: { underlyingAsset = new FxRateAsset { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "FxRate")); break; } case AssetTypesEnum.Equity: case AssetTypesEnum.EquityForward: { underlyingAsset = new EquityAsset { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price")); break; } case AssetTypesEnum.CommoditySpot: case AssetTypesEnum.CommodityForward: case AssetTypesEnum.CommodityAverageForward: case AssetTypesEnum.CommoditySpread: { underlyingAsset = new Commodity { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price")); break; } case AssetTypesEnum.Bond: case AssetTypesEnum.BondSpot: case AssetTypesEnum.BondForward: { underlyingAsset = new Bond { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); //Changed from DirtyPrice. break; } case AssetTypesEnum.Lease: { underlyingAsset = new Lease { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price")); break; } default: throw new NotSupportedException($"Asset type {properties.AssetType} is not supported"); } var id = underlyingAsset?.id; if (underlyingAsset == null) { id = listBasicQuotations[0].id; } return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(id, listBasicQuotations.ToArray()))); }
/// <summary> /// Parses the string info into an asset. /// </summary> /// <param name="instrumentId"></param> /// <returns></returns> public static Asset Parse(string instrumentId) { Asset underlyingAsset; var properties = new PriceableAssetProperties(instrumentId); switch (properties.AssetType) { case AssetTypesEnum.ZeroRate: { var zeroRate = new Cash { id = instrumentId }; underlyingAsset = zeroRate; break; } case AssetTypesEnum.Xibor: case AssetTypesEnum.OIS: { var rateIndex = new RateIndex { id = instrumentId, term = properties.TermTenor }; underlyingAsset = rateIndex; break; } case AssetTypesEnum.IRSwap: case AssetTypesEnum.ClearedIRSwap: case AssetTypesEnum.OISSwap: case AssetTypesEnum.XccySwap: case AssetTypesEnum.SimpleIRSwap: case AssetTypesEnum.XccyBasisSwap: case AssetTypesEnum.BasisSwap: case AssetTypesEnum.ResettableXccyBasisSwap: { var simpleIRSwap = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; underlyingAsset = simpleIRSwap; break; } case AssetTypesEnum.Deposit: case AssetTypesEnum.SpreadDeposit: case AssetTypesEnum.XccyDepo: case AssetTypesEnum.BankBill: case AssetTypesEnum.Repo: case AssetTypesEnum.RepoSpread: { var deposit = new Deposit { id = instrumentId, term = properties.TermTenor }; underlyingAsset = deposit; break; } case AssetTypesEnum.SimpleFra: case AssetTypesEnum.Fra: case AssetTypesEnum.BillFra: case AssetTypesEnum.SpreadFra: { var simpleFra = new SimpleFra { id = instrumentId, startTerm = properties.TermTenor }; if (properties.ForwardIndex == null) { throw new ArgumentException("ForwardIndex must be set in the instrumentId " + instrumentId, nameof(instrumentId)); } simpleFra.endTerm = simpleFra.startTerm.Sum(properties.ForwardIndex); underlyingAsset = simpleFra; break; } case AssetTypesEnum.IRFloor: case AssetTypesEnum.IRCap: { var simpleIRCap = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; underlyingAsset = simpleIRCap; break; } case AssetTypesEnum.IRFutureOption: case AssetTypesEnum.IRFuture: { var future = new Future { id = instrumentId }; underlyingAsset = future; break; } case AssetTypesEnum.CommodityFuture: case AssetTypesEnum.CommodityFutureSpread: { var future = new Future { id = instrumentId }; underlyingAsset = future; break; } case AssetTypesEnum.CPIndex: { var rateIndex = new RateIndex { id = instrumentId, term = properties.TermTenor }; underlyingAsset = rateIndex; break; } case AssetTypesEnum.SimpleCPISwap: case AssetTypesEnum.CPISwap: case AssetTypesEnum.ZCCPISwap: { var simpleIRSwap = new SimpleIRSwap { id = instrumentId, term = properties.TermTenor }; underlyingAsset = simpleIRSwap; break; } case AssetTypesEnum.Equity: case AssetTypesEnum.EquityForward: { // var tenor = results[2]; var equityAsset = new EquityAsset { id = instrumentId }; underlyingAsset = equityAsset; break; } case AssetTypesEnum.FxSpot: case AssetTypesEnum.FxForward: { // var tenor = results[2]; var fxRateAsset = new FxRateAsset { id = instrumentId }; underlyingAsset = fxRateAsset; break; } case AssetTypesEnum.CommoditySpot: case AssetTypesEnum.CommodityForward: case AssetTypesEnum.CommodityAverageForward: case AssetTypesEnum.CommoditySpread: { var commodityAsset = new Commodity { id = instrumentId }; underlyingAsset = commodityAsset; break; } case AssetTypesEnum.Bond: case AssetTypesEnum.BondSpot: case AssetTypesEnum.BondForward: { var bond = new Bond { id = instrumentId }; underlyingAsset = bond; break; } default: throw new NotSupportedException($"Asset type {properties.AssetType} is not supported"); } return(underlyingAsset); }