private static void GeneratePeriodsBackward(DateTime firstRollDate, CalculationPeriodFrequency frequency, BusinessDayAdjustments calculationPeriodDatesAdjustments, CalculationPeriodsPrincipalExchangesAndStubs result, DateTime adjustedEffectiveDate, StubPeriodTypeEnum?initialStubType , IBusinessCalendar paymentCalendar) { DateTime periodEndDate = firstRollDate; DateTime periodStartDate = AddPeriod(periodEndDate, IntervalHelper.FromFrequency(frequency), -1); bool encounteredShortInitialStub = false; //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, calculationPeriodDatesAdjustments.businessCenters); //} do { var calculationPeriod = new CalculationPeriod(); // Apply ROLL CONVENTION (NOT A BUSINESS DAY CONVENTION!) to unadjusted period start and end dates. // DateTime rollConventionAdjustedPeriodStartDate = periodStartDate; DateTime rollConventionAdjustedPeriodEndDate = periodEndDate; var frequencyPeriod = EnumHelper.Parse <PeriodEnum>(frequency.period, true); if (frequencyPeriod != PeriodEnum.D)//adjust if the frequency is NOT expressed in days { rollConventionAdjustedPeriodStartDate = RollConventionEnumHelper.AdjustDate(frequency.rollConvention, periodStartDate); rollConventionAdjustedPeriodEndDate = RollConventionEnumHelper.AdjustDate(frequency.rollConvention, periodEndDate); } CalculationPeriodHelper.SetUnadjustedDates(calculationPeriod, rollConventionAdjustedPeriodStartDate, rollConventionAdjustedPeriodEndDate); // Set adjusted period dates // DateTime adjustedPeriodStartDate = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, rollConventionAdjustedPeriodStartDate, calculationPeriodDatesAdjustments); DateTime adjustedPeriodEndDate = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, rollConventionAdjustedPeriodEndDate, calculationPeriodDatesAdjustments); CalculationPeriodHelper.SetAdjustedDates(calculationPeriod, adjustedPeriodStartDate, adjustedPeriodEndDate); //if (calculationPeriod.unadjustedStartDate > adjustedEffectiveDate) if (calculationPeriod.adjustedStartDate > adjustedEffectiveDate) { result.InsertFirst(calculationPeriod); periodEndDate = periodStartDate; periodStartDate = AddPeriod(periodEndDate, IntervalHelper.FromFrequency(frequency), -1); } //else if (calculationPeriod.unadjustedStartDate == adjustedEffectiveDate)//first period - not stub else if (calculationPeriod.adjustedStartDate == adjustedEffectiveDate)//first period - not stub { result.InsertFirst(calculationPeriod); break; } else//first period - short stub (merge with next period if a long stub specified) { encounteredShortInitialStub = true; //calculationPeriod.unadjustedStartDate = adjustedEffectiveDate; calculationPeriod.adjustedStartDate = adjustedEffectiveDate; result.InitialStubCalculationPeriod = calculationPeriod; break; } } while (true); if (encounteredShortInitialStub && initialStubType == StubPeriodTypeEnum.LongInitial) { result.CreateLongInitialStub(); } }
/// <summary> /// Initializes a new instance of the <see cref="PriceableFixedRateCoupon"/> class. /// </summary> /// <param name="uniqueId">The unique id.</param> /// <param name="payerIsBase">The payer is base flag.</param> /// <param name="accrualStartDate">The accrual start date. If they are adjusted then set <c>adjustCalculationDatesIndicator</c> to <c>false</c> [adjust calculation dates indicator].</param> /// <param name="accrualEndDate">The accrual end date. If they are adjusted then set <c>adjustCalculationDatesIndicator</c> to <c>false</c> [adjust calculation dates indicator].</param> /// <param name="adjustCalculationDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param> /// <param name="accrualDayAdjustments">The accrual business day adjustments.</param> /// <param name="paymentDate">The payment date.</param> /// <param name="calculation">The fixed rate calculation.</param> /// <param name="notionalAmount">The notional amount.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> public PriceableFixedRateCoupon ( string uniqueId , bool payerIsBase , DateTime accrualStartDate , DateTime accrualEndDate , bool adjustCalculationDatesIndicator , BusinessDayAdjustments accrualDayAdjustments , AdjustableOrAdjustedDate paymentDate , Calculation calculation , Money notionalAmount , IBusinessCalendar paymentCalendar) : base (uniqueId , CouponType.FixedRate , payerIsBase , accrualStartDate , accrualEndDate , adjustCalculationDatesIndicator , accrualDayAdjustments , calculation , notionalAmount , paymentDate , paymentCalendar) { Id = uniqueId; }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRCap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="identifier">The asset identifier.</param> /// <param name="rollDates">The roll dates. plus the maturity date. This array is an element longer than /// the notionals and strikes arrays.</param> /// <param name="notionals">The notionals for each caplet. There should be ne less than the number of roll dates.</param> /// <param name="strikes">The various strikes for each caplet. The same length as the notional list.</param> /// <param name="resets">An array of reset rates. This may be null.</param> /// <param name="resetOffset">The relative date offset for all the fixings.</param> /// <param name="paymentBusinessDayAdjustments">The payment business day adjustments.</param> /// <param name="capCalculation">The cap calculation.</param> /// <param name="fixingCalendar">The fixing Calendar.</param> public PriceableIRCap(DateTime baseDate, string identifier, List <DateTime> rollDates, List <double> notionals, List <double> strikes, List <double> resets, RelativeDateOffset resetOffset, BusinessDayAdjustments paymentBusinessDayAdjustments, Calculation capCalculation, IBusinessCalendar fixingCalendar) : base(baseDate, paymentBusinessDayAdjustments, resetOffset, capCalculation, null) { Id = identifier; SimpleIRCap = new SimpleIRSwap { dayCountFraction = capCalculation.dayCountFraction }; ResetRates = resets; RiskMaturityDate = rollDates[rollDates.Count - 1]; AdjustedPeriodDates = rollDates; AdjustedStartDate = AdjustedPeriodDates[0]; ExpiryDates = GetResetDates(AdjustedPeriodDates, fixingCalendar, resetOffset, true); OptionsExpiryDate = ExpiryDates[ExpiryDates.Count - 1]; IsCap = true; Strikes = strikes; Notionals = notionals; YearFractions = GetYearFractions(); if (DiscountingType != null) { ModelIdentifier = "DiscountCapAsset"; } }
/// <summary> /// A slightly ore complicated date scheduler. /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="rollsMetaSchedule"></param> /// <param name="backwardGeneration"></param> /// <param name="businessDayAdjustments"></param> /// <param name="businessCalendar"></param> /// <returns></returns> public static List <DateTime> GetAdjustedDates3(DateTime startDate, DateTime endDate, List <MetaScheduleItem> rollsMetaSchedule, bool backwardGeneration, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar businessCalendar) { var unadjustedDates = DatesMetaSchedule.GetUnadjustedDates3(startDate, endDate, rollsMetaSchedule, backwardGeneration); return(unadjustedDates.Select(date => AdjustedDateHelper.ToAdjustedDate(businessCalendar, date, businessDayAdjustments)).ToList()); }
///<summary> /// Gets the adjusted dates from a provided date schedule. ///</summary> ///<param name="metaScheduleDefinition"></param> ///<param name="startDate"></param> ///<param name="businessDayAdjustments"></param> ///<param name="businessCalendar"></param> ///<returns></returns> public static List <DateTime> GetAdjustedDates(List <Triplet <Period, Period, RollConventionEnum> > metaScheduleDefinition, DateTime startDate, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar businessCalendar) { var unadjustedDates = DatesMetaSchedule.GetUnadjustedDates(metaScheduleDefinition, startDate); return(unadjustedDates.Select(date => AdjustedDateHelper.ToAdjustedDate(businessCalendar, date, businessDayAdjustments)).ToList()); }
/// <summary> /// A simple date scheduler. /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="interval"></param> /// <param name="rollConventionEnum"></param> /// <param name="backwardGeneration"></param> /// <param name="businessDayAdjustments"></param> /// <param name="businessCalendar"></param> /// <returns></returns> public static List <DateTime> GetAdjustedDates2(DateTime startDate, DateTime endDate, Period interval, RollConventionEnum rollConventionEnum, bool backwardGeneration, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar businessCalendar) { var unadjustedDates = DatesMetaSchedule.GetUnadjustedDates2(startDate, endDate, interval, rollConventionEnum, backwardGeneration); return(unadjustedDates.Select(date => AdjustedDateHelper.ToAdjustedDate(businessCalendar, date, businessDayAdjustments)).ToList()); }
/// <summary> /// /// </summary> /// <param name="baseDate"></param> /// <param name="bondAsset"></param> /// <param name="notionalAmount"></param> /// <param name="bondCouponType"></param> /// <param name="paymentConvention"></param> /// <param name="fOCalculationMethod"></param> /// <param name="fixingCalendar"></param> /// <param name="paymentCalendar"></param> /// <returns></returns> public static List <PriceableRateCoupon> CreatePriceableBondCoupons(DateTime baseDate, Bond bondAsset, decimal notionalAmount, CouponStreamType bondCouponType, BusinessDayAdjustments paymentConvention, bool fOCalculationMethod, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar) { List <PriceableRateCoupon> result = new List <PriceableRateCoupon>(); //This handles the case of a bond forward used in curve building. if (bondAsset.maturity > baseDate) { var rollConvention = RollConventionEnumHelper.Parse(bondAsset.maturity.Day.ToString(CultureInfo.InvariantCulture)); //var frequency = FrequencyHelper.ToFrequency(bondAsset.paymentFrequency); var unAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(baseDate, bondAsset.maturity, bondAsset.paymentFrequency, rollConvention, out _, out _); var adjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unAdjustedPeriodDates, paymentConvention.businessDayConvention, paymentCalendar).ToArray(); var length = unAdjustedPeriodDates.Length; for (int i = 0; i < length - 1; i++) { var id = "Coupon" + "_" + i; var startDate = unAdjustedPeriodDates[i]; var endDate = unAdjustedPeriodDates[i + 1]; var paymentDate = adjustedPeriodDates[i + 1]; var coupon = CreatePriceableBondCoupon(id, bondAsset, notionalAmount, bondCouponType, startDate, endDate, paymentDate, paymentCalendar); result.Add(coupon); } return(result); } return(result); }
public static AdjustableOrAdjustedDate CreateUnadjustedDate(DateTime unadjustedDate, BusinessDayAdjustments businessDayAdjustments) { var date = new AdjustableOrAdjustedDate(); var identifiedDate = IdentifiedDateHelper.Create(ItemsChoiceType.unadjustedDate.ToString(), unadjustedDate); object[] items; ItemsChoiceType[] itemsElementName; if (businessDayAdjustments != null) { items = new object[2]; items[0] = identifiedDate; items[1] = businessDayAdjustments; itemsElementName = new ItemsChoiceType[2]; itemsElementName[0] = ItemsChoiceType.unadjustedDate; itemsElementName[1] = ItemsChoiceType.dateAdjustments; } else { items = new object[1]; items[0] = identifiedDate; itemsElementName = new ItemsChoiceType[1]; itemsElementName[0] = ItemsChoiceType.unadjustedDate; } date.Items = items; date.ItemsElementName = itemsElementName; return(date); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableDeposit"/> class. /// </summary> /// <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 PriceableSimpleInflationAsset(DateTime baseDate, Decimal amount, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) { Notional = amount; BaseDate = baseDate; BusinessDayAdjustments = businessDayAdjustments; SetRate(fixedRate); }
/// <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="PriceableBondCouponRateStream"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace.</param> /// <param name="bondId">The bond Id.</param> /// <param name="paymentConvention">The payment roll conventions</param> /// <param name="forecastRateInterpolation">ForwardEndDate = forecastRateInterpolation ? AccrualEndDate /// : AdjustedDateHelper.ToAdjustedDate(forecastRateIndex.indexTenor.Add(AccrualStartDate), AccrualBusinessDayAdjustments);</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="tradeDate">The trade date is used to set the base date for future coupon generation.</param> /// <param name="notionalAmount">The notional amount</param> /// <param name="couponType">The coupon type: fixed or floating.</param> /// <param name="bond">THe bond details.</param> public PriceableBondCouponRateStream ( ILogger logger , ICoreCache cache , string nameSpace , string bondId , DateTime tradeDate , decimal notionalAmount , CouponStreamType couponType , Bond bond , BusinessDayAdjustments paymentConvention , bool forecastRateInterpolation , IBusinessCalendar fixingCalendar , IBusinessCalendar paymentCalendar) { BondId = bondId; Multiplier = 1.0m; PaymentCurrencies = new List <string>(); AnalyticsModel = new BondStreamAnalytic(); BondCouponStreamType = couponType; Id = BuildId(bondId, BondCouponStreamType); Currency = bond.currency.Value; ForecastRateInterpolation = forecastRateInterpolation; //Get the currency. if (!PaymentCurrencies.Contains(bond.currency.Value)) { PaymentCurrencies.Add(bond.currency.Value); } //The calendars if (paymentCalendar == null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, paymentConvention.businessCenters, nameSpace); } //Set the default discount curve name. BondCurveName = CurveNameHelpers.GetBondCurveName(Currency, bondId); //Set the forecast curve name.//TODO extend this to the other types. //if (BondCouponStreamType != CouponStreamType.GenericFixedRate) //{ // if (fixingCalendar == null) // { // fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, ResetDates.resetDatesAdjustments.businessCenters, nameSpace); // } // ForecastCurveName = null; // //if (Calculation.Items != null) // //{ // // var floatingRateCalculation = Calculation.Items; // // var floatingRateIndex = (FloatingRateCalculation) floatingRateCalculation[0]; // // ForecastCurveName = CurveNameHelpers.GetForecastCurveName(floatingRateIndex); // //} //} //Build the coupons and principal exchanges. Coupons = PriceableInstrumentsFactory.CreatePriceableBondCoupons(tradeDate, bond, notionalAmount, BondCouponStreamType, paymentConvention, ForecastRateInterpolation, fixingCalendar, paymentCalendar);//TODO add the stub calculation. UpdateCouponDiscountCurveNames(); UpdateCouponIds(); //RiskMaturityDate = ; logger.LogInfo("Bond Coupon Stream built"); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRFloor"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="identifier">The asset identifier.</param> /// <param name="rollDates">The roll dates. plus the maturity date. This array is an element longer than /// the notionals and strikes arrays.</param> /// <param name="notionals">The notionals for each caplet. There should be ne less than the number of roll dates.</param> /// <param name="strikes">The various strikes for each caplet. The same length as the notional list.</param> /// <param name="resets">An array of reset rates. This may be null.</param> /// <param name="resetOffset">The relative date offset for all the fixings.</param> /// <param name="paymentBusinessDayAdjustments">The payment business day adjustments.</param> /// <param name="capCalculation">The cap calculation.</param> /// <param name="fixingCalendar">The fixing Calendar.</param> public PriceableIRFloor(DateTime baseDate, string identifier, List <DateTime> rollDates, List <double> notionals, List <double> strikes, List <double> resets, RelativeDateOffset resetOffset, BusinessDayAdjustments paymentBusinessDayAdjustments, Calculation capCalculation, IBusinessCalendar fixingCalendar) : base(baseDate, identifier, rollDates, notionals, strikes, resets, resetOffset, paymentBusinessDayAdjustments, capCalculation, fixingCalendar) { IsCap = false; }
/// <summary> /// Gets the adjusted date schedule. /// </summary> /// <param name="businessCalendar">The businessCalendar.</param> /// <param name="effectiveDate">The effective date.</param> /// <param name="intervalToTerminationDate">The interval to termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <returns></returns> public static List <DateTime> GetAdjustedDateSchedule(DateTime effectiveDate, Period intervalToTerminationDate, Period periodInterval, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar businessCalendar) { List <DateTime> unadjustedPeriodDates = DateScheduler.GetUnadjustedDateSchedule(effectiveDate, intervalToTerminationDate, periodInterval); IEnumerable <DateTime> adjustedPeriodDates = unadjustedPeriodDates.Select(a => businessCalendar.Roll(a, businessDayAdjustments.businessDayConvention)); return(adjustedPeriodDates.Distinct().ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableDeposit"/> class. /// </summary> /// <param name="baseDate"></param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="fixedRate">The fixed rate.</param> protected PriceableInflationSwapAsset(DateTime baseDate, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) { BaseDate = baseDate; BusinessDayAdjustments = businessDayAdjustments; SetRate(fixedRate); StartDiscountFactor = 1.0m; CurveName = string.Empty; }
/// <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); }
private static List <BusinessDayAdjustments> GetBusinessDayAdjustmentsRecursive(object objectGraph) { List <BusinessDayAdjustments> list = new List <BusinessDayAdjustments>(); // Stop traversing once simple type (primitive type, string or non-reference type) is encountered. // if ( objectGraph.GetType().IsPrimitive || //if a primitive type (i.e. int, long, double, etc) typeof(string) == objectGraph.GetType() || //if a string !objectGraph.GetType().IsClass) //if not a class (e.g. enum, struct) { return(list); } foreach (PropertyInfo propertyInfo in objectGraph.GetType().GetProperties()) { // If property of BusinessDayAdjustments type - add it into list // if (typeof(BusinessDayAdjustments) == propertyInfo.PropertyType) { BusinessDayAdjustments value = (BusinessDayAdjustments)propertyInfo.GetValue(objectGraph, null); list.Add(value); } else { Debug.Assert(null != objectGraph); object value = propertyInfo.GetValue(objectGraph, null); if (null != value) { if (value.GetType().IsArray)//if array { // iterate thru the array // Array valueAsArray = (Array)value; foreach (object arrayItem in valueAsArray) { if (null != arrayItem) { list.AddRange(GetBusinessDayAdjustmentsRecursive(arrayItem)); } } } else { list.AddRange(GetBusinessDayAdjustmentsRecursive(value)); } } } } return(list); }
public static BusinessDayAdjustments Create(BusinessDayConventionEnum businessDayConvention, BusinessCenters businessCenters) { var result = new BusinessDayAdjustments { businessDayConvention = businessDayConvention, businessCenters = businessCenters }; return(result); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableBankBill"/> 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 PriceableBankBill(DateTime baseDate, Decimal amount, BankBillNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) : base(nodeStruct.Deposit.id, baseDate, amount, businessDayAdjustments, fixedRate) { SpotDateOffset = nodeStruct.SpotDate; BankBill = nodeStruct.Deposit; AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, nodeStruct.SpotDate); RiskMaturityDate = GetEffectiveDate(AdjustedStartDate, paymentCalendar, nodeStruct.Deposit.term, nodeStruct.BusinessDayAdjustments.businessDayConvention); YearFraction = GetYearFraction(BankBill.dayCountFraction.Value, AdjustedStartDate, RiskMaturityDate); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableCash"/> class. /// </summary> /// <param name="baseDate"></param> /// <param name="cash">The deposit.</param> /// <param name="amount">The cah amount.</param> /// <param name="term">The term of the cash flow.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="fixedRate">The fixed rate.</param> /// <param name="paymentCalendar">The payment Calendar.</param> protected PriceableCash(DateTime baseDate, Asset cash, Decimal amount, Period term, IBusinessCalendar paymentCalendar, BusinessDayAdjustments businessDayAdjustments, BasicQuotation fixedRate) : base(cash.id, baseDate, amount, businessDayAdjustments, fixedRate) { Term = term; RiskMaturityDate = paymentCalendar.Advance(BaseDate, OffsetHelper.FromInterval(Term, DayTypeEnum.Calendar), BusinessDayAdjustments.businessDayConvention); YearFraction = (decimal)Actual365.Instance.YearFraction(BaseDate, RiskMaturityDate); }
/// <summary> /// </summary> /// <param name="cache"></param> /// <param name="interestRateStream"></param> /// <param name="listCalculationPeriods"></param> /// <param name="fixingCalendar"></param> /// <param name="nameSpace"></param> /// <returns></returns> /// <exception cref="NotSupportedException"></exception> /// <exception cref="NotImplementedException"></exception> public static List <DateTime> GetAdjustedResetDates(ICoreCache cache, InterestRateStream interestRateStream, List <CalculationPeriod> listCalculationPeriods, IBusinessCalendar fixingCalendar, string nameSpace) { var adjustedResetDates = new List <DateTime>(); ResetDates resetDates = interestRateStream.resetDates; Period resetFrequency = IntervalHelper.FromFrequency(resetDates.resetFrequency); Period calculationPeriodFrequency = IntervalHelper.FromFrequency(interestRateStream.calculationPeriodDates.calculationPeriodFrequency); if (resetFrequency.period != calculationPeriodFrequency.period) { throw new NotSupportedException( $"Reset period type ({resetFrequency.period}) and calculation period type ({calculationPeriodFrequency.period}) are different. This is not supported."); } if (int.Parse(resetFrequency.periodMultiplier) != int.Parse(calculationPeriodFrequency.periodMultiplier)) { throw new NotSupportedException( $"Reset period frequency ({resetFrequency.period}) is not equal to calculation period frequency ({calculationPeriodFrequency.period}). This is not supported."); } BusinessDayAdjustments resetDatesAdjustments = resetDates.resetDatesAdjustments; ResetRelativeToEnum resetRelativeTo = resetDates.resetRelativeTo; if (fixingCalendar == null) { fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, resetDatesAdjustments.businessCenters, nameSpace); } foreach (CalculationPeriod calculationPeriodsInPaymentPeriod in listCalculationPeriods) { switch (resetRelativeTo) { case ResetRelativeToEnum.CalculationPeriodStartDate: { DateTime unadjustedResetDate = calculationPeriodsInPaymentPeriod.unadjustedStartDate; DateTime adjustedResetDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, unadjustedResetDate, resetDatesAdjustments); adjustedResetDates.Add(adjustedResetDate); break; } case ResetRelativeToEnum.CalculationPeriodEndDate: { DateTime unadjustedResetDate = calculationPeriodsInPaymentPeriod.unadjustedEndDate; DateTime adjustedResetDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, unadjustedResetDate, resetDatesAdjustments); adjustedResetDates.Add(adjustedResetDate); break; } default: { throw new NotImplementedException("resetRelativeTo"); } } } return(adjustedResetDates); }
public static BusinessDayAdjustments Create(BusinessDayConventionEnum businessDayConvention, string businessCentersAsString) { var result = new BusinessDayAdjustments { businessDayConvention = businessDayConvention, businessCenters = BusinessCentersHelper.Parse(businessCentersAsString) }; return(result); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="baseDate"></param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="calculation">The calculation class that determines if the swap is discounted or not.</param> /// <param name="fixedRate">The fixed rate.</param> protected PriceableSwapRateAsset(DateTime baseDate, BusinessDayAdjustments businessDayAdjustments, Calculation calculation, BasicQuotation fixedRate) { ModelIdentifier = "SimpleSwapAsset"; BaseDate = baseDate; Calculation = calculation; BusinessDayAdjustments = businessDayAdjustments; SetRate(fixedRate); StartDiscountFactor = 1.0m; CurveName = string.Empty; }
/// <summary> /// A helper to extract properties from a namedvalueset.. /// </summary> /// <param name="propertyCollection">The collection of properties.</param> public static BusinessDayAdjustments ExtractBusinessDayAdjustments(NamedValueSet propertyCollection) { var businessDayConvention = ExtractBusinessDayConvention(propertyCollection); var businessCenters = ExtractBusinessCenters(propertyCollection); var businessDayAdjustments = new BusinessDayAdjustments { businessDayConvention = businessDayConvention, businessCenters = businessCenters }; return(businessDayAdjustments); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRCap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="effectiveDate">The effective Date.</param> /// <param name="term">The cap term.</param> /// <param name="strike">The strike for each caplet.</param> /// <param name="lastResets">A list of reset rates. This may be null.</param> /// <param name="includeStubFlag">A flag: include the first stub periood or not.</param> /// <param name="paymentFrequency">The caplet frequency.</param> /// <param name="rollBackward">A flag which determines whether to roll /// the dates: Backward or Forward. Currency this is ignored.</param> /// <param name="resetOffset">The relative date offset for all the fixings.</param> /// <param name="paymentBusinessDayAdjustments">The payment business day adjustments.</param> /// <param name="capCalculation">The cap calculation.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="fixingCalendar"></param> public PriceableIRFloor(DateTime baseDate, DateTime effectiveDate, string term, Double strike, List <double> lastResets, Boolean includeStubFlag, string paymentFrequency, Boolean rollBackward, RelativeDateOffset resetOffset, BusinessDayAdjustments paymentBusinessDayAdjustments, Calculation capCalculation, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar) : base(baseDate, effectiveDate, term, strike, lastResets, includeStubFlag, paymentFrequency, rollBackward, resetOffset, paymentBusinessDayAdjustments, capCalculation, fixingCalendar, paymentCalendar) { IsCap = false; }
private static DateTime CalculatePaymentDate(PaymentDates paymentDates, PayRelativeToEnum payRelativeTo, IList <CalculationPeriod> calculationPeriodsInPamentPeriod, Offset paymentDaysOffset, BusinessDayAdjustments paymentDatesBusinessDayAdjustments, IBusinessCalendar paymentCalendar) { switch (payRelativeTo) { case PayRelativeToEnum.CalculationPeriodStartDate: { // To get the calculation period start date - obtain a reference to FIRST calculation period in the payment period. // CalculationPeriod firstCalculatinPeriodInPaymentPeriod = calculationPeriodsInPamentPeriod[0]; BusinessDayAdjustments paymentDatesAdjustments = paymentDates.paymentDatesAdjustments; // Adjust using paymentDatesAdjustments... // DateTime adjustedPaymentDate = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, firstCalculatinPeriodInPaymentPeriod.unadjustedStartDate, paymentDatesAdjustments); // Apply offset // if (null != paymentDaysOffset) { return(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustedPaymentDate, paymentDatesBusinessDayAdjustments, paymentDaysOffset)); } return(adjustedPaymentDate); } case PayRelativeToEnum.CalculationPeriodEndDate: { // To get the calculation period end date - obtain a reference to LAST calculation period in the payment period. // CalculationPeriod lastCalculatinPeriodInPaymentPeriod = calculationPeriodsInPamentPeriod[calculationPeriodsInPamentPeriod.Count - 1]; BusinessDayAdjustments paymentDatesAdjustments = paymentDates.paymentDatesAdjustments; // Adjust using paymentDatesAdjustments... // DateTime adjustedPaymentDate = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, lastCalculatinPeriodInPaymentPeriod.unadjustedEndDate, paymentDatesAdjustments); // Apply offset (if present) // return(null != paymentDaysOffset?AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustedPaymentDate, paymentDatesBusinessDayAdjustments, paymentDaysOffset) : adjustedPaymentDate); } case PayRelativeToEnum.ResetDate: { throw new NotImplementedException("payRelativeTo to ResetDate"); } default: { throw new NotImplementedException("payRelativeTo"); } } }
/// <summary> /// Initializes a new instance of the <see cref="PriceableRateIndex"/> class. /// </summary> /// <param name="baseDate"></param> /// <param name="amount">The amount.</param> /// <param name="rateIndex">Index of the rate.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="resetDateConvention">The reset date convention.</param> /// <param name="fixedRate">The fixed rate.</param> protected PriceableRateIndex(DateTime baseDate, Decimal amount, RateIndex rateIndex, BusinessDayAdjustments businessDayAdjustments, RelativeDateOffset resetDateConvention, BasicQuotation fixedRate) : base(rateIndex.id, baseDate, amount, businessDayAdjustments, fixedRate) { UnderlyingRateIndex = rateIndex; if (PeriodEnum.D != resetDateConvention.period) { throw new System.Exception("Only day units are supported!"); } ResetDateConvention = resetDateConvention; Id = rateIndex.id; }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="simpleIRSwap">This contains the minimal information for the swap.</param> /// <param name="spotDateOffset">All necessary data related to the spot period for the swap type.</param> /// <param name="calculation">Contians information related to the floating leg.</param> /// <param name="businessDayAdjustments">The business day adjustments for all payments.</param> /// <param name="underlyingRateIndex">Index of the floating leg.</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, RelativeDateOffset spotDateOffset, Calculation calculation, BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, simpleIRSwap, spotDateOffset, calculation, 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> /// Converts t an adjustable date type. /// </summary> /// <param name="unadjustedDate"></param> /// <param name="businessDayConvention"></param> /// <returns></returns> public static AdjustableDate ToAdjustableDate(DateTime unadjustedDate, BusinessDayConventionEnum businessDayConvention) { var result = new AdjustableDate { unadjustedDate = ToUnadjustedIdentifiedDate(unadjustedDate) }; var businessDayAdjustments = new BusinessDayAdjustments { businessDayConvention = businessDayConvention, businessDayConventionSpecified = true }; result.dateAdjustments = businessDayAdjustments; return(result); }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="resetDates">The reset date information.</param> /// <param name="rateOption">A rateOption.</param> /// <param name="amount">The amount.</param> /// <param name="strike">The strike.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="marketQuotes">The market Quotes. This must include the volatility.</param> protected PriceableSimpleRateOptionAsset(DateTime baseDate, RelativeDateOffset resetDates, SimpleFra rateOption, Decimal amount, Decimal strike, BusinessDayAdjustments businessDayAdjustments, BasicAssetValuation marketQuotes) { Strike = strike; ResetDateOffset = resetDates; RateOption = rateOption; ModelIdentifier = "SimpleRateOptionAsset"; BaseDate = baseDate; BusinessDayAdjustments = businessDayAdjustments; Notional = amount; var quotes = new List <BasicQuotation>(marketQuotes.quote); SetQuote(VolatilityQuotationType, quotes); }
public List <DateTime> BuildDates(ILogger logger, ICoreCache cache, String nameSpace, BillSwapPricerDatesRange billSwapPricerDatesRange, IBusinessCalendar paymentCalendar) { CalculationPeriodFrequency frequency = CalculationPeriodFrequencyHelper.Parse(billSwapPricerDatesRange.RollFrequency, billSwapPricerDatesRange.RollConvention); StubPeriodTypeEnum? initialStub = null; if (!String.IsNullOrEmpty(billSwapPricerDatesRange.InitialStubPeriod)) { initialStub = EnumHelper.Parse <StubPeriodTypeEnum>(billSwapPricerDatesRange.InitialStubPeriod); } StubPeriodTypeEnum?finalStub = null; if (!String.IsNullOrEmpty(billSwapPricerDatesRange.FinalStubPeriod)) { finalStub = EnumHelper.Parse <StubPeriodTypeEnum>(billSwapPricerDatesRange.FinalStubPeriod); } //BusinessDayAdjustments adjustments = BusinessDayAdjustmentsHelper.Create(BusinessDayConventionEnum.NONE, ""); //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustments.businessCenters);//Make sure this builds a valid calendar! //} BusinessDayAdjustments calculationPeriodDayAdjustments = BusinessDayAdjustmentsHelper.Create(billSwapPricerDatesRange.BusinessDayConvention, billSwapPricerDatesRange.Calendar); if (paymentCalendar == null) { paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, calculationPeriodDayAdjustments.businessCenters, nameSpace); } CalculationPeriodsPrincipalExchangesAndStubs result = CalculationPeriodGenerator.GenerateAdjustedCalculationPeriods( billSwapPricerDatesRange.StartDate, billSwapPricerDatesRange.EndDate, billSwapPricerDatesRange.FirstRegularPeriodStartDate, frequency, calculationPeriodDayAdjustments, initialStub, finalStub, paymentCalendar ); foreach (CalculationPeriod regularCalculationPeriod in result.GetRegularAndStubPeriods()) { // Adjust both startDate & endDate of period // CalculationPeriodHelper.SetAdjustedDates(regularCalculationPeriod, AdjustedDateHelper.ToAdjustedDate(paymentCalendar, regularCalculationPeriod.unadjustedStartDate, calculationPeriodDayAdjustments), AdjustedDateHelper.ToAdjustedDate(paymentCalendar, regularCalculationPeriod.unadjustedEndDate, calculationPeriodDayAdjustments)); } var listResult = result.GetRegularAndStubPeriods().Select(regularCalculationPeriod => regularCalculationPeriod.adjustedStartDate).ToList(); listResult.Add(result.GetRegularAndStubPeriods()[result.GetRegularAndStubPeriods().Count - 1].adjustedEndDate); return(listResult); }