예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VanillaEuropeanFxOptionPricer"/> class.  All the cashflows must be signed.
        /// </summary>
        /// <param name="paymentCalendar">The payment calendar</param>
        /// <param name="fxOptionLeg">The fxLeg.</param>
        /// <param name="baseParty">The the base party.</param>
        /// <param name="logger">The logger</param>
        /// <param name="cache">The cache</param>
        /// <param name="nameSpace">The namespace</param>
        /// <param name="fixingCalendar">The fixing calendar</param>
        public VanillaEuropeanFxOptionPricer(ILogger logger, ICoreCache cache,
                                             String nameSpace, IBusinessCalendar fixingCalendar,
                                             IBusinessCalendar paymentCalendar, FxOption fxOptionLeg, string baseParty)
        {
            OrderedPartyNames = new List <string>();
            Multiplier        = 1.0m;
            Id                   = fxOptionLeg.id;
            AnalyticsModel       = new FxOptionLegAnalytic();
            ProductType          = ProductTypeSimpleEnum.FxOption;
            HybridValuation      = true;
            BuyerPartyReference  = fxOptionLeg.buyerPartyReference.href;
            SellerPartyReference = fxOptionLeg.sellerPartyReference.href;
            BasePartyBuyer       = baseParty == BuyerPartyReference;
            FxOptionType         = FxOptionType.Put;
            ProductType          = ProductTypeSimpleEnum.FxOption;
            if (fxOptionLeg.spotRateSpecified)
            {
                SpotRate = fxOptionLeg.spotRate;
            }
            if (CallCurrency == OptionOnCurrency)
            {
                FxOptionType = FxOptionType.Call;
            }
            FpMLProductType = ProductTypeHelper.GetProductType(fxOptionLeg.Items, fxOptionLeg.ItemsElementName);
            //Temporary values used to build the fx and option trades.
            PutCurrencyAmount  = fxOptionLeg.putCurrencyAmount.amount;
            PutCurrency        = fxOptionLeg.callCurrencyAmount.currency.Value;
            CallCurrencyAmount = fxOptionLeg.callCurrencyAmount.amount;
            CallCurrency       = fxOptionLeg.putCurrencyAmount.currency.Value;
            FxStrike           = fxOptionLeg.strike.rate;
            StrikeQuoteBasis   = fxOptionLeg.strike.strikeQuoteBasis;
            SoldAs             = fxOptionLeg.soldAs;
            if (fxOptionLeg.tenorPeriod != null)
            {
                QuotedTenor = fxOptionLeg.tenorPeriod.ToString();
            }
            var vanillaOption = fxOptionLeg.Item as FxEuropeanExercise;

            if (vanillaOption != null)
            {
                ExpiryDate = vanillaOption.expiryDate;
                ExpiryTimeBusinessCenter = vanillaOption.expiryTime.businessCenter.Value;
                ExpiryTime = vanillaOption.expiryTime.hourMinuteTime; //TODO Not Implemented yet!
                CutName    = vanillaOption.cutName;
                ValueDate  = vanillaOption.valueDate;
            }
            var type = HasBeenExercised ? ProductTypeSimpleEnum.FxSpot : ProductTypeSimpleEnum.FxForward;
            //Create the fxleg.
            //TODO Currently this does not handle non-deliverable forwards or a third settlement currency.
            var fxLeg = FxOption.CreateFxSingleLeg(HasBeenExercised, BuyerPartyReference, SellerPartyReference, PutCurrencyAmount, PutCurrency, CallCurrencyAmount,
                                                   CallCurrency, StrikeQuoteBasis, ValueDate, FxStrike);

            FxLeg = new FxSingleLegPricer(fxLeg, baseParty, type);
            VolatilitySurfaceName = fxOptionLeg.GetRequiredVolatilitySurfaces()[0];
            //FxOptionType;
            //Get the currency.
            PaymentCurrencies = new List <string>();
            PaymentCurrencies.AddRange(FxLeg.PaymentCurrencies);
            //Add the premia
            Premia = new List <PriceableFxOptionPremium>();
            if (fxOptionLeg.premium != null)
            {
                foreach (var premium in fxOptionLeg.premium)
                {
                    var priceablePayment = PriceableInstrumentsFactory.CreatePriceableFxOptionPremium(cache, nameSpace, null, baseParty, premium, fixingCalendar, paymentCalendar);
                    Premia.Add(priceablePayment);
                    PaymentCurrencies.AddRange(priceablePayment.PaymentCurrencies);
                }
            }
            PaymentCurrencies = PaymentCurrencies.Distinct().ToList();
            if (fxOptionLeg.cashSettlement != null)
            {
                IsCashSettled          = true;
                CashSettlementCurrency = fxOptionLeg.cashSettlement.settlementCurrency;
                //Only a single fixing date is currency implemented.
                if (fxOptionLeg.cashSettlement.fixing != null && fxOptionLeg.cashSettlement.fixing[0].fixingDateSpecified)
                {
                    FixingDate = fxOptionLeg.cashSettlement.fixing[0].fixingDate;
                    FixingQuotedCurrencyPair = fxOptionLeg.cashSettlement.fixing[0].quotedCurrencyPair;
                }
            }
            if (vanillaOption != null)
            {
                RiskMaturityDate = vanillaOption.valueDate;
            }
            logger.LogInfo("FxOption trade created :");
        }
