Пример #1
0
        public void CreateValuationFixedStream()
        {
            DateTime valuationDate   = DateTime.Today;
            var      irFloaterPricer = new FloaterPricer();
            string   discountCurveID = BuildAndCacheRateCurve(valuationDate);
            //string projectionCurveID = discountCurveID;
            SwapLegParametersRange_Old       receiveFixedLegParameters = CreateFixedAUD_6MSwapLegParametersRange(CounterParty, _NAB, valuationDate, 0.08m, "ACT/365.FIXED", "AUSY", "FOLLOWING", "AUSY", "NONE", discountCurveID);
            ValuationRange                   valuationRange            = CreateValuationRangeForNAB(valuationDate);
            List <DetailedCashflowRangeItem> receiveCFRangeItemList    = FloaterPricer.GetDetailedCashflowsTestOnly(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null, receiveFixedLegParameters, valuationRange);
            var tradeRange = new TradeRange {
                Id = "TradeId_12345", TradeDate = valuationDate
            };
            var leg2PrincipleExchangeCashflowList       = new List <PrincipalExchangeCashflowRangeItem>();
            var leg2BulletPaymentList                   = new List <AdditionalPaymentRangeItem>();
            List <PartyIdRangeItem>           partyList = GetPartyList("NAB", "book", "MCHammer", "counterparty");
            List <OtherPartyPaymentRangeItem> otherPartyPaymentRangeItems = GetOtherPartyPaymentList("counterparty", "cost center");
            //  Get price and swap representation using non-vanilla PRICE function.
            //
            string valuatonId = irFloaterPricer.CreateValuation(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null,
                                                                CreateValuationSetList2(12345.67, -0.321), valuationRange, tradeRange,
                                                                receiveFixedLegParameters,
                                                                receiveCFRangeItemList,
                                                                leg2PrincipleExchangeCashflowList,
                                                                leg2BulletPaymentList,
                                                                partyList, otherPartyPaymentRangeItems);
            var valuationReport = Engine.Cache.LoadObject <ValuationReport>(Engine.NameSpace + "." + valuatonId);

            Debug.Print(XmlSerializerHelper.SerializeToString(valuationReport));
        }
