//-------------------------------------------------------------------------
        public FxSwapTrade toTrade(TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double nearFxRate, double farLegForwardPoints)
        {
            Optional <LocalDate> tradeDate = tradeInfo.TradeDate;

            if (tradeDate.Present)
            {
                ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate");
            }
            double amount1 = BuySell.BUY.normalize(notional);

            return(FxSwapTrade.builder().info(tradeInfo).product(FxSwap.ofForwardPoints(CurrencyAmount.of(currencyPair.Base, amount1), FxRate.of(currencyPair, nearFxRate), farLegForwardPoints, startDate, endDate, BusinessDayAdjustment)).build());
        }
Exemple #2
0
        /// <summary>
        /// Builds this instance and returns the underlying instrument associated with the controller
        /// </summary>
        /// <returns></returns>
        public FxSwap Build()
        {
            var fxSwap = new FxSwap();
            var leg1   = Legs[0].Build();
            var leg2   = Legs[1].Build();

            fxSwap.nearLeg          = leg1;
            fxSwap.farLeg           = leg2;
            fxSwap.id               = Id;
            fxSwap.Items            = new object[] { ProductTypeHelper.Create(ProductTypeSimpleEnum.FxSwap.ToString()) };
            fxSwap.ItemsElementName = new[] { ItemsChoiceType2.productType };
            return(fxSwap);
        }
Exemple #3
0
        //-------------------------------------------------------------------------
        public virtual void test_createTrade()
        {
            FxSwapTemplate        @base     = FxSwapTemplate.of(NEAR_PERIOD, FAR_PERIOD, CONVENTION);
            LocalDate             tradeDate = LocalDate.of(2015, 10, 29);
            FxSwapTrade           test      = @base.createTrade(tradeDate, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS, REF_DATA);
            LocalDate             spotDate  = PLUS_TWO_DAYS.adjust(tradeDate, REF_DATA);
            LocalDate             nearDate  = spotDate.plus(NEAR_PERIOD);
            LocalDate             farDate   = spotDate.plus(FAR_PERIOD);
            BusinessDayAdjustment bda       = CONVENTION.BusinessDayAdjustment;
            FxSwap expected = FxSwap.ofForwardPoints(CurrencyAmount.of(EUR, NOTIONAL_EUR), FxRate.of(EUR, USD, FX_RATE_NEAR), FX_RATE_PTS, nearDate, farDate, bda);

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
        //-------------------------------------------------------------------------
        public virtual void test_toTrade_periods()
        {
            ImmutableFxSwapConvention @base = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW);
            Period      startPeriod         = Period.ofMonths(3);
            Period      endPeriod           = Period.ofMonths(6);
            LocalDate   tradeDate           = LocalDate.of(2015, 5, 5);
            LocalDate   spotDate            = PLUS_TWO_DAYS.adjust(tradeDate, REF_DATA);
            LocalDate   nearDate            = spotDate.plus(startPeriod);
            LocalDate   farDate             = spotDate.plus(endPeriod);
            FxSwapTrade test     = @base.createTrade(tradeDate, startPeriod, endPeriod, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS, REF_DATA);
            FxSwap      expected = FxSwap.ofForwardPoints(CurrencyAmount.of(EUR, NOTIONAL_EUR), FxRate.of(EUR, USD, FX_RATE_NEAR), FX_RATE_PTS, nearDate, farDate, BDA_FOLLOW);

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
        public virtual void test_toTrade_dates()
        {
            ImmutableFxSwapConvention @base = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW);
            LocalDate   tradeDate           = LocalDate.of(2015, 5, 5);
            LocalDate   nearDate            = LocalDate.of(2015, 7, 5);
            LocalDate   nearDateAdj         = LocalDate.of(2015, 7, 6); // Adjusted: 5 is Sunday
            LocalDate   farDate             = LocalDate.of(2015, 9, 5);
            LocalDate   farDateAdj          = LocalDate.of(2015, 9, 7); // Adjusted: 5 is Saturday
            FxSwapTrade test     = @base.toTrade(tradeDate, nearDate, farDate, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS);
            FxSwap      expected = FxSwap.ofForwardPoints(CurrencyAmount.of(EUR, NOTIONAL_EUR), FxRate.of(EUR, USD, FX_RATE_NEAR), FX_RATE_PTS, nearDate, farDate, BDA_FOLLOW);

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
            ResolvedFxSwap resolvedExpected = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(EUR, NOTIONAL_EUR), USD, FX_RATE_NEAR, FX_RATE_PTS, nearDateAdj, farDateAdj);

            assertEquals(test.Product.resolve(REF_DATA), resolvedExpected);
        }
