/// <summary> /// Initializes a new instance of the <see cref="PriceableXibor"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="amount">The amount.</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="fixingCalendar">The fixing Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="fixedRate">The fixedRate.</param> public PriceableOis(DateTime baseDate, Decimal amount, XiborNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, amount, nodeStruct.RateIndex, nodeStruct.BusinessDayAdjustments, nodeStruct.SpotDate, fixedRate) { AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, nodeStruct.SpotDate); RiskMaturityDate = GetEffectiveDate(AdjustedStartDate, paymentCalendar, nodeStruct.RateIndex.term, nodeStruct.BusinessDayAdjustments.businessDayConvention); YearFraction = GetYearFraction(nodeStruct.RateIndex.dayCountFraction.Value, AdjustedStartDate, RiskMaturityDate); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="simpleIRSwap">THe FpML swap.</param> /// <param name="spotDate">The spot date.</param> /// <param name="calculation">A calculation.</param> /// <param name="stringRollConvention">The roll convention.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="underlyingRateIndex">Index of the rate.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableSimpleIRSwap(DateTime baseDate, SimpleIRSwap simpleIRSwap, DateTime spotDate, Calculation calculation, String stringRollConvention, BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, businessDayAdjustments, calculation, fixedRate) { Id = simpleIRSwap.id; SimpleIRSwap = simpleIRSwap; UnderlyingRateIndex = underlyingRateIndex; AdjustedStartDate = spotDate; List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, SimpleIRSwap.paymentFrequency); AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, paymentCalendar); RiskMaturityDate = AdjustedPeriodDates[AdjustedPeriodDates.Count - 1]; Weightings = CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Count - 1); YearFractions = GetYearFractions(); ModelIdentifier = DiscountingType == null ? "SimpleSwapAsset" : "SimpleDiscountSwapAsset"; var timeToMaturity = Actual365.Instance.YearFraction(baseDate, RiskMaturityDate); EndDiscountFactor = (decimal)System.Math.Exp(-(double)fixedRate.value * timeToMaturity); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="simpleIRSwap">THe FpML swap.</param> /// <param name="spotDate">The spot date.</param> /// <param name="calculation">A calculation.</param> /// <param name="stringRollConvention">The roll convention.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="underlyingRateIndex">Index of the rate.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableIRSwap(DateTime baseDate, SimpleIRSwap simpleIRSwap, DateTime spotDate, Calculation calculation, String stringRollConvention, BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, simpleIRSwap, spotDate, calculation, stringRollConvention, businessDayAdjustments, underlyingRateIndex, fixingCalendar, paymentCalendar, fixedRate) { ModelIdentifier = DiscountingType == null ? "SwapAsset" : "DiscountSwapAsset"; //The floating leg which is now non-zero. var unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, UnderlyingRateIndex.term); FloatingLegAdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, fixingCalendar); FloatingLegWeightings = CreateWeightings(CDefaultWeightingValue, FloatingLegAdjustedPeriodDates.Count - 1); FloatingLegYearFractions = GetFloatingLegYearFractions(); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableCommodityForward"/> class. /// </summary> /// <param name="baseDate"></param> /// <param name="future"></param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="position">The number of contracts held.</param> /// <param name="commodityValue">The fixed rate.</param> /// <param name="rollOffset">The commodity contract roll offset.</param> protected PriceableCommodityFuturesAsset(DateTime baseDate, Future future, BusinessDayAdjustments businessDayAdjustments, int position, BasicQuotation commodityValue, Offset rollOffset) { ModelIdentifier = "CommoditiesFuturesAsset"; Margin = PeriodEnum.D; RollOffset = rollOffset; if (future?.multiplier != null) { Amount = int.Parse(future.multiplier); } Position = position; BaseDate = baseDate; Future = future; BusinessDayAdjustments = businessDayAdjustments; SetIndex(commodityValue); TimeToExpiry = 1.0m; CurveName = string.Empty; DayCounter = Actual365.Instance; }
/// <summary> /// Initializes a new instance of the <see cref="PriceableResettableXccyBasisSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="fixingCalendar">The fixing Calendar</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="spread">The spread.</param> public PriceableResettableXccyBasisSwap(DateTime baseDate, BasisSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation spread) : base(baseDate, nodeStruct, fixingCalendar, paymentCalendar, spread) { }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleFra"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct"></param> /// <param name="fixingCalendar"></param> /// <param name="paymentCalendar"></param> /// <param name="fixedRate">The fixed rate.</param> public PriceableSimpleRevenueInflationSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, nodeStruct.DateAdjustments, fixedRate) { Id = nodeStruct.SimpleIRSwap.id; SimpleInflationSwap = nodeStruct.SimpleIRSwap; SpotDateOffset = nodeStruct.SpotDate; Calculation = nodeStruct.Calculation; UnderlyingRateIndex = nodeStruct.UnderlyingRateIndex; AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, SpotDateOffset); DayCounter = DayCounterHelper.Parse(Calculation.dayCountFraction.Value); List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleInflationSwap.term, SimpleInflationSwap.paymentFrequency); AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, nodeStruct.DateAdjustments.businessDayConvention, paymentCalendar); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableBondAsset"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="exDivDateOffset">The exdiv offsets.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="amount">The notional amount.</param> /// <param name="currency">THe currency of the bond.</param> /// <param name="settlementDateOffset">The details to calculate the settlement date.</param> protected PriceableBondAsset(DateTime baseDate, Decimal amount, Currency currency, RelativeDateOffset settlementDateOffset, RelativeDateOffset exDivDateOffset, BusinessDayAdjustments businessDayAdjustments, BasicQuotation marketQuote) : this(baseDate, amount, currency, settlementDateOffset, exDivDateOffset, businessDayAdjustments, marketQuote, BondPriceEnum.YieldToMaturity) { }
/// <summary> /// Initializes a new instance of the <see cref="PriceableFuturesOptionAssetController"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="position">The number of contracts.</param> /// <param name="isPut">Is the option a put?</param> /// <param name="nodeStruct">The instrument</param> /// <param name="rollCalendar">The payment Calendar.</param> /// <param name="marketQuote">In the case of a future, this is a rate.</param> /// <param name="extraQuote">In the case of a future, this is the futures convexity volatility.</param> protected PriceableFuturesOptionAssetController(DateTime baseDate, int position, Boolean isPut, FutureOptionNodeStruct nodeStruct, IBusinessCalendar rollCalendar, BasicQuotation marketQuote, Decimal extraQuote) : base(baseDate, position, nodeStruct, marketQuote, extraQuote) { IsPut = isPut; Strike = extraQuote; SetQuote(VolatilityQuotationType, new List <BasicQuotation> { marketQuote }); FuturesLag = nodeStruct.SpotDate; ExpiryLag = nodeStruct.ExpiryLag; }
protected RequestContext ConvertStandardAssetQuotesToProviderInstrFieldCodes( MDSRequestType requestType, QuotedAssetSet standardQuotedAssetSet) { // extract assets/quotes that require market quotes var standardAssets = new List <Asset>(); var standardQuotes = new List <BasicQuotation>(); { // build a request/response map (indexed by instrument id) var instrumentMap = new Dictionary <string, Asset>(); //List<Pair<Asset, BasicQuotation>> completeAssetQuotes = new List<Pair<Asset, BasicQuotation>>(); foreach (Asset asset in standardQuotedAssetSet.instrumentSet.Items) { instrumentMap[asset.id.ToLower()] = asset; } foreach (BasicAssetValuation quoteInstr in standardQuotedAssetSet.assetQuote) { string instrId = quoteInstr.objectReference.href; if (!instrumentMap.TryGetValue(instrId.ToLower(), out var asset)) { throw new ApplicationException(String.Format( "Cannot find instrument '{0}' for assetQuote", instrId)); } foreach (BasicQuotation quoteField in quoteInstr.quote) { if (quoteField.valueSpecified) { // value provided - dont get from market //completeAssetQuotes.Add(new Pair<Asset, BasicQuotation>(asset, quoteField)); } else { // value not supplied - get from market BasicQuotation quote = BasicQuotationHelper.Clone(quoteField); standardAssets.Add(asset); standardQuotes.Add(quote); } } } } var requestItems = new List <RequestItem>(); var instrConversionMap = new Dictionary <string, string>(); var instrUniquenessMap = new Dictionary <string, string>(); var internalInstrIds = new List <string>(); var fieldConversionMap = new Dictionary <string, string>(); var fieldUniquenessMap = new Dictionary <string, string>(); var internalFieldIds = new List <string>(); Logger.LogDebug(" Mappings :"); for (int i = 0; i < standardAssets.Count; i++) { // map asset to provider instrument id Asset standardAsset = standardAssets[i]; string internalInstrId = standardAsset.id; internalInstrIds.Add(internalInstrId); string providerInstrId = _marketDataMap.Convert( MDSDictionaryType.Instrument, requestType, MDSProviderId.GlobalIB, ProviderId, internalInstrId, ConvertFailMode.ThrowException); // update 1-way map instrConversionMap[internalInstrId.ToLower()] = providerInstrId; instrUniquenessMap[providerInstrId.ToLower()] = providerInstrId; // map quote to provider field name BasicQuotation standardQuote = standardQuotes[i]; string internalFieldId = standardQuote.GetStandardFieldName(); internalFieldIds.Add(internalFieldId); string providerFieldId = _marketDataMap.Convert( MDSDictionaryType.FieldName, requestType, MDSProviderId.GlobalIB, ProviderId, internalFieldId, ConvertFailMode.ThrowException); // update 1-way map fieldConversionMap[internalFieldId.ToLower()] = providerFieldId; fieldUniquenessMap[providerFieldId.ToLower()] = providerFieldId; // get provider units string providerUnitsId = _marketDataMap.Convert( MDSDictionaryType.QuoteUnits, requestType, MDSProviderId.GlobalIB, ProviderId, $"{internalInstrId}/{internalFieldId}", ConvertFailMode.ThrowException); var requestItem = new RequestItem { StandardAsset = standardAsset, StandardQuote = standardQuote, StandardUnits = PriceQuoteUnitsScheme.ParseEnumString(standardQuote.quoteUnits.Value), ProviderInstrumentId = providerInstrId, ProviderFieldName = providerFieldId, ProviderUnits = PriceQuoteUnitsScheme.ParseEnumString(providerUnitsId) }; requestItems.Add(requestItem); // debug Logger.LogDebug(" [{0}] '{1}/{2}' ({3}) --> '{4}/{5}' ({6})", i, internalInstrIds[i], internalFieldIds[i], standardQuote.quoteUnits.Value, instrConversionMap[internalInstrIds[i].ToLower()], fieldConversionMap[internalFieldIds[i].ToLower()], providerUnitsId); // enddebug } var providerInstrIds = new List <string>(instrUniquenessMap.Values); var providerFieldIds = new List <string>(fieldUniquenessMap.Values); // build provider instr/field code sets - todo - for now just build 1 var results = new List <ProviderInstrFieldCodeSet>(); var result = new ProviderInstrFieldCodeSet(providerInstrIds, providerFieldIds); results.Add(result); return(new RequestContext { RequestItems = requestItems, ProviderInstrFieldCodeSets = results, InstrConversionMap = instrConversionMap, FieldConversionMap = fieldConversionMap }); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleRateAsset"/> class. /// </summary> /// <param name="id">The id.</param> /// <param name="baseDate">The base date.</param> /// <param name="amount">The amount.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="fixedRate">The fixed rate.</param> protected PriceableSimpleRateAsset(string id, DateTime baseDate, Decimal amount, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) { ModelIdentifier = "SimpleAsset"; Id = id; BaseDate = baseDate; BusinessDayAdjustments = businessDayAdjustments; Notional = amount; SetRate(fixedRate); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleCommoditySpreadAsset"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="spread">The fixed rate.</param> protected PriceableSimpleCommoditySpreadAsset(DateTime baseDate, BasicQuotation spread) { ModelIdentifier = "SimpleSpreadAsset"; BaseDate = baseDate; SetRate(spread); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableLMEFuture"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="rollCalendar">THe rollCalendar.</param> /// <param name="fixedRate"></param> public PriceableLMEFuture(DateTime baseDate, CommodityFutureNodeStruct nodeStruct, IBusinessCalendar rollCalendar, BasicQuotation fixedRate) : base(baseDate, nodeStruct.Future, nodeStruct.BusinessDayAdjustments, fixedRate, new Offset { dayType = DayTypeEnum.Business, dayTypeSpecified = true, period = PeriodEnum.D, periodMultiplier = "0", periodSpecified = true }) { Id = nodeStruct.Future.id; CommodityType = Future.description; Future = nodeStruct.Future; PriceQuoteUnits = nodeStruct.PriceQuoteUnits; ModelIdentifier = "CommoditiesFuturesAsset"; SettlementBasis = "EFP Delivery with an option to cash settle."; ContractMonthPeriod = nodeStruct.ContractMonthPeriod; ContractSeries = "Daily:3M/Weekly:6M/Monthly:" + ContractMonthPeriod.ToString(); ExchangeIdentifier = nodeStruct.Future.exchangeId.Value; var idParts = Id.Split('-'); var immCode = idParts[3]; if (int.TryParse(immCode, out int intResult)) { //If the roll is less that 3M then daily roll. //Less the number of business days in the next 3 months i.e. approximately 60. //TODO This hsould be all moved to configuration! var dailyCutoverOffset = new Offset { dayType = DayTypeEnum.Calendar, dayTypeSpecified = true, period = PeriodEnum.M, periodMultiplier = "3", periodSpecified = true }; var dailyCutoverDate = rollCalendar.Advance(BaseDate, dailyCutoverOffset, BusinessDayConventionEnum.MODFOLLOWING); var businessDays = rollCalendar.BusinessDaysBetweenDates(BaseDate, dailyCutoverDate); if (intResult <= businessDays.Count) { LastTradeDate = businessDays[intResult]; } //TODO //If the roll is greater than 3M and less than 6M then weekly on a Wednesday. //Less the number of weeks in the following 3 months i.e. approximately 12 // else { //Remember thefirst expiry is after the 3 motn cutover! //TODO this should be the 6 ContractMonthPeriod. var rollDate = baseDate.AddMonths(intResult - businessDays.Count + 3); var lastTradingDay = new LastTradingDate().GetLastTradingDay(rollDate.Month, rollDate.Year); //Do the date adjustment logic. LastTradeDate = rollCalendar.Advance(lastTradingDay, RollOffset, BusinessDayConventionEnum.PRECEDING); } } //This means that the value should be a period. else { var term = PeriodHelper.Parse(immCode); LastTradeDate = GetEffectiveDate(BaseDate, rollCalendar, term, nodeStruct.BusinessDayAdjustments.businessDayConvention); } RiskMaturityDate = LastTradeDate; TimeToExpiry = (decimal)DayCounter.YearFraction(BaseDate, RiskMaturityDate); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleBond"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The bond nodeStruct</param> /// <param name="settlementCalendar">The settlement Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="quoteType">THe quote Type</param> public PriceableSimpleBond(DateTime baseDate, BondNodeStruct nodeStruct, IBusinessCalendar settlementCalendar, IBusinessCalendar paymentCalendar, BasicQuotation marketQuote, BondPriceEnum quoteType) : base(baseDate, nodeStruct.Bond.faceAmount, nodeStruct.Bond.currency, nodeStruct.SettlementDate, nodeStruct.ExDivDate, nodeStruct.BusinessDayAdjustments, marketQuote, quoteType) { Id = nodeStruct.Bond.id; var tempId = Id.Split('-'); var bondId = tempId[0]; if (tempId.Length > 2) { bondId = tempId[2]; } SettlementDateCalendar = settlementCalendar; Issuer = (string)nodeStruct.Bond.Item;//Does not handle PartyReference type -> only string! Description = "Not Defined"; //IsYTMQuote = true; if (nodeStruct.Bond.description != null) { Description = nodeStruct.Bond.description; } MaturityDate = nodeStruct.Bond.maturity; CouponDayCount = new DayCountFraction { Value = nodeStruct.Bond.dayCountFraction.Value }; CouponFrequency = new Period { period = nodeStruct.Bond.paymentFrequency.period, periodMultiplier = nodeStruct.Bond.paymentFrequency.periodMultiplier }; if (nodeStruct.Bond.couponRateSpecified) { CouponRate = nodeStruct.Bond.couponRate; } if (nodeStruct.Bond.parValueSpecified) { ParValue = nodeStruct.Bond.parValue; } if (nodeStruct.Bond.clearanceSystem != null) { ClearanceSystem = nodeStruct.Bond.clearanceSystem.Value; } if (nodeStruct.Bond.exchangeId != null) { Exchange = nodeStruct.Bond.exchangeId.Value; } CouponType = CouponTypeEnum.Fixed; if (nodeStruct.Bond.seniority != null) { Seniority = EnumHelper.Parse <CreditSeniorityEnum>(nodeStruct.Bond.seniority.Value, true); } if (nodeStruct.Bond.instrumentId != null) { InstrumentIds = new List <InstrumentId>(); foreach (var identifier in nodeStruct.Bond.instrumentId.Select(id => InstrumentIdHelper.Parse(id.Value))) { InstrumentIds.Add(identifier); } } //This handles the case of a bondforward used in curve building. if (MaturityDate > BaseDate) { DateTime lastCouponDate; DateTime nextCouponDate; var rollConvention = RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture)); Frequency = FrequencyHelper.ToFrequency(nodeStruct.Bond.paymentFrequency); //Get the settlement date SettlementDate = GetSettlementDate(baseDate, settlementCalendar, nodeStruct.SettlementDate); //Generate the necessary dates. //TODO Should the settlement date and the underlying bond be calculated on the fly when calculation occurs? UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate, MaturityDate, CouponFrequency, rollConvention, out lastCouponDate, out nextCouponDate); LastCouponDate = UnAdjustedPeriodDates[0]; NextCouponDate = nextCouponDate; AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates, nodeStruct.BusinessDayAdjustments .businessDayConvention, paymentCalendar) .ToArray(); AdjustedPeriodDates[0] = SettlementDate; //TODO check this! NextExDivDate = GetNextExDivDate(); IsXD = IsExDiv(); } BondCurveName = CurveNameHelpers.GetBondCurveName(Currency.Value, bondId); SwapDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="fixedLegSwap">The fixed leg details.</param> /// <param name="spotDate">the spot date.</param> /// <param name="notional">The notional amount.</param> /// <param name="paymentBusinessDayAdjustments">The business day adjustments.</param> /// <param name="floatingLegSwap">The floating leg details.</param> /// <param name="floatingLegCalculation">The floatingLegCalculation.</param> /// <param name="fixingDateOffset">The fixing date business day adjustments.</param> /// <param name="resetRates">The reset rates of the floating leg - if any.</param> /// <param name="fixingCalendar">The fixing calendar. If null, a new is constructed based on the business calendars.</param> /// <param name="paymentCalendar">The payment calendar. If null, a new is constructed based on the business calendars.</param> /// <param name="fixedRate">The fixed rate.</param> /// <param name="spread">The spread on the floating leg.</param> public PriceableIRSwap(DateTime baseDate, SimpleIRSwap fixedLegSwap, DateTime spotDate, MoneyBase notional, BusinessDayAdjustments paymentBusinessDayAdjustments, SimpleIRSwap floatingLegSwap, Calculation floatingLegCalculation, RelativeDateOffset fixingDateOffset, List <Decimal> resetRates, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate, BasicQuotation spread) : base(baseDate, fixedLegSwap, fixingDateOffset, floatingLegCalculation, paymentBusinessDayAdjustments, null, fixingCalendar, paymentCalendar, fixedRate) { ModelIdentifier = DiscountingType == null ? "SwapAsset" : "DiscountSwapAsset"; FloatingLegSpread = GetSpread(spread); ForwardRates = resetRates?.ToArray(); UnderlyingRateIndex = RateIndexHelper.Parse(FloatingRateCalculation.floatingRateIndex.Value, notional.currency.Value, Calculation.dayCountFraction.Value); var unadjustedFloatingDates = DateScheduler.GetUnadjustedDateSchedule(spotDate, floatingLegSwap.term, floatingLegSwap.paymentFrequency); FloatingLegAdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedFloatingDates, paymentBusinessDayAdjustments.businessDayConvention, paymentCalendar); FloatingLegWeightings = CreateWeightings(CDefaultWeightingValue, FloatingLegAdjustedPeriodDates.Count - 1); FloatingLegYearFractions = GetFloatingLegYearFractions(); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleFra"/> class. /// This is a special case for use with the factory for bootstrapping, as it /// uses no calendar logic. This is done by the factory. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">A special class containing all salient data required.</param> /// <param name="fixingCalendar">The fixing calendar.</param> /// <param name="paymentCalendar">The payment calendar.></param> /// <param name="notional">The notional. The default value is 1.00m.</param> /// <param name="normalisedRate">The fixed rate as a decimal contained in a basic quotation.</param> public PriceableSimpleFra(DateTime baseDate, SimpleFraNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, Decimal notional, BasicQuotation normalisedRate) : base(nodeStruct.SimpleFra.id, baseDate, notional, nodeStruct.BusinessDayAdjustments, normalisedRate) { SimpleFra = nodeStruct.SimpleFra; FixingDateOffset = nodeStruct.SpotDate; UnderlyingRateIndex = nodeStruct.RateIndex; SpotDate = GetSpotDate(baseDate, fixingCalendar, nodeStruct.SpotDate); AdjustedStartDate = GetEffectiveDate(SpotDate, paymentCalendar, nodeStruct.SimpleFra.startTerm, nodeStruct.BusinessDayAdjustments.businessDayConvention);//GetSpotDate(); RiskMaturityDate = GetEffectiveDate(SpotDate, paymentCalendar, nodeStruct.SimpleFra.endTerm, nodeStruct.BusinessDayAdjustments.businessDayConvention); YearFraction = GetYearFraction(SimpleFra.dayCountFraction.Value, AdjustedStartDate, RiskMaturityDate); TimeToExpiry = GetTimeToMaturity(baseDate, RiskMaturityDate); }
protected List <BasicAssetValuation> ConvertProviderResultsToStandardValuations( Dictionary <string, BasicQuotation> providerResults, RequestContext requestContext) { var results = new List <BasicAssetValuation>(); // build standard results (and convert quote units) Logger.LogDebug(" Results :"); for (int i = 0; i < requestContext.RequestItems.Count; i++) { RequestItem requestItem = requestContext.RequestItems[i]; Asset standardAsset = requestItem.StandardAsset; BasicQuotation standardQuote = requestItem.StandardQuote; string standardInstrId = standardAsset.id; string standardFieldId = standardQuote.GetStandardFieldName(); PriceQuoteUnitsEnum standardQuoteUnit = requestItem.StandardUnits; PriceQuoteUnitsEnum providerQuoteUnit = requestItem.ProviderUnits; string providerInstrId = requestContext.InstrConversionMap[standardInstrId.ToLower()]; string providerFieldId = requestContext.FieldConversionMap[standardFieldId.ToLower()]; string providerQuoteKey = FormatProviderQuoteKey(providerInstrId, providerFieldId); if (providerResults.TryGetValue(providerQuoteKey, out var providerQuote)) { BasicQuotation convertedQuote; if (providerQuote.valueSpecified) { // valid value returned decimal convertedValue = PriceQuoteUnitsHelper.ConvertPriceQuoteUnitsValue(providerQuoteUnit, standardQuoteUnit, providerQuote.value); convertedQuote = BasicQuotationHelper.Create(standardQuote, convertedValue); // debug Logger.LogDebug(" [{0}] '{1}/{2}' ({3}/{4}) [{5}] --> '{6}/{7}' ({8}/{9}) [{10}]", i, providerInstrId, providerFieldId, AssetMeasureEnum.MarketQuote, providerQuoteUnit, providerQuote.value, standardInstrId, standardFieldId, AssetMeasureEnum.MarketQuote, standardQuoteUnit, convertedQuote.value); // enddebug } else { // no value - copy error details convertedQuote = providerQuote; // debug Logger.LogDebug(" [{0}] '{1}/{2}' ({3}/{4}) [{5}] --> '{6}/{7}' ({8}/{9}) [{10}]", i, providerInstrId, providerFieldId, providerQuote.measureType.Value, providerQuote.quoteUnits.Value, providerQuote.value, standardInstrId, standardFieldId, convertedQuote.measureType.Value, convertedQuote.quoteUnits.Value, convertedQuote.value); // enddebug } // add other provider info convertedQuote.timeSpecified = providerQuote.timeSpecified; convertedQuote.time = providerQuote.time; convertedQuote.valuationDateSpecified = providerQuote.valuationDateSpecified; convertedQuote.valuationDate = providerQuote.valuationDate; convertedQuote.informationSource = providerQuote.informationSource; results.Add(new BasicAssetValuation { objectReference = new AnyAssetReference { href = standardAsset.id }, quote = new[] { convertedQuote } }); } } return(results); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableCommodityAverageForward"/> class. /// </summary> /// <param name="notionalAmount">The notional amount</param> /// <param name="baseDate">The base date</param> /// <param name="expiryTerm">The expiry Term.</param> /// <param name="underlyingTenor">The underlying tenor</param> /// <param name="nodeStruct">The nodeStruct.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="commodityForward">The forward points.</param> public PriceableCommodityAverageForward(DateTime baseDate, decimal notionalAmount, string expiryTerm, string underlyingTenor, CommodityAverageSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation commodityForward) { PaymentDiscountFactorCcy12 = 1.0m; PaymentDiscountFactorCcy1 = 1.0m; Ccy2CurveName = string.Empty; Ccy1CurveName = string.Empty; ModelIdentifier = "SimpleCommodityAsset"; if (nodeStruct.Commodity != null) { Id = nodeStruct.Commodity.id; } ExpiryTerm = PeriodHelper.Parse(expiryTerm); //Default length is one month //TODO move to config. UnderlyingTenor = PeriodHelper.Parse(underlyingTenor); NotionalAmount = notionalAmount; CommodityAsset = nodeStruct.Commodity; BaseDate = baseDate; SpotDateOffset = nodeStruct.SpotDate; //FixingCalendar = BusinessCenterHelper.ToBusinessCalendar(SpotDateOffset.businessCenters); SpotDate = GetSpotDate(baseDate, fixingCalendar, SpotDateOffset); //TODO Set the start date based on the config data AdjustedStartDate = GetEffectiveDate(SpotDate, paymentCalendar, ExpiryTerm, nodeStruct.SpotDate.businessDayConvention); RiskMaturityDate = GetForwardDate(AdjustedStartDate, paymentCalendar, UnderlyingTenor, SpotDateOffset.businessDayConvention); SetRate(commodityForward); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleBond"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="bond">The bond</param> /// <param name="settlementDate">The settlement date.</param> /// <param name="exDivDate">The ex dividend date.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="quoteType">The quote type</param> public PriceableSimpleBond(DateTime baseDate, Bond bond, DateTime settlementDate, DateTime exDivDate, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar paymentCalendar, BasicQuotation marketQuote, BondPriceEnum quoteType) : base(baseDate, bond.faceAmount, bond.currency, null, null, businessDayAdjustments, marketQuote, quoteType) { Id = bond.id; var tempId = Id.Split('-'); var bondId = tempId[0]; if (tempId.Length > 2) { bondId = tempId[2]; } Issuer = (string)bond.Item;//Does not handle PartyReference type -> only string! Description = "Not Defined"; if (bond.description != null) { Description = bond.description; } MaturityDate = bond.maturity; CouponDayCount = new DayCountFraction { Value = bond.dayCountFraction.Value }; if (bond.parValueSpecified) { ParValue = bond.parValue; } if (bond.couponRateSpecified) { CouponRate = bond.couponRate; } CouponFrequency = new Period { period = bond.paymentFrequency.period, periodMultiplier = bond.paymentFrequency.periodMultiplier }; CouponType = CouponTypeEnum.Fixed; if (bond.clearanceSystem != null) { ClearanceSystem = bond.clearanceSystem.Value; } if (bond.exchangeId != null) { Exchange = bond.exchangeId.Value; } if (bond.seniority != null) { Seniority = EnumHelper.Parse <CreditSeniorityEnum>(bond.seniority.Value); } if (bond.instrumentId != null) { InstrumentIds = new List <InstrumentId>(); foreach (var identifier in bond.instrumentId.Select(id => InstrumentIdHelper.Parse(id.Value))) { InstrumentIds.Add(identifier); } } //This handles the case of a bond forward used in curve building. if (MaturityDate > BaseDate) { var rollConvention = RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture)); Frequency = FrequencyHelper.ToFrequency(bond.paymentFrequency); SettlementDate = settlementDate; UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate, MaturityDate, CouponFrequency, rollConvention, out _, out var nextCouponDate); LastCouponDate = UnAdjustedPeriodDates[0]; NextCouponDate = nextCouponDate; AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates, PaymentBusinessDayAdjustments.businessDayConvention, paymentCalendar).ToArray(); AdjustedPeriodDates[0] = SettlementDate; NextExDivDate = exDivDate; IsXD = IsExDiv(); } BondCurveName = CurveNameHelpers.GetBondCurveName(Currency.Value, bondId); SwapDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableRepo"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="amount">Notional Amount.</param> /// <param name="nodeStruct">The deposit nodeStruct.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="fixingCalendar">The fixing Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableRepo(DateTime baseDate, Decimal amount, RepoNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) : base(nodeStruct.Deposit.id, baseDate, amount, businessDayAdjustments, fixedRate) { SpotDateOffset = nodeStruct.SpotDate; Deposit = nodeStruct.Deposit; UnderlyingAsset = nodeStruct.UnderlyingAsset; AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, nodeStruct.SpotDate); RiskMaturityDate = GetEffectiveDate(AdjustedStartDate, paymentCalendar, nodeStruct.Deposit.term, nodeStruct.BusinessDayAdjustments.businessDayConvention); YearFraction = GetYearFraction(Deposit.dayCountFraction.Value, AdjustedStartDate, RiskMaturityDate); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableDeposit"/> class. /// </summary> /// <param name="curveName"></param> /// <param name="baseDate"></param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="fixedRate">The fixed rate.</param> protected PriceableInflationSwapAsset(string curveName, DateTime baseDate, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) { CurveName = curveName; BaseDate = baseDate; BusinessDayAdjustments = businessDayAdjustments; SetRate(fixedRate); StartDiscountFactor = 1.0m; CurveName = string.Empty; }
/// <summary> /// Initializes a new instance of the <see cref="PriceableBondAsset"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="exDivDateOffset">The exdiv offsets.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="amount">The notional amount.</param> /// <param name="currency">THe currency of the bond.</param> /// <param name="settlementDateOffset">The details to calculate the settlement date.</param> /// <param name="quoteType">THe market quote type</param> protected PriceableBondAsset(DateTime baseDate, Decimal amount, Currency currency, RelativeDateOffset settlementDateOffset, RelativeDateOffset exDivDateOffset, BusinessDayAdjustments businessDayAdjustments, BasicQuotation marketQuote, BondPriceEnum quoteType) { Multiplier = 1.0m; YearFractions = new[] { 0.25m }; ModelIdentifier = "GenericBondAsset"; Notional = amount; Currency = currency; QuoteType = quoteType; SettlementDateOffset = settlementDateOffset; ExDividendDateOffset = exDivDateOffset; BaseDate = baseDate; PaymentBusinessDayAdjustments = businessDayAdjustments; SetQuote(marketQuote); }
///// <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="PriceableSimpleRateSpreadAsset"/> class. /// </summary> /// <param name="baseDate"></param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="spread">The fixed rate.</param> protected PriceableSimpleRateSpreadAsset(DateTime baseDate, BusinessDayAdjustments businessDayAdjustments, BasicQuotation spread) { ModelIdentifier = "SimpleSpreadAsset"; BaseDate = baseDate; BusinessDayAdjustments = businessDayAdjustments; SetSpread(spread); }
/// <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="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct;</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableSimpleIRSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, nodeStruct.DateAdjustments, nodeStruct.Calculation, fixedRate) { Id = nodeStruct.SimpleIRSwap.id; FixingDateOffset = nodeStruct.SpotDate; SimpleIRSwap = nodeStruct.SimpleIRSwap; UnderlyingRateIndex = nodeStruct.UnderlyingRateIndex; //TODO: This needs to be modified to use backwards roll. AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, FixingDateOffset); List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, SimpleIRSwap.paymentFrequency); AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, paymentCalendar); RiskMaturityDate = AdjustedPeriodDates[AdjustedPeriodDates.Count - 1]; Weightings = CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Count - 1); YearFractions = GetYearFractions(); ModelIdentifier = DiscountingType == null ? "SimpleSwapAsset" : "SimpleDiscountSwapAsset"; var timeToMaturity = Actual365.Instance.YearFraction(baseDate, RiskMaturityDate); EndDiscountFactor = (decimal)System.Math.Exp(-(double)fixedRate.value * timeToMaturity); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableEquityForward"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="position">The underlysing prosiiotn.</param> /// <param name="equity">The equity</param> /// <param name="settlementCalendar">The settlement Calendar.</param> /// <param name="marketQuote">The market quote.</param> public PriceableEquityForward(DateTime baseDate, int position, EquityNodeStruct equity, IBusinessCalendar settlementCalendar, BasicQuotation marketQuote) : base(baseDate, position, equity.SettlementDate, settlementCalendar, marketQuote) { IsXD = IsExDiv(); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="amount">The amount.</param> /// <param name="discountingType">The discounting type.</param> /// <param name="effectiveDate">The base date.</param> /// <param name="tenor">The maturity tenor.</param> /// <param name="fxdDayFraction">The fixed leg day fraction.</param> /// <param name="businessCenters">The payment business centers.</param> /// <param name="businessDayConvention">The payment business day convention.</param> /// <param name="fxdFrequency">The business day adjustments.</param> /// <param name="underlyingRateIndex">Index of the rate.</param> /// <param name="fixedRate">The fixed rate.</param> /// <param name="id">The identifier.</param> /// <param name="baseDate">The base date.</param> /// <param name="currency">THe currency.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> public PriceableSimpleIRSwap(string id, DateTime baseDate, string currency, decimal amount, DiscountingTypeEnum?discountingType, DateTime effectiveDate, string tenor, string fxdDayFraction, string businessCenters, string businessDayConvention, string fxdFrequency, RateIndex underlyingRateIndex, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : this(baseDate, SimpleIrsHelper.Parse(id, currency, fxdDayFraction, tenor, fxdFrequency, id), effectiveDate, CalculationFactory.CreateFixed(fixedRate.value, MoneyHelper.GetAmount(amount, currency), DayCountFractionHelper.Parse(fxdDayFraction), discountingType), BusinessDayAdjustmentsHelper.Create(businessDayConvention, businessCenters), underlyingRateIndex, fixingCalendar, paymentCalendar, fixedRate) { }
/// <summary> /// Initializes a new instance of the <see cref="PriceableCommoditySpread"/> class. /// </summary> /// <param name="baseDate">The base date</param> /// <param name="identifier">The asset identifier</param> /// <param name="maturityDate">The matrutiy date.</param> /// <param name="spread">The spread.</param> public PriceableCommoditySpread(String identifier, DateTime baseDate, DateTime maturityDate, BasicQuotation spread) : base(baseDate, spread) { Id = identifier; RiskMaturityDate = maturityDate; TimeToExpiry = GetTimeToMaturity(baseDate, RiskMaturityDate); SetRate(spread); }