Пример #2
0
        public static double GetPremiumImpl(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            SwapLegParametersRange payLegParametersRange,
            SwapLegParametersRange receiveLegParametersRange,
            SwaptionParametersRange swaptionTermsRange,
            ValuationRange valuationRange)
        {
            InterestRateStream payStream     = null;
            InterestRateStream receiveStream = null;

            UpdateCashflowsWithAmounts(logger, cache, nameSpace, payStream, payLegParametersRange, valuationRange);
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, receiveStream, receiveLegParametersRange, valuationRange);
            Money  fv         = CashflowsHelper.GetForecastValue(payStream.cashflows);
            Money  pv         = CashflowsHelper.GetPresentValue(payStream.cashflows);
            double tillExpiry = (swaptionTermsRange.ExpirationDate - valuationRange.ValuationDate).TotalDays / 365.0;
            //Debug.Print("Future value :{0}", fv.amount);
            //Debug.Print("Present value :{0}", pv.amount);
            // get swaption price
            //
            double pricePerDollar = BlackModel.GetSwaptionValue((double)payLegParametersRange.CouponOrLastResetRate, (double)swaptionTermsRange.StrikeRate, (double)swaptionTermsRange.Volatility, tillExpiry);
            double premium        = System.Math.Abs((double)payLegParametersRange.NotionalAmount * pricePerDollar);

            return(premium);
        }
        public void GetPrice2Vanilla()
        {
            DateTime valuationDate    = DateTime.Today;
            var      irCapFloorPricer = new CapFloorPricer();
            var      curveId          = BuildAndCacheRateCurve(valuationDate);

            foreach (CapFloorType capFloorType in new[] { CapFloorType.Cap, CapFloorType.Floor })
            {
                Debug.Print("Type: {0}", capFloorType);
                CapFloorLegParametersRange_Old capLeg = GetCapFloorInputParameters(valuationDate, valuationDate.AddMonths(6), valuationDate.AddYears(5),
                                                                                   capFloorType, "Standard", curveId, curveId);
                ValuationRange valuationRange                 = CreateValuationRangeForNAB(valuationDate);
                List <DateTimeDoubleRangeItem>   notional     = GetAmortNotional(capLeg, 3);
                List <DetailedCashflowRangeItem> cashflowList =
                    irCapFloorPricer.GetDetailedCashflowsWithNotionalSchedule(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null, capLeg, notional, valuationRange);
                TradeRange tradeRange            = null;
                var        leg1BulletPaymentList = new List <AdditionalPaymentRangeItem>();
                List <FeePaymentRangeItem> feePaymentRangeItems = GetFeeList("counterparty", "book");
                //  Get price and swap representation using non-vanilla PRICE function.
                //
                var newCashflowList = cashflowList.Cast <InputCashflowRangeItem>().ToList();
                Pair <ValuationResultRange, CapFloor> nonVanillaPriceImpl = CapFloorPricer.GetPriceAndGeneratedFpML(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null,
                                                                                                                    valuationRange, tradeRange, capLeg,
                                                                                                                    newCashflowList, null, leg1BulletPaymentList, feePaymentRangeItems);
                // NO PExs
                //
                CollectionAssertExtension.IsEmpty(nonVanillaPriceImpl.Second.capFloorStream.cashflows.principalExchange);
                // No payments
                //
                CollectionAssertExtension.IsEmpty(nonVanillaPriceImpl.Second.additionalPayment);
                Debug.Print(ValuationResultRangeToString(nonVanillaPriceImpl.First));
            }
        }
        public void CreateValuationVanilla()
        {
            DateTime valuationDate    = DateTime.Today;
            var      irCapFloorPricer = new CapFloorPricer();
            var      curveId          = BuildAndCacheRateCurve(valuationDate);

            foreach (CapFloorType capFloorType in new[] { CapFloorType.Cap, CapFloorType.Floor })
            {
                Debug.Print("Type: {0}", capFloorType);
                CapFloorLegParametersRange_Old capLeg = GetCapFloorInputParameters(valuationDate, valuationDate.AddMonths(6), valuationDate.AddYears(5),
                                                                                   capFloorType, "Standard", curveId, curveId);
                ValuationRange valuationRange                 = CreateValuationRangeForNAB(valuationDate);
                List <DateTimeDoubleRangeItem>   notional     = GetAmortNotional(capLeg, 3);
                List <DetailedCashflowRangeItem> cashflowList =
                    irCapFloorPricer.GetDetailedCashflowsWithNotionalSchedule(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null, capLeg, notional, valuationRange);
                switch (capFloorType)
                {
                case CapFloorType.Cap:
                    cashflowList[0].CouponType = "cap";    // that should test case insensitive nature of the coupons
                    cashflowList[1].CouponType = "Cap";    //

                    break;

                case CapFloorType.Floor:
                    cashflowList[0].CouponType = "floor";    // that should test case insensitive nature of the coupons
                    cashflowList[1].CouponType = "Floor";    //

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                var tradeRange = new TradeRange {
                    TradeDate = DateTime.Now
                };
                var leg1BulletPaymentList = new List <AdditionalPaymentRangeItem>();
                var newCashflowList       = cashflowList.Cast <InputCashflowRangeItem>().ToList();
                //  Get price and swap representation using non-vanilla PRICE function.
                //
                List <StringObjectRangeItem>      valuationSetList            = CreateValuationSetList2(1111, 12);
                List <PartyIdRangeItem>           partyList                   = GetPartyList("NAB", "book", "MCHammer", "counterparty");
                List <OtherPartyPaymentRangeItem> otherPartyPaymentRangeItems = GetOtherPartyPaymentList("counterparty", "cost center");
                List <FeePaymentRangeItem>        feePaymentRangeItems        = GetFeeList("counterparty", "book");
                string id = irCapFloorPricer.CreateValuation(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null,
                                                             valuationSetList, valuationRange, tradeRange,
                                                             capLeg, newCashflowList, null, leg1BulletPaymentList,
                                                             partyList, otherPartyPaymentRangeItems, feePaymentRangeItems);
                var valuationReport = Engine.Cache.LoadObject <ValuationReport>(Engine.NameSpace + "." + id);
                Debug.Print(XmlSerializerHelper.SerializeToString(valuationReport));
            }
        }
Пример #5
0
        internal static Pair <ValuationResultRange, Swap> GetPriceAndGeneratedFpMLSwap(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            SwapLegParametersRange_Old leg1ParametersRange,
            List <DetailedCashflowRangeItem> leg1DetailedCashflowsList,
            List <PrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowList,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentList)
        {
            InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange);//parametric definiton + cashflows schedule
            var swap = SwapFactory.Create(stream1);

            // Update FpML cashflows
            //
            UpdateCashflowsWithDetailedCashflows(stream1.cashflows, leg1DetailedCashflowsList);
            //  Update PE
            //
            if (null != leg1PrincipalExchangeCashflowList)
            {
                CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, leg1PrincipalExchangeCashflowList);
            }
            //  Add bullet payments...
            //
            if (null != leg1AdditionalPaymentList)
            {
                swap.additionalPayment = leg1AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment
                {
                    payerPartyReference    = PartyReferenceFactory.Create(leg1ParametersRange.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Receiver),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount),
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate)
                }).ToArray();
            }
            // Update FpML cashflows with DF,FV,PV, etc (LegParametersRange needed to access curve functionality)
            //
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream1, leg1ParametersRange, valuationRange);
            //  Update additional payments
            //
            var leg1DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg1ParametersRange.DiscountCurve);

            SwapGenerator.UpdatePaymentsAmounts(logger, cache, nameSpace, swap, leg1ParametersRange, leg1DiscountCurve, valuationRange.ValuationDate, paymentCalendar);
            //~  Update additional payments
            string baseParty = valuationRange.BaseParty;

            return(new Pair <ValuationResultRange, Swap>(CreateValuationRange(swap, baseParty), swap));
        }
