Ejemplo n.º 1
0
        ///// <summary>
        ///// Initializes a new instance of the <see cref="PriceableFxSpotRate"/> 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 PriceableFxTNRate(DateTime baseDate, RelativeDateOffset spotDateOffset, FxRateAsset fxRateAsset, BasicQuotation fxForward)
        //    : this(1.0m, baseDate, fxRateAsset,
        //           spotDateOffset, fxForward)
        //{}

        /// <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 PriceableFxTNRate(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 = fixingCalendar.Advance(AdjustedStartDate, OffsetHelper.FromInterval(Tenor, DayTypeEnum.Business), SpotDateOffset.businessDayConvention);
            RiskMaturityDate = fixingCalendar.Advance(AdjustedStartDate, OffsetHelper.FromInterval(Tenor, DayTypeEnum.Business), SpotDateOffset.businessDayConvention);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RateSpreadCurve"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 ///  <param name="nameSpace">The client namespace</param>
 /// <param name="properties">The properties.</param>
 /// <param name="refCurve">The reference parent curveid.</param>
 /// <param name="value">The values.</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="rollCalendar">The rollCalendar.</param>
 public RateSpreadCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, IPricingStructure refCurve, Decimal value,
                        IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
     : base(logger, cache, nameSpace, AdjustMarketQuotes(value, refCurve.GetFpMLData(), PropertyHelper.ExtractUniqueCurveIdentifier(properties)), properties,
            fixingCalendar, rollCalendar)
 {
     PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties);
     ReferenceCurveId     = refCurve.GetPricingStructureId();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Deal settle.
        /// </summary>
        /// <param name="dealDate"></param>
        /// <param name="settC"></param>
        /// <param name="hols"></param>
        /// <returns></returns>
        public static DateTime SettFromDeal(DateTime dealDate, BondSettlementEnum settC,
                                            IBusinessCalendar hols)
        {
            switch (settC)
            {
            case BondSettlementEnum.SC_dealDate: return(dealDate);

            case BondSettlementEnum.SC_1bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(1), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_2bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(2), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_1b1cd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(1), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING).AddDays(1));

            case BondSettlementEnum.SC_3bd:
            case BondSettlementEnum.SC_3bd_6bdLO: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(3), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_3b1cd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(3), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING).AddDays(1));

            case BondSettlementEnum.SC_4bd:
            case BondSettlementEnum.SC_4bd_6bdLO: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(4), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_5bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(5), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_7bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(7), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_3d: return(hols.Roll(dealDate.AddDays(3), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_7d: return(hols.Roll(dealDate.AddDays(7), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_7c1bd: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(7), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));

            case BondSettlementEnum.SC_3cd: return(hols.Roll(dealDate.AddDays(3), BusinessDayConventionEnum.FOLLOWING));

            //               case BondSettlementHelper.BondSettlementEnum.SC_Canada:
            //                   return

            default: return(hols.Advance(dealDate, OffsetHelper.FromInterval(IntervalHelper.FromDays(1), DayTypeEnum.Business), BusinessDayConventionEnum.FOLLOWING));
            }

            /*           switch (settC)
             *         {
             *             case SC_Canada:
             *                 CalendarDate(ym, mm, dm, maturityDate);
             *                 return TCs->NextBizDay(dealDate, 2 + (dealDate <= UnadjustedDate(ym - 3, mm, dm)));
             *
             *             case SC_Austria: return TCs->NextBizDay(dealDate + 15 - DayOfWeek(dealDate), 0);
             *
             *             case SC_Australia:
             *                 CalendarDate(ym, mm, dm, maturityDate);
             *                 return TCs->NextBizDay(dealDate, dealDate > UnadjustedDate(ym, mm - 6, dm) ? 1 : 3);
             *
             *             case SC_SouthAfrica:
             *                 settDate = dealDate + 15 - DayOfWeek(dealDate + 4);
             *                 if (!TCs->IsBizDay(settDate + 1)) settDate--;
             *                 return settDate;
             *         }
             *         return dealDate;*/
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFxRateCashflow"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustAccrualDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="baseRate">The base rate for a nettable fixed/floating cash flow. </param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountfraction">Type of day Countfraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecastrateindex.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fradiscounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableFloatingRateCoupon
 (
     string cashlfowId
     , bool payerIsBase
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustAccrualDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountfraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Decimal baseRate
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashlfowId
         , CouponType.FloatingRate
         , payerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustAccrualDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , dayCountfraction
         , observedRate
         , notionalAmount
         , paymentDate
         , discountingType
         , discountRate
         , fraDiscounting
         , paymentCalendar)
 {
     BaseRate        = baseRate;
     FixingCalendar  = fixingCalendar;
     ModelIdentifier = "DualCurveCouponModel";
     Id = cashlfowId;
     ForwardStartDate         = AccrualStartDate;
     ForecastRateIndex        = forecastRateIndex;
     FixingDateRelativeOffset = fixingDateRelativeOffset;
     ResetRelativeTo          = resetRelativeTo;
     Margin             = margin;
     AdjustedFixingDate = GetResetDate(resetRelativeTo, fixingDateRelativeOffset);
     if (observedRate != null)
     {
         RateObservation = RateObservationHelper.Parse(AdjustedFixingDate, (decimal)observedRate, "1");
     }
     SetRateObservation(RateObservation, ResetDate);
     ForecastCurveName = CurveNameHelpers.GetForecastCurveName(forecastRateIndex);
 }
 /// <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");
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableCapFloorCoupon"/> class.
 /// </summary>
 /// <param name="cashlFowId">The stream id.</param>
 /// <param name="buyerIsBase">The buyer is base flag.</param>
 /// <param name="capStrike">The Cap strike.</param>
 /// <param name="floorStrike">The floor strike.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="observedRate">The observed Rate. If this is not null, then it is used.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="adjustedFixingDate">The adjusted fixing date.</param>
 /// <param name="dayCountFraction">Type of day Count fraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="forecastRateIndex">The forecast rate index.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fra discounting</param>
 /// <param name="fixingCalendar"> The fixingCalendar. </param>
 /// <param name="paymentCalendar"> The paymentCalendar. </param>
 public PriceableCapFloorCoupon
 (
     string cashlFowId
     , bool buyerIsBase
     , decimal?capStrike
     , decimal?floorStrike
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , DateTime adjustedFixingDate
     , DayCountFraction dayCountFraction
     , Decimal margin
     , Decimal?observedRate
     , Money notionalAmount
     , DateTime paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashlFowId
         , buyerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustedFixingDate
         , dayCountFraction
         , margin
         , observedRate
         , notionalAmount
         , paymentDate
         , forecastRateIndex
         , discountingType
         , discountRate
         , fraDiscounting
         , fixingCalendar
         , paymentCalendar)
 {
     CapStrike             = capStrike;
     FloorStrike           = floorStrike;
     VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(forecastRateIndex);
     if (capStrike != null && floorStrike == null)
     {
         PriceableCouponType = CouponType.Cap;
         ModelIdentifier     = "DualCurveCapModel";
         IsCall = true;
     }
     if (floorStrike != null && capStrike == null)
     {
         PriceableCouponType = CouponType.Floor;
         ModelIdentifier     = "DualCurveFloorModel";
     }
     if (floorStrike != null && capStrike != null)
     {
         PriceableCouponType = CouponType.Collar;
         ModelIdentifier     = "DualCurveCollarModel";
     }
 }
Ejemplo n.º 7
0
        private static InterestRateStream GetCashflowsSchedule(IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                                                               CapFloorLegParametersRange legParametersRange)
        {
            InterestRateStream stream    = InterestRateStreamParametricDefinitionGenerator.GenerateStreamDefinition(legParametersRange);
            Cashflows          cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream, fixingCalendar, paymentCalendar);

            stream.cashflows = cashflows;
            return(stream);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RateSpreadCurve"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 ///  <param name="nameSpace">The client namespace</param>
 /// <param name="referenceCurve">The reference parent curve id.</param>
 /// <param name="spreadAssets">The spreads by asset.</param>
 /// <param name="properties">The properties of the new spread curve.</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="rollCalendar">The rollCalendar.</param>
 public RateSpreadCurve(ILogger logger, ICoreCache cache, string nameSpace,
                        IRateCurve referenceCurve, QuotedAssetSet spreadAssets, NamedValueSet properties,
                        IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
     : base(logger, cache, nameSpace, ProcessQuotedAssetSet(logger, cache, nameSpace, referenceCurve, spreadAssets, properties, fixingCalendar, rollCalendar), properties, fixingCalendar, rollCalendar)
 {
     PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties);
     BaseCurve            = referenceCurve;
     ReferenceCurveId     = BaseCurve.GetPricingStructureId();
 }
Ejemplo n.º 9
0
        /////<summary>
        /////</summary>
        /////<returns></returns>
        //public decimal GetSpotRate()
        //{
        //    var fxVal = (FxCurveValuation)GetFpMLData().Second;
        //    BasicAssetValuation spotRateAsset = (from spotRateAssets in fxVal.spotRate.assetQuote
        //                                         where spotRateAssets.objectReference.href.EndsWith("-Equity-SP", StringComparison.InvariantCultureIgnoreCase)//TODO FIX This!
        //                                         select spotRateAssets).Single();
        //    decimal spotRate = spotRateAsset.quote[0].value;
        //    return spotRate;
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace">THe client namespace</param>
        /// <param name="equityId">THe curve asset.</param>
        /// <param name="fixingCalendar"></param>
        /// <param name="rollCalendar"></param>
        /// <param name="baseDate"></param>
        /// <returns></returns>
        protected static DateTime GetSettlementDate(ILogger logger, ICoreCache cache, string nameSpace,
                                                    EquityCurveIdentifier equityId, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar, DateTime baseDate)
        {
            BasicAssetValuation bav = BasicAssetValuationHelper.Create(BasicQuotationHelper.Create(0, "MarketQuote", PriceQuoteUnitsEnum.Price.ToString()));
            var assetId             = BuildSpotAssetId(equityId);
            var priceableAsset      = (IPriceableEquityAssetController)PriceableAssetFactory.Create(logger, cache, nameSpace, assetId, baseDate, bav, fixingCalendar, rollCalendar);

            return(priceableAsset.GetRiskMaturityDate());
        }
Ejemplo n.º 10
0
 /// <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="marketQuote">The market quote.</param>
 /// <param name="quoteType">THe quote Type</param>
 public PriceableBondSpot(DateTime baseDate, BondNodeStruct nodeStruct, IBusinessCalendar settlementCalendar, BasicQuotation marketQuote, BondPriceEnum quoteType)
     : base(baseDate, nodeStruct.Bond.faceAmount, nodeStruct.Bond.currency, nodeStruct.SettlementDate, nodeStruct.ExDivDate, nodeStruct.BusinessDayAdjustments, marketQuote, quoteType)
 {
     Id = nodeStruct.Bond.id;
     SettlementDateCalendar = settlementCalendar;
     //Get the settlement date
     SettlementDate = GetSettlementDate(baseDate, settlementCalendar, nodeStruct.SettlementDate);
     MaturityDate   = SettlementDate;
 }
Ejemplo n.º 11
0
 /// <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;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Calculate the end date of the FRA which
        /// will replace the cash instrument
        /// </summary>
        /// <param name="calendar"></param>
        /// <param name="assetController"></param>
        /// <returns></returns>
        public DateTime CalculateFraEndTime(IBusinessCalendar calendar, IPriceableRateAssetController assetController)//,
        //string currency, string rollConvention)
        {
            var deposit = (PriceableDeposit)assetController;
            BusinessDayConventionEnum adjustment = deposit.BusinessDayAdjustments.businessDayConvention;

            return(DatePeriodHelper.AddPeriod(assetController.GetRiskMaturityDate(),
                                              "3M", calendar, adjustment.ToString(), null));
        }
Ejemplo n.º 13
0
 /// <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"></param>
 public PriceableXibor(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);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RateBasisCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="spreadFpmlData">The FPML data.</param>
        /// <param name="properties">The properties</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public RateBasisCurve(ILogger logger, ICoreCache cache, string nameSpace,
                              Pair <PricingStructure, PricingStructureValuation> spreadFpmlData, NamedValueSet properties,
                              IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, spreadFpmlData, properties, fixingCalendar, rollCalendar)
        {
            PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties);
            var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(properties);

            ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null;
        }
        protected static Cashflows BuildCashflow(InterestRateStream stream, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar)
        {
            var cashflows = stream.cashflows;

            if (stream.cashflows == null || stream.cashflows.cashflowsMatchParameters == false)
            {
                cashflows = FixedAndFloatingRateStreamCashflowGenerator.GetCashflows(stream, fixingCalendar, paymentCalendar);
            }
            return(cashflows);
        }
