/// <summary> /// Parses the data. /// </summary> /// <param name="instrumentIds"></param> /// <returns></returns> public static QuotedAssetSet Parse(string[] instrumentIds) { var quotedAssetSetFactory = new QuotedAssetSetFactory(); const string rateQuotationType = "MarketQuote"; for (var i = 0; i < instrumentIds.Length; i++) { Asset underlyingAsset; var instrumentId = instrumentIds[i]; var results = instrumentIds[i].Split('-'); var instrument = results[1]; var listBasicQuotations = new List <BasicQuotation>(); const string priceUnitDecimalRate = "DecimalRate"; switch (instrument) { case "ZeroRate": { underlyingAsset = new Cash { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } case "Xibor": case "OIS": { var tenor = results[2]; underlyingAsset = new RateIndex { id = instrumentId, term = Period.Parse(tenor) }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } case "IRSwap": case "XccySwap": case "SimpleIRSwap": { underlyingAsset = new SimpleIRSwap { id = instrumentId, term = Period.Parse(results[2]) }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } case "Deposit": case "XccyDepo": case "BankBill": { underlyingAsset = new Deposit { id = instrumentId, term = Period.Parse(results[2]) }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } case "SimpleFra": case "Fra": case "BillFra": { var index = results[3]; var asset = new SimpleFra { id = instrumentId, startTerm = Period.Parse(results[2]) }; asset.endTerm = asset.startTerm.Sum(Period.Parse(index)); underlyingAsset = asset; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } case "IRFuture": { underlyingAsset = new Future { id = instrumentId }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); listBasicQuotations.Add(BasicQuotationHelper.Create("Volatility", "LognormalVolatility")); break; } case "CPIndex": { var tenor = results[2]; underlyingAsset = new RateIndex { id = instrumentId, term = Period.Parse(tenor) }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } case "SimpleCPISwap": case "CPISwap": case "ZCCPISwap": { underlyingAsset = new SimpleIRSwap { id = instrumentId, term = Period.Parse(results[2]) }; listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate)); break; } default: throw new NotSupportedException(string.Format("Asset type {0} is not supported", instrument)); } quotedAssetSetFactory.AddAssetAndQuotes(underlyingAsset, BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray())); } return(quotedAssetSetFactory.Create()); }
/// <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 = "MarketQuote"; Asset underlyingAsset; var results = instrumentId.Split('-'); var instrument = results[1]; var listBasicQuotations = new List <BasicQuotation>(); switch (instrument) { case "ZeroRate": { var zeroRate = new Cash { id = instrumentId }; underlyingAsset = zeroRate; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); break; } case "Xibor": case "OIS": { var tenor = results[2]; var rateIndex = new RateIndex { id = instrumentId, term = Period.Parse(tenor) }; underlyingAsset = rateIndex; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate")); break; } case "IRSwap": case "XccySwap": case "SimpleIRSwap": { var simpleIRSwap = new SimpleIRSwap { id = instrumentId, term = Period.Parse(results[2]) }; underlyingAsset = simpleIRSwap; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate")); break; } case "Deposit": case "XccyDepo": case "BankBill": { var deposit = new Deposit { id = instrumentId, term = Period.Parse(results[2]) }; underlyingAsset = deposit; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate")); break; } case "SimpleFra": case "Fra": case "BillFra": case "SpreadFra": { var index = results[3]; var asset = new SimpleFra { id = instrumentId, startTerm = Period.Parse(results[2]) }; asset.endTerm = asset.startTerm.Sum(Period.Parse(index)); underlyingAsset = asset; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate")); break; } case "IRCap": { var simpleIRCap = new SimpleIRSwap { id = instrumentId, term = Period.Parse(results[2]) }; underlyingAsset = simpleIRCap; listBasicQuotations.Add(BasicQuotationHelper.Create(value, "Premium", "Amount")); break; } case "IRFuture": { var future = new Future { id = instrumentId }; underlyingAsset = future; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); listBasicQuotations.Add(BasicQuotationHelper.Create(adjustment, "Volatility", "LognormalVolatility")); break; } case "CommodityFuture": { var future = new Future { id = instrumentId }; underlyingAsset = future; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate")); break; } case "CPIndex": { var tenor = results[2]; var rateIndex = new RateIndex { id = instrumentId, term = Period.Parse(tenor) }; underlyingAsset = rateIndex; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate")); break; } case "SimpleCPISwap": case "CPISwap": case "ZCCPISwap": { var simpleIRSwap = new SimpleIRSwap { id = instrumentId, term = Period.Parse(results[2]) }; underlyingAsset = simpleIRSwap; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate")); break; } case "FxSpot": case "FxForward": { // var tenor = results[2]; var fxRateAsset = new FxRateAsset { id = instrumentId }; underlyingAsset = fxRateAsset; listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "FxRate")); break; } case "CommoditySpot": case "CommodityForward": { var commodityAsset = new FxRateAsset { id = instrumentId }; underlyingAsset = commodityAsset; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "Price")); break; } case "Bond": { var asset = new Bond { id = instrumentId }; underlyingAsset = asset; listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DirtyPrice")); break; } default: throw new NotSupportedException(string.Format("Asset type {0} is not supported", instrument)); } return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray()))); }