Пример #6
0
        public string CreateValuation(
            ILogger logger, ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            List <StringObjectRangeItem> valuationSet,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            CapFloorLegParametersRange_Old legParametersRange,
            List <InputCashflowRangeItem> legDetailedCashflowsListArray,
            List <InputPrincipalExchangeCashflowRangeItem> legPrincipleExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> legAdditionalPaymentListArray,
            List <PartyIdRangeItem> partyIdList,                     //optional
            List <OtherPartyPaymentRangeItem> otherPartyPaymentList, //optional
            List <FeePaymentRangeItem> feePaymentList                //optional
            )
        {
            Pair <ValuationResultRange, CapFloor> fpML = GetPriceAndGeneratedFpML(logger, cache, nameSpace, fixingCalendar, paymentCalendar, valuationRange, tradeRange,
                                                                                  legParametersRange, legDetailedCashflowsListArray, legPrincipleExchangeCashflowListArray,
                                                                                  legAdditionalPaymentListArray, feePaymentList);
            CapFloor capFloor = fpML.Second;
            string   valuationReportAndProductId = tradeRange.Id ?? Guid.NewGuid().ToString();

            capFloor.id = valuationReportAndProductId;
            AssetValuation assetValuation = InterestRateProduct.CreateAssetValuationFromValuationSet(valuationSet);
            //Valuation valuation = new Valuation();
            //  TODO: add Trade Id & Trade data into valuation. (Trade.Id & Trade.TradeHeader.TradeDate)
            //
            string baseParty    = valuationRange.BaseParty;
            var    uniqueCurves = new List <IRateCurve>();

            foreach (string curveName in new[] { legParametersRange.ForecastCurve, legParametersRange.DiscountCurve })
            {
                if (!String.IsNullOrEmpty(curveName))
                {
                    var curve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, curveName);
                    if (!uniqueCurves.Contains(curve))
                    {
                        uniqueCurves.Add(curve);
                    }
                }
            }
            Market          fpMLMarket      = InterestRateProduct.CreateFpMLMarketFromCurves(uniqueCurves);
            ValuationReport valuationReport = ValuationReportGenerator.Generate(valuationReportAndProductId, baseParty, valuationReportAndProductId, tradeRange.TradeDate, capFloor, fpMLMarket, assetValuation);

            cache.SaveObject(valuationReport, valuationReportAndProductId, null);
            InterestRateProduct.ReplacePartiesInValuationReport(valuationReport, partyIdList);
            InterestRateProduct.AddOtherPartyPayments(valuationReport, otherPartyPaymentList);
            return(valuationReportAndProductId);
        }
Пример #7
0
        public List <DetailedCashflowRangeItem> GetDetailedCashflowsWithNotionalSchedule(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            var tempList = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
            NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(tempList);
            Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
            NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
            InterestRateStream        interestRateStream   = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);

            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <DetailedCashflowRangeItem>();

            //int periodNumber = 1;
            foreach (PaymentCalculationPeriod paymentCalculationPeriod in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                var detailedCashflowRangeItem = new DetailedCashflowRangeItem();
                list.Add(detailedCashflowRangeItem);
                detailedCashflowRangeItem.PaymentDate = paymentCalculationPeriod.adjustedPaymentDate;
                detailedCashflowRangeItem.StartDate   = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.EndDate     = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                //detailedCashflowRangeItem.NumberOfDays = PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod);
                //detailedCashflowRangeItem.FutureValue = MoneyHelper.ToDouble(paymentCalculationPeriod.forecastPaymentAmount);
                //detailedCashflowRangeItem.PresentValue = MoneyHelper.ToDouble(paymentCalculationPeriod.presentValueAmount);
                //detailedCashflowRangeItem.DiscountFactor = (double)paymentCalculationPeriod.discountFactor;
                detailedCashflowRangeItem.NotionalAmount = (double)PaymentCalculationPeriodHelper.GetNotionalAmount(paymentCalculationPeriod);
                detailedCashflowRangeItem.CouponType     = GetCouponType(paymentCalculationPeriod);
                detailedCashflowRangeItem.Rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                //  If  floating rate - retrieve the spread.
                //
                if (legParametersRange.IsFloatingLegType())
                {
                    detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                }
            }

            return(list);
        }
        public void GetDetailedCapFloorCashflowsVanilla()
        {
            DateTime valuationDate    = DateTime.Today;
            var      irCapFloorPricer = new CapFloorPricer();
            var      curveId          = BuildAndCacheRateCurve(valuationDate);

            foreach (CapFloorType legType in new[] { CapFloorType.Cap, CapFloorType.Floor })
            {
                Debug.Print("LegType: {0}", legType);
                CapFloorLegParametersRange_Old capLeg = GetCapFloorInputParameters(valuationDate, valuationDate.AddMonths(6), valuationDate.AddYears(5),
                                                                                   legType, "Standard", curveId, curveId);

                ValuationRange valuationRange                 = CreateValuationRange(valuationDate);
                List <DateTimeDoubleRangeItem>   notional     = GetAmortNotional(capLeg, 3);
                List <DetailedCashflowRangeItem> cashflowList =
                    irCapFloorPricer.GetDetailedCashflowsWithNotionalSchedule(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null, capLeg, notional, valuationRange);
                object[,] arrayOfCashflows = ObjectToArrayOfPropertiesConverter.ConvertListToHorizontalArrayRange(cashflowList);
                Debug.WriteLine("Cashflows:");
                Debug.WriteLine(ParameterFormatter.FormatObject(arrayOfCashflows));
            }
        }