예제 #2
0
        protected SwapPricer(ILogger logger, ICoreCache cache, String nameSpace,
                             List <Pair <IBusinessCalendar, IBusinessCalendar> > legCalendars,
                             Swap swapFpML, string basePartyReference,
                             ProductTypeSimpleEnum productType, Boolean forecastRateInterpolation)
        {
            Multiplier = 1.0m;
            if (swapFpML == null)
            {
                return;
            }
            BusinessCentersResolver.ResolveBusinessCenters(swapFpML);
            ForecastRateInterpolation = forecastRateInterpolation;
            //Get the effective date
            AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(swapFpML.swapStream[0].calculationPeriodDates);

            EffectiveDate = adjustableEffectiveDate.unadjustedDate.Value;
            //We make the assumption that the termination date is the same for all legs.
            AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(swapFpML.swapStream[0].calculationPeriodDates);
            var            paymentCalendar           = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace);

            TerminationDate  = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate);
            RiskMaturityDate = TerminationDate;
            //EffectiveDate is not set;
            ProductType       = productType;
            PaymentCurrencies = new List <string>();
            //Resolve the payer
            var legs = swapFpML.swapStream.Length;

            if (legs == 0)
            {
                return;
            }
            var flag  = false;
            var index = 0;

            if (legCalendars != null && legCalendars.Count == legs)
            {
                flag = true;
            }
            foreach (var swapStream in swapFpML.swapStream)
            {
                bool payerIsBase = basePartyReference == swapStream.payerPartyReference.href;//TODO add in the calendar functionality.
                //Set the id of the first stream.
                PriceableInterestRateStream leg = flag ? new PriceableInterestRateStream(logger, cache, nameSpace, payerIsBase, swapStream, ForecastRateInterpolation, legCalendars[index].First, legCalendars[index].Second)
                    : new PriceableInterestRateStream(logger, cache, nameSpace, payerIsBase, swapStream, ForecastRateInterpolation, null, null);
                Legs.Add(leg);
                //Add the currencies for the trade pricer.
                if (!PaymentCurrencies.Contains(leg.Currency.Value))
                {
                    PaymentCurrencies.Add(leg.Currency.Value);
                }
                index++;
            }
            if (swapFpML.additionalPayment != null)
            {
                AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, swapFpML.additionalPayment, null);
                foreach (var payment in swapFpML.additionalPayment)
                {
                    if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value))
                    {
                        PaymentCurrencies.Add(payment.paymentAmount.currency.Value);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="paymentCalendar"> </param>
        /// <param name="capFloorFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="forecastRateInterpolation"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"> </param>
        public CapFloorPricer(ILogger logger, ICoreCache cache, String nameSpace,
                              IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                              CapFloor capFloorFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            if (capFloorFpML == null)
            {
                return;
            }
            //AnalyticsModel = new SimpleIRSwapInstrumentAnalytic();
            BusinessCentersResolver.ResolveBusinessCenters(capFloorFpML);
            ForecastRateInterpolation = forecastRateInterpolation;
            //We make the assumption that the termination date is the same for all legs..
            AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(capFloorFpML.capFloorStream.calculationPeriodDates);

            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableTerminationDate.dateAdjustments.businessCenters, nameSpace);
            }
            RiskMaturityDate  = AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate);
            ProductType       = ProductTypeSimpleEnum.CapFloor;
            PaymentCurrencies = new List <string>();
            //Resolve the payer
            if (capFloorFpML.capFloorStream == null)
            {
                return;
            }
            var calculation             = capFloorFpML.capFloorStream.calculationPeriodAmount.Item as Calculation;
            var floatingRatecalculation = calculation?.Items[0] as FloatingRateCalculation;

            if (floatingRatecalculation == null)
            {
                return;
            }
            if (floatingRatecalculation.capRateSchedule != null)
            {
                var schedule            = floatingRatecalculation.capRateSchedule[0];
                var buyerPartyReference = schedule.buyer.Value;
                if (buyerPartyReference == PayerReceiverEnum.Receiver)
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.receiverPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href;
                }
                else
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.payerPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href;
                }
            }
            if (floatingRatecalculation.capRateSchedule == null && floatingRatecalculation.floorRateSchedule != null)
            {
                var schedule            = floatingRatecalculation.floorRateSchedule[0];
                var buyerPartyReference = schedule.buyer.Value;
                if (buyerPartyReference == PayerReceiverEnum.Receiver)
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.receiverPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.payerPartyReference.href;
                }
                else
                {
                    BuyerPartyReference  = capFloorFpML.capFloorStream.payerPartyReference.href;
                    SellerPartyReference = capFloorFpML.capFloorStream.receiverPartyReference.href;
                }
            }
            BasePartyBuyer = basePartyReference == BuyerPartyReference;//TODO add in the calendar functionality.
            //Set the id of the first stream. THe generator requires the flag: BasePartyPayer.
            var capFloorLeg = new PriceableCapFloorStream(logger, cache, nameSpace, !BasePartyBuyer, capFloorFpML.capFloorStream, ForecastRateInterpolation, fixingCalendar, paymentCalendar);

            Legs.Add(capFloorLeg);
            //Add the currencies for the trade pricer.
            if (!PaymentCurrencies.Contains(capFloorLeg.Currency.Value))
            {
                PaymentCurrencies.Add(capFloorLeg.Currency.Value);
            }
            if (capFloorFpML.additionalPayment != null)
            {
                AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, capFloorFpML.additionalPayment, null);
                foreach (var payment in capFloorFpML.additionalPayment)
                {
                    if (!PaymentCurrencies.Contains(payment.paymentAmount.currency.Value))
                    {
                        PaymentCurrencies.Add(payment.paymentAmount.currency.Value);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="tradeDate"></param>
        /// <param name="effectiveDate"></param>
        /// <param name="referenceEquity"></param>
        /// <param name="settlementCalendar"></param>
        /// <param name="equityFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="forecastRateInterpolation"></param>
        public EquityTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate, DateTime effectiveDate,
                                       String referenceEquity, IBusinessCalendar settlementCalendar, EquityTransaction equityFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            logger.LogInfo("EquityType set. Commence to build a equity transaction.");
            if (equityFpML == null)
            {
                return;
            }
            SettlementDate    = effectiveDate;
            TradeDate         = tradeDate;
            Multiplier        = 1.0m;
            BuyerReference    = equityFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                equityFpML.unitPrice.currency.Value
            };
            SellerReference           = equityFpML.sellerPartyReference.href;
            BasePartyBuyer            = basePartyReference == equityFpML.buyerPartyReference.href;
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            ReferenceEquity           = referenceEquity;
            NumberOfShares            = Convert.ToInt16(equityFpML.numberOfUnits);
            PurchasePrice             = MoneyHelper.GetAmount(equityFpML.unitPrice.amount, equityFpML.unitPrice.currency.Value);
            PaymentCurrencies         = new List <string> {
                equityFpML.unitPrice.currency.Value
            };
            var exchangeMIC     = equityFpML.equity.exchangeId;
            var exchangeMICData = InstrumentDataHelper.CreateEquityExchangeKey(nameSpace, exchangeMIC.Value);
            var exchangeData    = cache.LoadItem <ExchangeConfigData>(exchangeMICData);

            if (exchangeData?.Data is ExchangeConfigData exchange)
            {
                var equityTypeInfo = new EquityNodeStruct {
                    SettlementDate = exchange.SettlementDate
                };
                if (equityFpML.equity != null)
                {
                    if (SettlementCalendar == null)
                    {
                        SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache,
                                                                                     equityTypeInfo.SettlementDate
                                                                                     .businessCenters,
                                                                                     nameSpace);
                    }
                    if (PaymentCalendar == null)
                    {
                        PaymentCalendar = SettlementCalendar;
                    }
                    var equity = XmlSerializerHelper.Clone(equityFpML.equity);
                    EquityTypeInfo        = XmlSerializerHelper.Clone(equityTypeInfo);
                    EquityTypeInfo.Equity = equity;
                    RiskMaturityDate      = SettlementDate;
                    MaturityDate          = SettlementDate;
                    if (!PaymentCurrencies.Contains(equityFpML.equity.currency.Value))
                    {
                        PaymentCurrencies.Add(equityFpML.equity.currency.Value);
                    }
                    logger.LogInfo("Equity transaction has been successfully created.");
                }
            }
            else
            {
                logger.LogInfo("Equity type data not available.");
            }
            //Add payments like the settlement price
            if (PurchasePrice == null || !PurchasePrice.amountSpecified)
            {
                return;
            }
            var amount            = PurchasePrice.amount * NumberOfShares;
            var settlementPayment = PaymentHelper.Create("EquitySettlementAmount", BuyerReference, SellerReference, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, PaymentCalendar);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }
        public FutureTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate, ExchangeContractTypeEnum futuresType,
                                       IBusinessCalendar settlementCalendar, FutureTransaction futureFpML, string basePartyReference, Boolean forecastRateInterpolation)
        {
            logger.LogInfo("FuturesType set. Commence to build a future transaction.");
            if (futureFpML == null)
            {
                return;
            }
            Multiplier        = 1.0m;
            BuyerReference    = futureFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                futureFpML.unitPrice.currency.Value
            };
            SellerReference = futureFpML.sellerPartyReference.href;
            BasePartyBuyer  = basePartyReference == futureFpML.buyerPartyReference.href;
            if (!BasePartyBuyer)
            {
                Multiplier = -1.0m;
            }
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            FuturesType       = futuresType;
            ReferenceContract = futureFpML.future.id;
            var futuresCode = ReferenceContract.Split('-')[2];

            NumberOfContracts = Convert.ToInt16(futureFpML.numberOfUnits);
            PurchasePrice     = MoneyHelper.GetAmount(futureFpML.unitPrice.amount, futureFpML.unitPrice.currency.Value);
            var exchangeMIC = futureFpML.future.exchangeId;

            FuturesCurveName  = CurveNameHelpers.GetExchangeTradedCurveName(futureFpML.unitPrice.currency.Value, exchangeMIC.Value, futuresCode);
            DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(futureFpML.unitPrice.currency, true);
            FuturesTypeInfo   = new FutureNodeStruct();
            var exchangeMICData = InstrumentDataHelper.CreateEquityExchangeKey(nameSpace, exchangeMIC.Value);
            var exchangeData    = cache.LoadItem <ExchangeConfigData>(exchangeMICData);

            if (exchangeData?.Data is ExchangeConfigData data)
            {
                Exchange = data;
                FuturesTypeInfo.SpotDate = Exchange.SettlementDate;
            }
            if (futureFpML.future != null)
            {
                if (SettlementCalendar == null)
                {
                    SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache,
                                                                                 FuturesTypeInfo.SpotDate
                                                                                 .businessCenters,
                                                                                 nameSpace);
                }
                var future = XmlSerializerHelper.Clone(futureFpML.future);
                FuturesTypeInfo.Future = future;
                if (FuturesTypeInfo.SpotDate != null)
                {
                    SettlementDate = GetSettlementDate(tradeDate, SettlementCalendar,
                                                       FuturesTypeInfo.SpotDate);
                }
                //Instantiate the priceable future.
                NamedValueSet namedValueSet = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, FuturesTypeInfo.Future.id, tradeDate);
                var           asset         = AssetHelper.Parse(FuturesTypeInfo.Future.id, 0.0m, 0.0m);
                UnderlyingFuture = PriceableAssetFactory.Create(logger, cache, nameSpace, asset.Second, namedValueSet, null, null) as IPriceableFuturesAssetController;
                if (UnderlyingFuture != null)
                {
                    RiskMaturityDate = UnderlyingFuture.GetRiskMaturityDate();
                    MaturityDate     = RiskMaturityDate;
                    LastTradeDate    = UnderlyingFuture.LastTradeDate;
                }
                if (!PaymentCurrencies.Contains(futureFpML.future.currency.Value))
                {
                    PaymentCurrencies.Add(futureFpML.future.currency.Value);
                }
                logger.LogInfo("Futures transaction has been successfully created.");
            }
            else
            {
                logger.LogInfo("Futures type data not available.");
            }
            //Add payments like the settlement price
            if (!PurchasePrice.amountSpecified)
            {
                return;
            }
            var amount            = PurchasePrice.amount * NumberOfContracts / 100;
            var settlementPayment = PaymentHelper.Create("FuturesSettlementAmount", BuyerReference, SellerReference, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, SettlementCalendar);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableInterestRateStream"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace.</param>
        /// <param name="swapId">The swap Id.</param>
        /// <param name="payerPartyReference">The payer party reference.</param>
        /// <param name="receiverPartyReference">The receiver party reference.</param>
        /// <param name="payerIsBase">The flag for whether the payer reference is the base party.</param>
        /// <param name="calculationPeriodDates">The calculation period date information.</param>
        /// <param name="paymentDates">The payment dates of the swap leg.</param>
        /// <param name="resetDates">The reset dates of the swap leg.</param>
        /// <param name="principalExchanges">The principal Exchange type.</param>
        /// <param name="calculationPeriodAmount">The calculation period amount data.</param>
        /// <param name="stubCalculationPeriodAmount">The stub calculation information.</param>
        /// <param name="cashflows">The FpML cashflows for that stream.</param>
        /// <param name="settlementProvision">The settlement provision data.</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>
        public PriceableInterestRateStream
        (
            ILogger logger
            , ICoreCache cache
            , String nameSpace
            , string swapId
            , string payerPartyReference
            , string receiverPartyReference
            , bool payerIsBase
            , CalculationPeriodDates calculationPeriodDates
            , PaymentDates paymentDates
            , ResetDates resetDates
            , PrincipalExchanges principalExchanges
            , CalculationPeriodAmount calculationPeriodAmount
            , StubCalculationPeriodAmount stubCalculationPeriodAmount
            , Cashflows cashflows
            , SettlementProvision settlementProvision
            , bool forecastRateInterpolation
            , IBusinessCalendar fixingCalendar
            , IBusinessCalendar paymentCalendar)
        {
            Multiplier              = 1.0m;
            Payer                   = payerPartyReference;
            Receiver                = receiverPartyReference;
            PayerIsBaseParty        = payerIsBase;
            CalculationPeriodDates  = calculationPeriodDates;
            PaymentDates            = paymentDates;
            PaymentCurrencies       = new List <string>();
            ResetDates              = resetDates;
            PrincipalExchanges      = principalExchanges;
            CalculationPeriodAmount = calculationPeriodAmount;
            AnalyticsModel          = new StructuredStreamAnalytic();
            Calculation             = (Calculation)CalculationPeriodAmount.Item;
            if (Calculation.Items?[0] is Schedule strikeSchedule)
            {
                Strike = strikeSchedule.initialValue;//Only picks up the first fixed rate for the swaption calculation.
            }
            StubCalculationPeriodAmount = stubCalculationPeriodAmount;
            Cashflows        = cashflows;
            CouponStreamType = CouponTypeFromCalculation(Calculation);
            Id = BuildId(swapId, CouponStreamType);
            ForecastRateInterpolation = forecastRateInterpolation;
            var isThereDiscounting = XsdClassesFieldResolver.CalculationHasDiscounting(Calculation);

            if (isThereDiscounting)
            {
                IsDiscounted = true; //TODO need to include rate logic for the correct solved answers. What about reset cashflows??
            }
            //Get the currency.
            var currency = XsdClassesFieldResolver.CalculationGetNotionalSchedule(Calculation);

            Currency = currency.notionalStepSchedule.currency;
            if (!PaymentCurrencies.Contains(Currency.Value))
            {
                PaymentCurrencies.Add(Currency.Value);
            }
            //The calendars
            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, PaymentDates.paymentDatesAdjustments.businessCenters, nameSpace);
            }
            SettlementProvision = settlementProvision;
            //Set the default discount curve name.
            DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true);
            //Set the forecast curve name.//TODO extend this to the other types.
            if (CouponStreamType != 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.
            if (GetCashflowPaymentCalculationPeriods() != null)
            {
                Coupons = PriceableInstrumentsFactory.CreatePriceableCoupons(PayerIsBaseParty,
                                                                             GetCashflowPaymentCalculationPeriods(),
                                                                             Calculation, ForecastRateInterpolation, fixingCalendar, paymentCalendar);//TODO add the stubcalculation.
                UpdateCouponIds();
            }
            if (GetCashflowPrincipalExchanges() != null)
            {
                var exchanges = GetCashflowPrincipalExchanges();
                Exchanges = PriceableInstrumentsFactory.CreatePriceablePrincipalExchanges(PayerIsBaseParty, exchanges, Currency.Value, paymentCalendar);
                UpdateExchangeIds();
            }
            RiskMaturityDate = LastDate();
            logger.LogInfo("Stream built");
        }