/// <summary> /// Initializes a new instance of the <see cref="PriceableFxSpotRate"/> class. /// </summary> /// <param name="notionalAmount">The notional.</param> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="fxRateAsset">The asset itself</param> /// <param name="fixingCalendar">The fixing Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="fxForward">The forward points.</param> public PriceableFxSpotRate(DateTime baseDate, decimal notionalAmount, FxSpotNodeStruct nodeStruct, FxRateAsset fxRateAsset, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fxForward) : base(baseDate, "2D", notionalAmount, nodeStruct, fxRateAsset, fixingCalendar, paymentCalendar, fxForward) { AdjustedStartDate = baseDate;//GetSpotDate(); AdjustedEffectiveDate = AdjustedStartDate; RiskMaturityDate = GetSpotDate(AdjustedStartDate, fixingCalendar, nodeStruct.SpotDate); }
///// <summary> ///// Initializes a new instance of the <see cref="PriceableFxONRate"/> class. ///// </summary> ///// <param name="baseDate">The base date.</param> ///// <param name="spotDateOffset">The business day adjustments.</param> ///// <param name="fxRateAsset"></param> ///// <param name="fxForward">The forward points.</param> //public PriceableFxONRate(DateTime baseDate, RelativeDateOffset spotDateOffset, FxRateAsset fxRateAsset, BasicQuotation fxForward) // : this(1.0m, baseDate, fxRateAsset, // spotDateOffset, fxForward) //{} /// <summary> /// Initializes a new instance of the <see cref="PriceableFxONRate"/> class. /// </summary> /// <param name="notionalAmount">The notional.</param> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="fxRateAsset">The asset itself</param> /// <param name="fixingCalendar">The fixing Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="fxForward">The forward points.</param> public PriceableFxONRate(DateTime baseDate, decimal notionalAmount, FxSpotNodeStruct nodeStruct, FxRateAsset fxRateAsset, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fxForward) : base(baseDate, "1D", notionalAmount, nodeStruct, fxRateAsset, fixingCalendar, paymentCalendar, fxForward) { AdjustedStartDate = baseDate; AdjustedEffectiveDate = baseDate; RiskMaturityDate = baseDate; //fixingCalendar.Advance(AdjustedStartDate, OffsetHelper.FromInterval(Tenor, DayTypeEnum.Business), SpotDateOffset.businessDayConvention); //baseDate;// GetForwardDate(); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableFxSpotRate"/> class. /// </summary> /// <param name="notionalAmount">The notional.</param> /// <param name="baseDate">The base date.</param> /// <param name="tenor">The tenor.</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="fxRateAsset">The asset itself</param> /// <param name="fixingCalendar">The fixing Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="fxForward">The forward points.</param> public PriceableFxForwardRate(DateTime baseDate, string tenor, decimal notionalAmount, FxSpotNodeStruct nodeStruct, FxRateAsset fxRateAsset, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fxForward) { PaymentDiscountFactorCcy12 = 1.0m; PaymentDiscountFactorCcy1 = 1.0m; Ccy2CurveName = string.Empty; Ccy1CurveName = string.Empty; ModelIdentifier = "SimpleFxRateAsset"; Id = fxRateAsset.id; Tenor = PeriodHelper.Parse(tenor); NotionalAmount = notionalAmount; FxRateAsset = fxRateAsset; BaseDate = baseDate; SpotDateOffset = nodeStruct.SpotDate; AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, nodeStruct.SpotDate);//GetSpotDate(); AdjustedEffectiveDate = AdjustedStartDate; RiskMaturityDate = GetEffectiveDate(AdjustedStartDate, paymentCalendar, Tenor, nodeStruct.SpotDate.businessDayConvention); SetRate(fxForward); }
/// <summary> /// Gets the spot date relative to the date provided. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace"></param> /// <param name="baseDate"></param> /// <param name="fixingCalendar"></param> /// <param name="rollCalendar"></param> /// <returns></returns> public DateTime GetSpotDate(ILogger logger, ICoreCache cache, string nameSpace, DateTime baseDate, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) { //var bq = BasicQuotationHelper.Create(.79m, "MarketQuote"); no magic constants in code var bq = BasicQuotationHelper.Create(0, "MarketQuote"); var bav = BasicAssetValuationHelper.Create(bq); //var quotedCurrencyPair = commodityCurveId.QuotedCurrencyPair; var quotedCurrencyPair = ((FpML.V5r10.Reporting.FxCurve)GetFpMLData().First).quotedCurrencyPair; var identifier = quotedCurrencyPair.currency1.Value + quotedCurrencyPair.currency2.Value + "-CommoditySpot-SP"; var fxspot = new FxRateAsset { id = identifier, currency = new IdentifiedCurrency { Value = quotedCurrencyPair.currency1.Value }, quotedCurrencyPair = quotedCurrencyPair }; var priceableAsset = (IPriceableCommodityAssetController)PriceableAssetFactory.Create(logger, cache, nameSpace, fxspot.id, baseDate, bav, fixingCalendar, rollCalendar); var spot = priceableAsset.GetRiskMaturityDate(); return(spot); }
/// <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, Helpers.BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray()))); }
/// <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); }