Пример #9
0
        internal static ValuationResultRange GetPriceOld(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old leg1ParametersRange,
            SwapLegParametersRange_Old leg2ParametersRange,
            ValuationRange valuationRange)
        {
            string baseParty = valuationRange.BaseParty;

            InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange); //pay leg
            InterestRateStream stream2 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg2ParametersRange); //receive leg
            var swap = SwapFactory.Create(stream1, stream2);

            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream1, leg1ParametersRange, valuationRange);
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream2, leg2ParametersRange, valuationRange);
            ValuationResultRange resultRange = CreateValuationRange(swap, baseParty);

            return(resultRange);
        }
Пример #10
0
        public List <PrincipalExchangeCashflowRangeItem> GetPrincipalExchanges(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            InterestRateStream interestRateStream;

            if (notionalValueItems.Count > 0)
            {
                var tempList = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
                NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(tempList);
                Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
                NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
                interestRateStream = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);
            }
            else
            {
                interestRateStream = GetCashflowsSchedule(fixingCalendar, paymentCalendar, legParametersRange);
            }
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <PrincipalExchangeCashflowRangeItem>();

            //int periodNumber = 0;
            foreach (PrincipalExchange principleExchange in interestRateStream.cashflows.principalExchange)
            {
                var principalExchangeCashflowRangeItem = new PrincipalExchangeCashflowRangeItem();
                list.Add(principalExchangeCashflowRangeItem);
                principalExchangeCashflowRangeItem.PaymentDate = principleExchange.adjustedPrincipalExchangeDate;
                principalExchangeCashflowRangeItem.Amount      = (double)principleExchange.principalExchangeAmount;
                //principalExchangeCashflowRangeItem.PresentValueAmount = MoneyHelper.ToDouble(principleExchange.presentValuePrincipalExchangeAmount);
                //principalExchangeCashflowRangeItem.DiscountFactor = (double)principleExchange.discountFactor;
            }
            return(list);
        }
Пример #11
0
        private static void UpdateCashflowsWithAmounts(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            InterestRateStream stream,
            SwapLegParametersRange legParametersRange,
            ValuationRange valuationRange)
        {
            //  Get a forecast curve
            //
            IRateCurve forecastCurve = null;

            if (!String.IsNullOrEmpty(legParametersRange.ForecastCurve))
            {
                forecastCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, legParametersRange.ForecastCurve);
            }
            //  Get a discount curve
            //
            var discountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, legParametersRange.DiscountCurve);

            FixedAndFloatingRateStreamCashflowGenerator.UpdateCashflowsAmounts(stream, forecastCurve, discountCurve, valuationRange.ValuationDate);
        }
Пример #12
0
        public static List <DetailedCashflowRangeItem> GetDetailedCashflowsTestOnly(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwapLegParametersRange_Old legParametersRange,
            ValuationRange valuationRange)
        {
            InterestRateStream interestRateStream = GetCashflowsSchedule(fixingCalendar, paymentCalendar, legParametersRange);

            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <DetailedCashflowRangeItem>();

            foreach (PaymentCalculationPeriod paymentCalculationPeriod in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                var detailedCashflowRangeItem = new DetailedCashflowRangeItem();
                list.Add(detailedCashflowRangeItem);
                detailedCashflowRangeItem.PaymentDate = paymentCalculationPeriod.adjustedPaymentDate;
                detailedCashflowRangeItem.StartDate   = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.EndDate     = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                //detailedCashflowRangeItem.NumberOfDays   = PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod);
                //detailedCashflowRangeItem.FutureValue    = MoneyHelper.ToDouble(paymentCalculationPeriod.forecastPaymentAmount);
                //detailedCashflowRangeItem.PresentValue = MoneyHelper.ToDouble(paymentCalculationPeriod.presentValueAmount);
                //detailedCashflowRangeItem.DiscountFactor = (double)paymentCalculationPeriod.discountFactor;
                detailedCashflowRangeItem.NotionalAmount = (double)PaymentCalculationPeriodHelper.GetNotionalAmount(paymentCalculationPeriod);
                detailedCashflowRangeItem.CouponType     = GetCouponType(paymentCalculationPeriod);
                detailedCashflowRangeItem.Rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                //  If  floating rate - retrieve a spread.
                //
                if (legParametersRange.IsFloatingLegType())
                {
                    detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                }
            }

            return(list);
        }
