Пример #1
0
 bool CompareLegs(Leg leg1, Leg leg2, MurexProduct murex, bool isFloatFloat,
     bool fullMatch, bool sameRef, ref string unmatchReason, DateTime dt)
 {
     var date = new SimpleDate(dt);
     var time = dt; 
     if (leg1.NotionalCurrency != murex.Currency1)
     {
         if (!sameRef) return false;
         else unmatchReason += "Currency1 ";
     }
     if (leg2.NotionalCurrency != murex.Currency2)
     {
         if (!sameRef) return false;
         else unmatchReason += "Currency2 ";
     }
     if (leg1.StartDate != murex.EffectiveDate &&
         leg1.FirstCalculationPeriodStart != murex.EffectiveDate)
     {
         if (!sameRef) return false;
         else unmatchReason += "SwapStartDate ";
     }
     if (leg1.EndDate != murex.EndDate)
     {
         if (!sameRef) return false;
         else unmatchReason += "SwapEndDate ";
     }
     if (Math.Abs(leg1.CurrentNominal(date, time, false) - murex.Nominal1) > _qtyTolerance)
     {
         if (fullMatch) return false;
         else unmatchReason += "Nominal1 ";
     }
     if (Math.Abs(leg2.CurrentNominal(date, time, false) - murex.Nominal2) > _qtyTolerance)
     {
         if (fullMatch) return false;
         else unmatchReason += "Nominal2 ";
     }
     if (!isFloatFloat && Math.Abs(leg1.FixedRate - murex.FixedRate) > _rateTolerance)
     {
         if (fullMatch) return false;
         else unmatchReason += "FixedRate ";
     }
     if (Math.Abs(leg2.Spread - murex.Spread2) > _rateTolerance)
     {
         if (fullMatch) return false;
         else unmatchReason += "Spread2 ";
     }
     if (leg2.FirstFixing != 0 && Math.Abs(leg2.FirstFixing - murex.FirstFixingRate2) > _rateTolerance)
     {
         if (fullMatch) return false;
         else unmatchReason += "FirstFixing2 ";
     }
     if (isFloatFloat)
     {
         if (Math.Abs(leg1.Spread - murex.Spread1) > _rateTolerance)
         {
             if (fullMatch) return false;
             else unmatchReason += "Spread1 ";
         }
         if (leg1.FirstFixing != 0 && Math.Abs(leg1.FirstFixing - murex.FirstFixingRate1) > _rateTolerance)
         {
             if (fullMatch) return false;
             else unmatchReason += "FirstFixing1 ";
         }
     }
     return true;
 }