Ejemplo n.º 16
0
        public virtual IBusinessCalendar GetBusinessCalendar(string businessCalendarRef)
        {
            IBusinessCalendar businessCalendar = businessCalendars[businessCalendarRef];

            if (businessCalendar == null)
            {
                throw new ActivitiException("Requested business calendar " + businessCalendarRef + " does not exist. Allowed calendars are " + this.businessCalendars.Keys + ".");
            }
            return(businessCalendar);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XccySpreadCurve"/> class,
 /// by applying spreads to an existing RateCurve. Using FX Curve to create synthetic swaps
 /// for the period under 1Y.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 /// <param name="nameSpace">The client namespace</param>
 /// <param name="properties">The properties of the new curve.</param>
 /// <param name="baseCurve">The base zero curve.</param>
 /// <param name="quoteCurve">The quote zero curve.</param>
 /// <param name="fxCurve">The FX curve, used for constructing synthetic deposits</param>
 /// <param name="inputs">The quoted asset instruments.</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="rollCalendar">The rollCalendar.</param>
 public XccySpreadCurve(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, QuotedAssetSet inputs,
                        IRateCurve baseCurve, IRateCurve quoteCurve, FxCurve fxCurve,
                        IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
     : base(logger, cache, nameSpace, new RateCurveIdentifier(properties))
 {
     BasicAssetValuation[] assetQuote = inputs.assetQuote;
     string[]  instruments            = ExtractInstruments(assetQuote, null);
     decimal[] values = ExtractValues(assetQuote, null);
     Initialize(logger, cache, nameSpace, properties, baseCurve, quoteCurve, instruments, values, fxCurve, fixingCalendar, rollCalendar);
 }
Ejemplo n.º 18
0
 /// <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);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SecuredRateCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="fpmlData">The FPML data.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public SecuredRateCurve(ILogger logger, ICoreCache cache, string nameSpace,
                                Pair <PricingStructure, PricingStructureValuation> fpmlData,
                                NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, fpmlData, properties, fixingCalendar, rollCalendar)
        {
            var refId    = properties.GetValue <String>(BondProp.ReferenceBond, true);
            var refItem  = cache.LoadItem <Bond>(nameSpace + '.' + "ReferenceData.FixedIncome." + refId);
            var refAsset = refItem.Data as Bond;

            UnderlyingAsset = refAsset;
        }
Ejemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        protected IBusinessCalendar ExtractPaymentCalendar(ICoreCache cache, string nameSpace, NamedValueSet properties)
        {
            string[]          paymentCalendars = properties.GetArray <string>("PaymentCenters");
            IBusinessCalendar paymentCalendar  = null;

            if (paymentCalendars != null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, paymentCalendars, nameSpace);
            }
            return(paymentCalendar);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        protected IBusinessCalendar ExtractFixingCalendar(ICoreCache cache, string nameSpace, NamedValueSet properties)
        {
            string[]          fixingCalendars = properties.GetArray <string>("FixingCenters");
            IBusinessCalendar fixingCalendar  = null;

            if (fixingCalendars != null)
            {
                fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fixingCalendars, nameSpace);
            }
            return(fixingCalendar);
        }