Пример #13
0
        public string CreateValuation(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            List <StringObjectRangeItem> valuationSet,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            SwapLegParametersRange_Old leg1ParametersRange,
            List <DetailedCashflowRangeItem> leg1DetailedCashflowsListArray,
            List <PrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentListArray,
            List <PartyIdRangeItem> partyIdList,//optional
            List <OtherPartyPaymentRangeItem> otherPartyPaymentList
            )
        {
            Swap   floater   = GetPriceAndGeneratedFpMLSwap(logger, cache, nameSpace, fixingCalendar, paymentCalendar, valuationRange, tradeRange, leg1ParametersRange, leg1DetailedCashflowsListArray, leg1PrincipalExchangeCashflowListArray, leg1AdditionalPaymentListArray).Second;
            string baseParty = valuationRange.BaseParty;
            string valuationReportAndProductId = tradeRange.Id ?? Guid.NewGuid().ToString();

            floater.id = valuationReportAndProductId;
            var    uniqueCurves = GetUniqueCurves(logger, cache, nameSpace, leg1ParametersRange);
            Market fpMLMarket   = InterestRateProduct.CreateFpMLMarketFromCurves(uniqueCurves);
            var    valuation    = new Valuations.Valuation();
            //  TODO: add Trade Id & Trade data into valuation. (Trade.Id & Trade.TradeHeader.TradeDate)
            //
            AssetValuation assetValuation = InterestRateProduct.CreateAssetValuationFromValuationSet(valuationSet);

            valuation.CreateSwapValuationReport(cache, nameSpace, valuationReportAndProductId, baseParty, tradeRange.Id, tradeRange.TradeDate, floater, fpMLMarket, assetValuation);
            ValuationReport valuationReport = valuation.Get(cache, nameSpace, valuationReportAndProductId);

            InterestRateProduct.ReplacePartiesInValuationReport(valuationReport, partyIdList);
            InterestRateProduct.AddOtherPartyPayments(valuationReport, otherPartyPaymentList);

            return(valuationReportAndProductId);
        }
Пример #14
0
 public InterestRateSwapParRateObjectiveFunction(SwapLegParametersRange payLegParametersRange, SwapLegParametersRange receiveLegParametersRange, ValuationRange valuationRange)
 {
     _payLegParametersRange     = payLegParametersRange;
     _receiveLegParametersRange = receiveLegParametersRange;
     _valuationRange            = valuationRange;
 }
Пример #15
0
        public List <DetailedCashflowRangeItem> GetDetailedCashflowsWithNotionalSchedule(
            ILogger logger, ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            CapFloorLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            //Check if the calendars are null. If not build them!
            var list1 = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
            NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(list1);
            Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
            NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
            InterestRateStream        interestRateStream   = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);
            //Add the principal exchanges to the cashflows.
            var principalExchangeList = list1.Select(cashflow => new PrincipalExchange
            {
                adjustedPrincipalExchangeDate = cashflow.First, adjustedPrincipalExchangeDateSpecified = true, principalExchangeAmount = cashflow.Second, principalExchangeAmountSpecified = true
            }).ToArray();

            interestRateStream.cashflows.principalExchange = principalExchangeList;
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <DetailedCashflowRangeItem>();

            foreach (PaymentCalculationPeriod paymentCalculationPeriod in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                var detailedCashflowRangeItem = new DetailedCashflowRangeItem();
                detailedCashflowRangeItem.PaymentDate    = paymentCalculationPeriod.adjustedPaymentDate;
                detailedCashflowRangeItem.StartDate      = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.EndDate        = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.NumberOfDays   = PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod);
                detailedCashflowRangeItem.FutureValue    = MoneyHelper.ToDouble(paymentCalculationPeriod.forecastPaymentAmount);
                detailedCashflowRangeItem.PresentValue   = MoneyHelper.ToDouble(paymentCalculationPeriod.presentValueAmount);
                detailedCashflowRangeItem.DiscountFactor = (double)paymentCalculationPeriod.discountFactor;
                detailedCashflowRangeItem.NotionalAmount = (double)PaymentCalculationPeriodHelper.GetNotionalAmount(paymentCalculationPeriod);
                detailedCashflowRangeItem.CouponType     = GetCouponType(paymentCalculationPeriod);
                detailedCashflowRangeItem.Rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                CalculationPeriod      calculationPeriod      = PaymentCalculationPeriodHelper.GetCalculationPeriods(paymentCalculationPeriod)[0];
                FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriodGetFloatingRateDefinition(calculationPeriod);
                switch (detailedCashflowRangeItem.CouponType.ToLower())
                {
                case "cap":
                {
                    Strike strike = floatingRateDefinition.capRate[0];
                    detailedCashflowRangeItem.StrikeRate = (double)strike.strikeRate;
                    break;
                }

                case "floor":
                {
                    Strike strike = floatingRateDefinition.floorRate[0];
                    detailedCashflowRangeItem.StrikeRate = (double)strike.strikeRate;
                    break;
                }

                default:
                {
                    string message =
                        String.Format("Specified coupon type : '{0}' is not supported. Please use one of these: 'cap, floor'", detailedCashflowRangeItem.CouponType.ToLower());
                    throw new NotSupportedException(message);
                }
                }
                //  If  floating rate - retrieve the spread.
                //
                detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                var fixingDate = new DateTime();
                var tempDate   = PaymentCalculationPeriodHelper.GetFirstFloatingFixingDate(paymentCalculationPeriod);
                if (tempDate != null)
                {
                    fixingDate = (DateTime)tempDate;
                }
                detailedCashflowRangeItem.FixingDate = fixingDate;
                detailedCashflowRangeItem.Currency   = "Not Specified";
                if (currency != null)
                {
                    detailedCashflowRangeItem.Currency = currency.Value;
                }
                list.Add(detailedCashflowRangeItem);
            }
            return(list);
        }