Exemple #6
0
        /// <summary>
        /// Builds a fx swap.
        /// </summary>
        /// <returns></returns>
        public static FxSwap Parse(string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference,
                                   decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis,
                                   DateTime startValueDate, DateTime forwardValueDate, Decimal startRate, Decimal forwardRate, Decimal?forwardPoints)
        {
            var fxSwap = new FxSwap
            {
                Items            = new object[] { ProductTypeHelper.Create(ProductTypeSimpleEnum.FxSwap.ToString()) },
                ItemsElementName = new[] { ItemsChoiceType2.productType }
            };
            var leg1 = ParseSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount,
                                 exchangeCurrency1, exchangeCurrency2, quoteBasis, startValueDate, startRate);
            var leg2 = PriceableFxSwapLeg.ParseForward(exchangeCurrency2PayPartyReference, exchangeCurrency1PayPartyReference, exchangeCurrency1Amount,
                                                       exchangeCurrency1, exchangeCurrency2, quoteBasis, forwardValueDate, forwardRate, forwardRate, forwardPoints);

            fxSwap.nearLeg = leg1;
            fxSwap.farLeg  = leg2;
            return(fxSwap);
        }
Exemple #7
0
        public static Trade CreateFxSwap(string tradeId, DateTime tradeDate, string exchangeCurrency1PayPartyReference, string exchangeCurrency2PayPartyReference,
                                         decimal exchangeCurrency1Amount, string exchangeCurrency1, string exchangeCurrency2, QuoteBasisEnum quoteBasis,
                                         DateTime valueDate, Decimal spotRate, Decimal?forwardRate, Decimal?forwardPoints)
        {
            var trade = new Trade {
                id = tradeId, tradeHeader = new TradeHeader()
            };
            var party1 = PartyTradeIdentifierHelper.Parse(tradeId, "party1");
            var party2 = PartyTradeIdentifierHelper.Parse(tradeId, "party2");

            trade.tradeHeader.partyTradeIdentifier = new[] { party1, party2 };
            trade.tradeHeader.tradeDate            = new IdentifiedDate {
                Value = tradeDate
            };
            var nearLeg = new FxSwapLeg();
            var farLeg  = new FxSwapLeg();

            if (forwardRate == null)
            {
                nearLeg = ParseSpot(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount,
                                    exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate);
            }
            else
            {
                farLeg = PriceableFxSwapLeg.ParseForward(exchangeCurrency1PayPartyReference, exchangeCurrency2PayPartyReference, exchangeCurrency1Amount,
                                                         exchangeCurrency1, exchangeCurrency2, quoteBasis, valueDate, spotRate, (decimal)forwardRate, forwardPoints);
            }
            var fxSwap = new FxSwap
            {
                nearLeg          = nearLeg,
                farLeg           = farLeg,
                Items            = new object[] { ProductTypeHelper.Create(ProductTypeSimpleEnum.FxSwap.ToString()) },
                ItemsElementName = new[] { ItemsChoiceType2.productType }
            };

            FpMLFieldResolver.TradeSetFxSwap(trade, fxSwap);
            return(trade);
        }
 public static void TradeSetFxSwap(Trade trade, FxSwap swap)
 {
     trade.Item            = swap;
     trade.ItemElementName = ItemChoiceType15.fxSwap;
 }
        public static object CreateFxSwap(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Value Date")] DateTime ValDate,
            [ExcelArgument(Description = "Tenor")] string Tenor,
            [ExcelArgument(Description = "Spot Price")] double SpotPrice,
            [ExcelArgument(Description = "Domestic Currency")] string DomesticCcy,
            [ExcelArgument(Description = "Foreign Currency")] string ForeignCcy,
            [ExcelArgument(Description = "Domestic Notional")] double DomesticNotional,
            [ExcelArgument(Description = "Swap Points")] double SwapPoints,
            [ExcelArgument(Description = "Foreign Discount Curve")] string DiscountCurve,
            [ExcelArgument(Description = "Solve Curve name ")] string SolveCurve,
            [ExcelArgument(Description = "Solve Pillar Date")] object SolvePillarDate,
            [ExcelArgument(Description = "Divisor, defualt 10,000")] object Divisor,
            [ExcelArgument(Description = "Spot lag, defualt 2b")] object SpotLag)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var spotLag = SpotLag.OptionalExcel("2b");
                var divisor = Divisor.OptionalExcel(10000.0);
                ContainerStores.SessionContainer.GetService <ICalendarProvider>().Collection.TryGetCalendar(DomesticCcy, out var domesticCal);
                ContainerStores.SessionContainer.GetService <ICalendarProvider>().Collection.TryGetCalendar(ForeignCcy, out var foreignCal);
                var domesticCCY = ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>().GetCurrency(DomesticCcy);
                var foreignCCY = ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>().GetCurrency(ForeignCcy);

                var pair = new FxPair()
                {
                    Domestic = domesticCCY, Foreign = foreignCCY, SpotLag = new Frequency(spotLag), PrimaryCalendar = domesticCal, SecondaryCalendar = foreignCal
                };
                var SettleDate = new DateTime();
                var SolveDate = new DateTime();
                var fwd = SpotPrice;
                switch (Tenor.ToUpper())
                {
                case "ON":
                case "O/N":
                case "OVERNIGHT":
                    SettleDate = ValDate.AddPeriod(RollType.F, domesticCal, 1.Bd());
                    SettleDate = SettleDate.IfHolidayRollForward(foreignCal);

                    var swapProduct = new FxSwap(SwapPoints, ValDate, SettleDate, DomesticNotional, ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>().GetCurrency(DomesticCcy), ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>().GetCurrency(ForeignCcy))
                    {
                        SolveCurve = SolveCurve,
                        PillarDate = DateTime.FromOADate(SolvePillarDate.OptionalExcel(SettleDate.ToOADate())),
                    };

                    return ExcelHelper.PushToCache(swapProduct, ObjectName);

                case "T/N":
                case "TN":
                    SettleDate = pair.SpotDate(ValDate).SubtractPeriod(RollType.P, domesticCal, 1.Bd());
                    var startDate = SettleDate.IfHolidayRollBack(foreignCal);
                    SolveDate = DateTime.FromOADate(SolvePillarDate.OptionalExcel(pair.SpotDate(ValDate).ToOADate()));
                    fwd -= SwapPoints / divisor;
                    break;

                default:
                    SettleDate = pair.SpotDate(ValDate);
                    var rt = Tenor.EndsWith("M") || Tenor.EndsWith("Y") ? RollType.MF : RollType.F;
                    SettleDate = SettleDate.AddPeriod(rt, domesticCal, new Frequency(Tenor));
                    SettleDate = SettleDate.IfHolidayRollForward(foreignCal);
                    fwd += SwapPoints / divisor;
                    SolveDate = DateTime.FromOADate(SolvePillarDate.OptionalExcel(SettleDate.ToOADate()));;
                    break;
                }



                var product = new FxForward
                {
                    DomesticCCY = ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>().GetCurrency(DomesticCcy),
                    ForeignCCY = ContainerStores.GlobalContainer.GetRequiredService <ICurrencyProvider>().GetCurrency(ForeignCcy),
                    DomesticQuantity = DomesticNotional,
                    DeliveryDate = SettleDate,
                    ForeignDiscountCurve = DiscountCurve,
                    SolveCurve = SolveCurve,
                    PillarDate = SolveDate,
                    Strike = fwd,
                    TradeId = ObjectName
                };

                return ExcelHelper.PushToCache(product, ObjectName);
            }));
        }