Пример #2
0
        public Product GetProduct(IDictionary<string, Contract> contracts, Log logger)
        {
            Product prod = null;
            var prodCurrency = Env.Current.StaticData.GetCurrency(Currency1);
            if (SecurityType.Equals(TradeInfo.Bonds))
            {
                prod = Env.Current.Trade.GetProductByCode(Product.IsinProductCode, Identifier2) ??
                    Env.Current.Trade.GetProductByCode(Product.CusipProductCode, Identifier2);
            }
            else if (IsFuture)
            {
                var tickerSymbol = Identifier1.Length == 1 ? Identifier1 + " " : Identifier1;
                string ticker = tickerSymbol;
                if (SecurityType.Equals(TradeInfo.EquityFutures))
                {
                    ticker += " Index";
                }
                else if (SecurityType.Equals(TradeInfo.OtherFutures))
                {
                    ticker += " Curncy";
                }
                else
                {
                    ticker += " Comdty";
                }
                Contract c = null;
                contracts.TryGetValue(ticker, out c);
                if (c == null)
                    contracts.TryGetValue(tickerSymbol, out c);
                if (c != null)
                {
                    var maturity = Maturity;
                    if (c.UnderlierType == ContractUnderlierType.Bond)
                    {
                        var expirations = c.NextExpiries(ReportDate, c.TotalListed, true, true);
                        if (expirations != null && expirations.Count > 0)
                        {
                            foreach (var ex in expirations)
                            {
                                if (maturity == c.LastDeliveryDate(ex))
                                {
                                    maturity = ex;
                                    break;
                                }
                            }
                        }
                    }
                    var bbgTicker = c.GetFutureCode(maturity) + " " + c.TickerSuffix;
                    prod = Env.Current.Trade.GetProductByCode(Product.DefaultTicker, bbgTicker) ??
                        ImportHelper.FindFuture(false, null, contracts.Values.ToList(), bbgTicker, null, null,
                    c.ContractMonth(maturity), maturity, 0, 0, Currency1, new List<Exception>(), null);
                    if (prod == null)
                        prod = Env.Current.Trade.GetProductByCode(TradeImportHelper.MurexMaturity, c.TickerSymbol + " " + maturity);
                }
            }
            else if (IsListedOption)
            {
                Contract c = null;
                var tickerSymbol = Identifier1.Length == 1 ? Identifier1 + " " : Identifier1;
                var ticker = tickerSymbol;
                if (SecurityType.Equals(TradeInfo.IrfOption))
                {
                    ticker += " Comdty";
                }
                else if (SecurityType.Equals(TradeInfo.EqOption))
                {
                    ticker += " Equity";
                }
                else
                {
                    ticker += " Comdty";
                }
                contracts.TryGetValue(ticker, out c);
                if (c == null)
                    contracts.TryGetValue(tickerSymbol, out c);
                if (c != null)
                {
                    var contractMonth = c.ContractMonth(Maturity);
                    var bbgTicker = tickerSymbol + DateHelper.ToImm(contractMonth) + contractMonth.Year % 10
                        + CallPut + " " + Strike + " " + c.TickerSuffix;
                    prod = Env.Current.Trade.GetProductByCode(Product.DefaultTicker, bbgTicker) ??
                        ImportHelper.FindFuture(true, null, contracts.Values.ToList(), bbgTicker, null, null, contractMonth, Maturity,
                        Strike, CallPut.Equals("P") ? OptionType.Put : OptionType.Call, Currency1, new List<Exception>(), null);
                    if (prod == null)
                        prod = Env.Current.Trade.GetProductByCode(TradeImportHelper.MurexMaturity, c.TickerSymbol + " " + Maturity
                            + " " + CallPut + Strike);
                }
            }
            else if (SecurityType.Equals(SwapInfo.IRSwap) || SecurityType.Equals(Fras) || SecurityType.Equals(SwapInfo.CcySwap)
                || SecurityType.Equals(SwaptionInfo.Swaption))
            {
                var murex = new MurexProduct();
                prod = murex;
                string prodtype;
                if (SecurityType.Equals(SwapInfo.IRSwap))
                {
                    prodtype = prodCurrency.IsNonDeliverable ? "NDS" : "Swap";
                }
                else if (SecurityType.Equals(SwapInfo.CcySwap))
                {
                    prodtype = Instrument.Contains("MTM") ? "MTMCurrencySwap" : "CurrencySwap";
                }
                else if (SecurityType.Equals(MurexInfo.Fras))
                {
                    prodtype = "FRA";
                }
                else
                {
                    prodtype = "Swaption";
                }
                murex.ProductProcessingType = prodtype;
                murex.ProductAccountingType = prodtype;
                murex.ProductPricingType = prodtype;
                murex.Generator = Instrument;
                if (prodtype == "Swaption")
                {
                    murex.Nominal1 = Math.Abs(Nominal1);
                    murex.Nominal2 = Math.Abs(Nominal2);
                    murex.Notional = murex.Nominal1;
                    murex.Currency1 = Currency1;
                    murex.Currency2 = Currency2;
                    if (OptionExerciseMethod != null)
                    {
                        murex.ExerciseSettlement = OptionExerciseMethod.Equals("0")
                            ? ExerciseSettlement.Physical : ExerciseSettlement.Cash;
                    }
                    murex.EffectiveDate = SettleDate;
                    murex.EndDate = SwaptionMaturity;
                    murex.SwapStartDate = StartDate1;
                    murex.SwapEndDate = EndDate;
                    murex.UpFrontAmount = UpFrontAmount;
                    murex.UpFrontCcy = UpFrontCcy;
                    murex.UpFrontDate = UpFrontDate;
                    murex.FixedRate = Strike / 100;
                    if (CallPut != null)
                        murex.CallPut = CallPut.Equals("C") ? OptionType.Call : OptionType.Put;
                    if (OptionStyle != null)
                        murex.ExerciseType = OptionStyle.Equals("E") ? OptionExerciseType.European : OptionExerciseType.American;
                }
                else
                {
                    // swap, fra..
                    murex.Nominal1 = Math.Abs(Nominal1);
                    murex.Nominal2 = Math.Abs(Nominal2);
                    murex.Notional = murex.Nominal1;
                    murex.Currency1 = Currency1;
                    murex.Currency2 = Currency2;
                    murex.EffectiveDate = StartDate1;
                    murex.EndDate = EndDate;
                    murex.FirstFixingRate1 = FirstFixingRate1 / 100;
                    murex.FirstFixingRate2 = FirstFixingRate2 / 100;
                    murex.Spread1 = Spread1 / 100;
                    murex.Spread2 = Spread2 / 100;
                    murex.FixedRate = Price / 100;
                    murex.UpFrontAmount = UpFrontAmount;
                    murex.UpFrontCcy = UpFrontCcy;
                    murex.UpFrontDate = UpFrontDate;
                }
            }
            else if (SecurityType.Equals(FxInfo.SpotForward) || SecurityType.Equals(FxoInfo.SimpleFXO))
            {
                CurrencyPair cp;
                string c1, c2;
                c1 = PrimaryCcy ?? Currency1;
                c2 = QuotingCcy ?? Currency2;
                cp = Env.Current.Trade.GetCurrencyPair(c1, c2);
                if (cp != null)
                {
                    var ccy1 = Env.Current.StaticData.GetCurrency(cp.Primary);
                    var ccy2 = Env.Current.StaticData.GetCurrency(cp.Quoting);
                    var isNdf = false;
                    if (!FixingDate.IsNull)
                        isNdf = true;
                    if (SecurityType.Equals(FxInfo.SpotForward))
                    {
                        var fx = isNdf ? new NDF() : new FX();
                        prod = fx;
                        fx.IsForward = false;
                        fx.Primary = cp.Primary;
                        fx.Quoting = cp.Quoting;
                        fx.PrimarySettleDate = NDFSettleDate;
                        fx.QuotingSettleDate = NDFSettleDate;
                        if (fx.Primary == PrimaryCcy)
                        {
                            fx.PrimaryAmount = Math.Abs(PrimaryAmount);
                            fx.QuotingAmount = Math.Abs(QuotingAmount);
                        }
                        else
                        {
                            fx.PrimaryAmount = Math.Abs(QuotingAmount);
                            fx.QuotingAmount = Math.Abs(PrimaryAmount);
                        }
                        fx.SpotRate = Math.Abs(Price);
                        if (isNdf)
                        {
                            var ndCcy = ccy1.IsNonDeliverable ? cp.Primary : cp.Quoting;
                            var ndfixing = cp.Quoting + "/" + cp.Primary;
                            var ndf = fx as NDF;
                            ndf.NonDeliverableCurrency = ndCcy;
                            var fix = Env.Current.StaticData.GetFxFixing(ndfixing);
                            if (fix != null)
                            {
                                ndf.FXFixingName = fix.Name;
                                ndf.FXFixingOffset = fix.FixingLag;
                                ndf.FXFixingDate = FixingDate;
                                ndf.FixingValue = FixingRate;
                            }
                        }
                    }
                    else
                    {
                        var fxo = new FXOption();
                        prod = fxo;
                        fxo.ExpiryDate = Maturity;
                        fxo.Primary = cp.Primary;
                        fxo.Quoting = cp.Quoting;
                        fxo.IsBuy = BuySell.Equals("B") ? true : false;
                        if (fxo.Primary.Equals(Currency1))
                        {
                            fxo.PrimaryAmount = Math.Abs(Nominal1);
                            fxo.QuotingAmount = Math.Abs(Nominal2);

                        }
                        else
                        {
                            fxo.PrimaryAmount = Math.Abs(Nominal2);
                            fxo.QuotingAmount = Math.Abs(Nominal1);
                        }
                        fxo.OptionStrike = Math.Abs(Strike);
                        if (OptionExerciseMethod != null)
                            fxo.ExerciseSettlement = OptionExerciseMethod.Equals("0") ? ExerciseSettlement.Cash : ExerciseSettlement.Physical;
                        fxo.InitialPremiumAmount = Math.Abs(UpFrontAmount);
                        fxo.InitialPremiumDate = UpFrontDate;
                        fxo.InitialPremiumCurrency = UpFrontCcy;
                        fxo.InitialPremiumPayReceive = UpFrontAmount > 0 ? PayReceive.Receive : PayReceive.Pay;
                        fxo.OptionType = CallPut == "P" ? OptionType.Put : OptionType.Call;
                        if (fxo.ExerciseSettlement == ExerciseSettlement.Cash)
                            fxo.SettleCurrency = Currency1;
                        fxo.SettlementMarketPlaces = cp.DefaultMarketPlaces;
                        fxo.SettlementLag = cp.SpotLag;
                        fxo.ExerciseType = OptionExerciseType.European;
                    }
                }
                else
                    logger.Error("Cannot find CurrencyPair: " + Symbol);
            }
            if (prod == null)
                prod = new GenericProduct
                {
                    ProductProcessingType = SecurityType,
                    ProductDescription = Symbol
                };
            return prod;
        }
Пример #3
0
 bool CompareFees(Trade tr1, MurexProduct murex)
 {
     if (murex.UpFrontAmount != 0)
     {
         if (tr1.Fees == null) return false;
         foreach (var f in tr1.Fees)
         {
             if (f.FeeType == FeeType.Upfront)
             {
                 if (Math.Abs(f.Amount - Math.Abs(murex.UpFrontAmount)) > _amountTolerance) continue;
                 if (f.Currency != murex.UpFrontCcy) continue;
                 //if (f.PayReceive == PayReceive.Pay && murex.UpFrontAmount > 0) continue;
                 //if (f.PayReceive == PayReceive.Receive && murex.UpFrontAmount < 0) continue;
                 if (f.Date != murex.UpFrontDate) continue;
                 return true;
             }
         }
         return false;
     }
     return true;
 }