Пример #16
0
        public static Pair <ValuationResultRange, CapFloor> GetPriceAndGeneratedFpML(
            ILogger logger, ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            ValuationRange valuationRange, TradeRange tradeRange,
            CapFloorLegParametersRange_Old leg1ParametersRange,
            List <InputCashflowRangeItem> leg1DetailedCashflowsList,
            List <InputPrincipalExchangeCashflowRangeItem> legPrincipalExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentList,
            List <FeePaymentRangeItem> feePaymentList
            )
        {
            //Check if the calendars are null. If not build them!
            InterestRateStream stream1 = GetCashflowsSchedule(fixingCalendar, paymentCalendar, leg1ParametersRange);//parametric definiton + cashflows schedule

            // Update FpML cashflows
            //
            stream1.cashflows = UpdateCashflowsWithDetailedCashflows(leg1DetailedCashflowsList);
            if (null != legPrincipalExchangeCashflowListArray)
            {
                // create principal exchanges
                //
                InterestRateSwapPricer.CreatePrincipalExchangesFromListOfRanges(stream1.cashflows, legPrincipalExchangeCashflowListArray);
            }
            //  Add bullet payments...
            //
            var bulletPaymentList = new List <Payment>();

            if (null != leg1AdditionalPaymentList)
            {
                bulletPaymentList.AddRange(leg1AdditionalPaymentList.Select(bulletPaymentRangeItem => new Payment
                {
                    payerPartyReference    = PartyReferenceFactory.Create(leg1ParametersRange.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(leg1ParametersRange.Receiver),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(bulletPaymentRangeItem.Amount, bulletPaymentRangeItem.Currency),
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(bulletPaymentRangeItem.PaymentDate)
                }));
            }
            CapFloor capFloor = CapFloorFactory.Create(stream1);

            capFloor.additionalPayment = bulletPaymentList.ToArray();
            var feeList = new List <Payment>();

            if (null != feePaymentList)
            {
                feeList.AddRange(feePaymentList.Select(feePaymentRangeItem => new Payment
                {
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(feePaymentRangeItem.PaymentDate),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(feePaymentRangeItem.Amount, feePaymentRangeItem.Currency),
                    payerPartyReference    = PartyReferenceFactory.Create(feePaymentRangeItem.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Receiver)
                }));
            }
            capFloor.premium = feeList.ToArray();
            // Update FpML cashflows with DF,FV,PV, etc (LegParametersRange needed to access curve functionality)
            //
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, stream1, leg1ParametersRange, valuationRange);
            //  Update additional payments
            //
            var leg1DiscountCurve = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, leg1ParametersRange.DiscountCurve);

            CapFloorGenerator.UpdatePaymentsAmounts(paymentCalendar, capFloor, leg1ParametersRange, leg1DiscountCurve, valuationRange.ValuationDate);
            //~  Update additional payments
            string baseParty = valuationRange.BaseParty;

            return(new Pair <ValuationResultRange, CapFloor>(CreateValuationRange(capFloor, baseParty), capFloor));
        }
        public void CreateSwaptionValuation()
        {
            DateTime valuationDate = DateTime.Today;

            SwaptionPricer irSwaptionPricer = new InterestRateSwaptionPricer();

            string discountCurveID   = BuildAndCacheRateCurve(valuationDate); //RateCurveExcelInterfaceTests.ExcelInterface_CreateAUDCurveFromDepostSwapsFuturesFras_WithDates(valuationDate, valuationDate);
            string projectionCurveID = discountCurveID;

            SwapLegParametersRange_Old payFixed       = CreateFixedAUD_6MSwapLegParametersRange(_NAB, CounterParty, valuationDate, 0.065m, "ACT/365.FIXED", "AUSY", "FOLLOWING", "AUSY", "NONE", discountCurveID);
            SwapLegParametersRange_Old receiveFloat   = CreateFloatingAUD_6MSwapLegParametersRange(CounterParty, _NAB, valuationDate, 0, "ACT/365.FIXED", "AUSY", "FOLLOWING", "AUSY", "NONE", discountCurveID, projectionCurveID);
            ValuationRange             valuationRange = CreateValuationRangeForNAB(valuationDate);
            var payCFRangeItemList = InterestRateSwapPricer.GetDetailedCashflowsTestOnly(Engine.Logger, Engine.Cache, Engine.NameSpace, payFixed, valuationRange);

            payCFRangeItemList[0].CouponType = "fixed"; // that should test case insensitive nature of coupons
            payCFRangeItemList[1].CouponType = "Fixed"; //
            var receiveCFRangeItemList = InterestRateSwapPricer.GetDetailedCashflowsTestOnly(Engine.Logger, Engine.Cache, Engine.NameSpace, receiveFloat, valuationRange);

            receiveCFRangeItemList[0].CouponType = "float"; // that should test case insensitive nature of coupons
            receiveCFRangeItemList[1].CouponType = "Float"; //
            var tradeRange = new TradeRange {
                Id = "TradeId_12345", TradeDate = valuationDate
            };
            var leg1PrincipalExchangeCashflowList = new List <InputPrincipalExchangeCashflowRangeItem>();
            var leg2PrincipalExchangeCashflowList = new List <InputPrincipalExchangeCashflowRangeItem>();
            var leg1BulletPaymentList             = new List <AdditionalPaymentRangeItem>();
            var leg2BulletPaymentList             = new List <AdditionalPaymentRangeItem>();
            var swaptionParametersRange           = new SwaptionParametersRange
            {
                Premium                = 456789.12m,
                PremiumCurrency        = "AUD",
                PremiumPayer           = CounterParty,
                PremiumReceiver        = _NAB,
                ExpirationDate         = valuationDate.AddDays(10),
                ExpirationDateCalendar = "AUSY-GBLO",
                ExpirationDateBusinessDayAdjustments = "FOLLOWING",
                PaymentDate         = valuationDate.AddDays(20),
                PaymentDateCalendar = "USNY-GBLO",
                PaymentDateBusinessDayAdjustments = "MODFOLLOWING",
                EarliestExerciseTime = new TimeSpan(10, 0, 0).TotalDays,
                ExpirationTime       = new TimeSpan(11, 0, 0).TotalDays,
                AutomaticExcercise   = false
            };
            List <PartyIdRangeItem>           partyList = GetPartyList("NAB", "book", "MCHammer", "counterparty");
            List <OtherPartyPaymentRangeItem> otherPartyPaymentRangeItems = GetOtherPartyPaymentList("counterparty", "cost center");
            List <FeePaymentRangeItem>        feePaymentRangeItems        = GetFeeList("counterparty", "book");
            //  Get price and swap representation using non-vanilla PRICE function.
            //
            string valuatonId = irSwaptionPricer.CreateValuation(Engine.Logger, Engine.Cache, Engine.NameSpace, null, null,
                                                                 swaptionParametersRange,
                                                                 CreateValuationSetList2(12345.67, -0.321), valuationRange, tradeRange,
                                                                 payFixed, receiveFloat,
                                                                 payCFRangeItemList, receiveCFRangeItemList,
                                                                 leg1PrincipalExchangeCashflowList, leg2PrincipalExchangeCashflowList,
                                                                 leg1BulletPaymentList, leg2BulletPaymentList,
                                                                 partyList, otherPartyPaymentRangeItems,
                                                                 feePaymentRangeItems);
            var valuationReport = Engine.Cache.LoadObject <ValuationReport>(Engine.NameSpace + "." + valuatonId);

            Debug.Print(XmlSerializerHelper.SerializeToString(valuationReport));
        }