Exemple #10
0
        /// <summary>
        /// The main constructor.
        /// </summary>
        /// <param name="fxSwapFpML"></param>
        /// <param name="basePartyReference"></param>
        public FxSwapPricer(FxSwap fxSwapFpML, string basePartyReference)
        {
            //BusinessCentersResolver.ResolveBusinessCenters(swapFpML);
            Multiplier        = 1.0m;
            Id                = fxSwapFpML.id;
            OrderedPartyNames = new List <string>();
            //We make the assumption that the termination date is the same for all legs..
            var lastDate = new DateTime();

            ProductType       = ProductTypeSimpleEnum.FxSwap;
            PaymentCurrencies = new List <string>();
            var tempDate     = new DateTime();
            var fxSwapStream = fxSwapFpML.nearLeg;

            if (fxSwapStream != null)
            {
                //Set the id of the first stream.
                fxSwapStream.id = fxSwapStream.id + "_" + "nearLeg";
                var leg = new PriceableFxSwapLeg(fxSwapStream, basePartyReference, ProductTypeSimpleEnum.FxSwap);
                Legs.Add(leg);
                //Add the currencies for the trade pricer.
                if (!PaymentCurrencies.Contains(leg.Currency1.Value))
                {
                    PaymentCurrencies.Add(leg.Currency1.Value);
                }
                if (!PaymentCurrencies.Contains(leg.Currency2.Value))
                {
                    PaymentCurrencies.Add(leg.Currency2.Value);
                }
                //find the last date.
                tempDate = leg.LastDate();
                //Add the payments
                Currency1Payments = new List <InstrumentControllerBase>();
                Currency2Payments = new List <InstrumentControllerBase>();
                Currency1Payments.Add(leg.Currency1Payment);
                Currency2Payments.Add(leg.Currency2Payment);
            }
            fxSwapStream = fxSwapFpML.farLeg;
            if (fxSwapStream != null)
            {
                //Set the id of the first stream.
                fxSwapStream.id = fxSwapStream.id + "_" + "farLeg";
                var leg = new PriceableFxSwapLeg(fxSwapStream, basePartyReference, ProductTypeSimpleEnum.FxSwap);
                Legs.Add(leg);
                //Add the currencies for the trade pricer.
                if (!PaymentCurrencies.Contains(leg.Currency1.Value))
                {
                    PaymentCurrencies.Add(leg.Currency1.Value);
                }
                if (!PaymentCurrencies.Contains(leg.Currency2.Value))
                {
                    PaymentCurrencies.Add(leg.Currency2.Value);
                }
                //Add the payments
                Currency1Payments = new List <InstrumentControllerBase>();
                Currency2Payments = new List <InstrumentControllerBase>();
                Currency1Payments.Add(leg.Currency1Payment);
                Currency2Payments.Add(leg.Currency2Payment);
            }
            if (lastDate < tempDate)
            {
                lastDate = tempDate;
            }
            RiskMaturityDate = lastDate;
        }
        // create an FX Swap trade
        private static Trade createTrade3()
        {
            FxSwap swap = FxSwap.ofForwardPoints(CurrencyAmount.of(GBP, 10000), FxRate.of(GBP, USD, 1.62), 0.03, LocalDate.of(2014, 6, 14), LocalDate.of(2014, 9, 14));

            return(FxSwapTrade.builder().product(swap).info(TradeInfo.builder().id(StandardId.of("example", "3")).addAttribute(AttributeType.DESCRIPTION, "GBP 10,000/USD @ 1.62 swap").counterparty(StandardId.of("example", "BigBankA")).settlementDate(LocalDate.of(2014, 9, 15)).build()).build());
        }