Ejemplo n.º 22
0
 ///<summary>
 ///</summary>
 public DateTime GetSettlementDate(DateTime baseDate, IBusinessCalendar settlementCalendar, RelativeDateOffset settlementDateOffset)
 {
     try
     {
         return(settlementCalendar.Advance(baseDate, settlementDateOffset, settlementDateOffset.businessDayConvention));
     }
     catch (System.Exception)
     {
         throw new System.Exception("No settlement calendar set.");
     }
 }
Ejemplo n.º 23
0
 /// <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)
 {
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Builds this instance.
        /// </summary>
        public override void Build(ILogger logger, ICoreCache cache, string nameSpace,
                                   IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
        {
            PriceableCommodityAssets = PriceableAssetFactory.CreatePriceableCommodityAssets(logger, cache, nameSpace, GetFxCurveValuation().baseDate.Value, GetFxCurveValuation().spotRate, fixingCalendar, rollCalendar);
            var termCurve = ((FxCurveValuation)PricingStructureValuation).fxForwardCurve;

            termCurve.point = CommodityBootstrapper.Bootstrap(PriceableCommodityAssets, GetFxCurveValuation().baseDate.Value, termCurve.extrapolationPermitted,
                                                              termCurve.interpolationMethod);
            SetFpMLData(new Pair <PricingStructure, PricingStructureValuation>(PricingStructure, PricingStructureValuation));
            SetInterpolator(GetFxCurveValuation().baseDate.Value, Holder);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Process a PPD Grid. The result is a Market structure that camn be published.
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="cache">The cache.</param>
        /// <param name="swapCurve">The latest rate curve</param>
        /// <param name="ppdGrid">The raw Points Per Day matrix supplied from the subscriber</param>
        /// <param name="id">The id to use in publishing the curve</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <returns></returns>
        public static Market ProcessSwaption(ILogger logger, ICoreCache cache, Market swapCurve, SwaptionPPDGrid ppdGrid, string id, string nameSpace)
        {
            var mkt   = swapCurve;
            var curve = new SimpleRateCurve(mkt);
            // List the values so we can build our ATM vols
            var atmVols = new Dictionary <SimpleKey, decimal>();
            // Create a calendar to use to modify the date
            // default to be Sydney...
            IBusinessCalendar bc = BusinessCenterHelper.ToBusinessCalendar(cache, new[] { "AUSY" }, nameSpace); //BusinessCalendarHelper("AUSY");
            // Use some logic to get the spot date to use
            // LPM Spot lag is 2 days (modfollowing)
            DateTime spotDate = curve.GetSpotDate();

            // Extract each surface and build an ATM engine therefrom
            // Build a list of all possible engines
            foreach (string e in ExpiryKeys)
            {
                // Assume frequency = 4 months until 3 years tenor is reached
                Period expiration         = PeriodHelper.Parse(e);
                double expiryYearFraction = expiration.ToYearFraction();
                foreach (string t in TenorKeys)
                {
                    // Create a Swaprate for each expiry/tenor pair
                    // Assume frequency = 4 months until 3 years tenor is reached
                    double tenorYearFraction = PeriodHelper.Parse(t).ToYearFraction();
                    int    frequency         = tenorYearFraction < 4 ? 4 : 2;
                    // Calculation date
                    // Discount factors
                    // Offsets (elapsed days)
                    var rates = new SwapRate(logger, cache, nameSpace, "AUSY", curve.BaseDate, "ACT/365.FIXED", curve.GetDiscountFactors(), curve.GetDiscountFactorOffsets(), frequency, BusinessDayConventionEnum.MODFOLLOWING);
                    // Calculate the volatility given PPD and swap curve
                    DateTime expiry = bc.Roll(expiration.Add(spotDate), BusinessDayConventionEnum.FOLLOWING);
                    decimal  vol    = CalculateAtmVolatility(rates, expiry, ppdGrid, expiryYearFraction, tenorYearFraction);
                    atmVols.Add(new SimpleKey(e, t), vol);
                }
            }
            var vols = new object[atmVols.Count + 1, 3];
            var i    = 1;

            vols[0, 0] = "Expiry";
            vols[0, 1] = "Tenor";
            vols[0, 2] = "0";
            foreach (var key in atmVols.Keys)
            {
                vols[i, 0] = key.Expiry;
                vols[i, 1] = key.Tenor;
                vols[i, 2] = atmVols[key];
                i++;
            }
            DateTime buildDateTime = swapCurve.Items1[0].buildDateTime;
            var      volSurface    = new VolatilitySurface(vols, new VolatilitySurfaceIdentifier(id), curve.BaseDate, buildDateTime);

            return(CreateMarketDocument(volSurface.GetFpMLData()));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Adjusteds the dates from effective date.
        /// </summary>
        /// <param name="effectiveDate">The effective date.</param>
        /// <param name="terminationDate">The termination date.</param>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <param name="businessCenters">The business centers.</param>
        /// <param name="dateAdjustmentConvention">The date adjustment convention.</param>
        /// <returns>A vertical arrray of dates.</returns>
        public object[,] AdjustedDatesFromEffectiveDate(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention,
                                                        string businessCenters, string dateAdjustmentConvention)
        {
            BusinessCenters   centers  = BusinessCentersHelper.Parse(businessCenters);
            IBusinessCalendar calendar = Engine.ToBusinessCalendar(centers);
            var adjustments            = EnumHelper.Parse <BusinessDayConventionEnum>(dateAdjustmentConvention);
            var adjustedDateSchedule   = AdjustedDateScheduler.AdjustedDatesFromEffectiveDate(effectiveDate, terminationDate, periodInterval, rollConvention, calendar, adjustments);
            var result = RangeHelper.ConvertArrayToRange(adjustedDateSchedule);

            return(result);
        }
Ejemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timerEntity"></param>
        /// <param name="variableScope"></param>
        protected internal virtual void RestoreExtraData(IJobEntity timerEntity, IVariableScope variableScope)
        {
            string activityId = timerEntity.JobHandlerConfiguration;

            if (timerEntity.JobHandlerType.Equals(TimerStartEventJobHandler.TYPE, StringComparison.CurrentCultureIgnoreCase) || timerEntity.JobHandlerType.Equals(TriggerTimerEventJobHandler.TYPE, StringComparison.CurrentCultureIgnoreCase))
            {
                activityId = TimerEventHandler.GetActivityIdFromConfiguration(timerEntity.JobHandlerConfiguration);
                string endDateExpressionString = TimerEventHandler.GetEndDateFromConfiguration(timerEntity.JobHandlerConfiguration);

                if (!(endDateExpressionString is null))
                {
                    IExpression endDateExpression = processEngineConfiguration.ExpressionManager.CreateExpression(endDateExpressionString);

                    string endDateString = null;

                    IBusinessCalendar businessCalendar = processEngineConfiguration.BusinessCalendarManager.GetBusinessCalendar(GetBusinessCalendarName(TimerEventHandler.GeCalendarNameFromConfiguration(timerEntity.JobHandlerConfiguration), variableScope));

                    if (endDateExpression != null)
                    {
                        object endDateValue = endDateExpression.GetValue(variableScope);
                        if (endDateValue is string)
                        {
                            endDateString = (string)endDateValue;
                        }
                        else if (endDateValue is DateTime)
                        {
                            timerEntity.EndDate = (DateTime)endDateValue;
                        }
                        else
                        {
                            throw new ActivitiException("Timer '" + ((IExecutionEntity)variableScope).ActivityId + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
                        }

                        if (!timerEntity.EndDate.HasValue)
                        {
                            timerEntity.EndDate = businessCalendar.ResolveEndDate(endDateString).GetValueOrDefault();
                        }
                    }
                }
            }

            int maxIterations = 1;

            if (!(timerEntity.ProcessDefinitionId is null))
            {
                Process process = ProcessDefinitionUtil.GetProcess(timerEntity.ProcessDefinitionId);
                maxIterations = GetMaxIterations(process, activityId);
                if (maxIterations <= 1)
                {
                    maxIterations = GetMaxIterations(process, activityId);
                }
            }
            timerEntity.MaxIterations = maxIterations;
        }
Ejemplo n.º 28
0
        private static double GetParRateFromRange(ILogger logger, ICoreCache cache, IRateCurve forwardCurve, IRateCurve discountCurve,
                                                  IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, FraInputRange fraInputRange, String nameSpace)
        {
            Fra fra = ProductFactory.GetFpMLFra(fraInputRange);
            //var forwardCurve = ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.ForwardCurveId);
            //var discountCurve = (RateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.DiscountingCurveId);
            var market       = CreateMarket(discountCurve, forwardCurve);
            var priceInMoney = GetParRate(logger, cache, fixingCalendar, paymentCalendar, fra, fraInputRange.ValuationDate, market, nameSpace);

            return(priceInMoney);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableIRSwap"/> 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 PriceableIRSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct,
                               IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate)
            : base(baseDate, nodeStruct, 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();
        }
Ejemplo n.º 30
0
 /// <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;
 }