Пример #18
0
        public string CreateValuation(
            ILogger logger,
            ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            SwaptionParametersRange swaptionParametersRange,
            List <StringObjectRangeItem> valuationSet,
            ValuationRange valuationRange,
            TradeRange tradeRange,
            SwapLegParametersRange leg1ParametersRange,
            SwapLegParametersRange leg2ParametersRange,
            List <InputCashflowRangeItem> leg1DetailedCashflowsListArray,
            List <InputCashflowRangeItem> leg2DetailedCashflowsListArray,
            List <InputPrincipalExchangeCashflowRangeItem> leg1PrincipalExchangeCashflowListArray,
            List <InputPrincipalExchangeCashflowRangeItem> leg2PrincipalExchangeCashflowListArray,
            List <AdditionalPaymentRangeItem> leg1AdditionalPaymentListArray,
            List <AdditionalPaymentRangeItem> leg2AdditionalPaymentListArray,
            List <PartyIdRangeItem> partyIdList,                     //optional
            List <OtherPartyPaymentRangeItem> otherPartyPaymentList, //opt
            List <FeePaymentRangeItem> feePaymentList                //opt
            )
        {
            var swap = GetPriceAndGeneratedFpMLSwap(logger, cache, nameSpace,
                                                    fixingCalendar, paymentCalendar, valuationRange,
                                                    tradeRange, leg1ParametersRange, leg2ParametersRange,
                                                    leg1DetailedCashflowsListArray, leg2DetailedCashflowsListArray,
                                                    leg1PrincipalExchangeCashflowListArray, leg2PrincipalExchangeCashflowListArray,
                                                    leg1AdditionalPaymentListArray, leg2AdditionalPaymentListArray).Second;
            string            baseParty    = valuationRange.BaseParty;
            List <IRateCurve> uniqueCurves = GetUniqueCurves(logger, cache, nameSpace, leg1ParametersRange, leg2ParametersRange);
            Market            fpMLMarket   = InterestRateProduct.CreateFpMLMarketFromCurves(uniqueCurves);
            //  TODO: add Trade Id & Trade data into valuation. (Trade.Id & Trade.TradeHeader.TradeDate)
            //
            //  create ValuationReport and add it to in-memory collection.
            //  Add methods!
            AssetValuation           assetValuation = InterestRateProduct.CreateAssetValuationFromValuationSet(valuationSet);
            NonNegativeMoney         premium        = MoneyHelper.GetNonNegativeAmount(swaptionParametersRange.Premium, swaptionParametersRange.PremiumCurrency);
            AdjustableDate           expirationDate = DateTypesHelper.ToAdjustableDate(swaptionParametersRange.ExpirationDate, swaptionParametersRange.ExpirationDateBusinessDayAdjustments, swaptionParametersRange.ExpirationDateCalendar);
            AdjustableOrAdjustedDate paymentDate    = DateTypesHelper.ToAdjustableOrAdjustedDate(swaptionParametersRange.PaymentDate, swaptionParametersRange.PaymentDateBusinessDayAdjustments, swaptionParametersRange.PaymentDateCalendar);
            TimeSpan earliestExerciseTimeAsTimeSpan = TimeSpan.FromDays(swaptionParametersRange.EarliestExerciseTime);
            DateTime earliestExerciseTime           = DateTime.MinValue.Add(earliestExerciseTimeAsTimeSpan);
            TimeSpan expirationTimeAsTimeSpan       = TimeSpan.FromDays(swaptionParametersRange.ExpirationTime);
            DateTime expirationTime = DateTime.MinValue.Add(expirationTimeAsTimeSpan);
            var      swaption       = SwaptionFactory.Create(swap, premium, swaptionParametersRange.PremiumPayer, swaptionParametersRange.PremiumReceiver,
                                                             paymentDate, expirationDate,
                                                             earliestExerciseTime, expirationTime, swaptionParametersRange.AutomaticExcercise);
            // overrides the premium created by SwaptionFactort.Create
            //
            var feeList = new List <Payment>();

            if (null != feePaymentList)
            {
                feeList.AddRange(feePaymentList.Select(feePaymentRangeItem => new Payment
                {
                    paymentDate            = DateTypesHelper.ToAdjustableOrAdjustedDate(feePaymentRangeItem.PaymentDate),
                    paymentAmount          = MoneyHelper.GetNonNegativeAmount(feePaymentRangeItem.Amount),
                    payerPartyReference    = PartyReferenceFactory.Create(feePaymentRangeItem.Payer),
                    receiverPartyReference = PartyReferenceFactory.Create(feePaymentRangeItem.Receiver)
                }));
            }
            swaption.premium = feeList.ToArray();
            string valuationReportAndProductId = tradeRange.Id ?? Guid.NewGuid().ToString();

            swaption.id = valuationReportAndProductId;
            ValuationReport valuationReport = ValuationReportGenerator.Generate(valuationReportAndProductId, baseParty, valuationReportAndProductId, tradeRange.TradeDate, swaption, fpMLMarket, assetValuation);

            cache.SaveObject(valuationReport, valuationReportAndProductId, null);
            InterestRateProduct.ReplacePartiesInValuationReport(valuationReport, partyIdList);
            InterestRateProduct.AddOtherPartyPayments(valuationReport, otherPartyPaymentList);
            return(valuationReportAndProductId);
        }