protected string GetCutOff(FXOption opt)
 {
     var expireCity = opt.ExpireCity;
     var cutOffTime = opt.OptionExerciseTime;
     var cutOffTZ = opt.OptionExerciseTimeZone;
     string name = null;
     if (expireCity != null)
     {
         name = expireCity + " " + cutOffTime.ToString(CultureInfo.InvariantCulture);                
     }
     else if (cutOffTZ != null)
     {
         var cp = Env.Current.Trade.GetCurrencyPair(opt.Primary, opt.Quoting);
         if (cp != null && cp.DefaultExpireCity != null && cp.DefaultOptionExerciseTimeZone != null 
             && cp.DefaultOptionExerciseTimeZone.Equals(cutOffTZ))
         {
             name = cp.DefaultExpireCity + " " + cutOffTime.ToString(CultureInfo.InvariantCulture);   
         }
     }
     if (name != null)
     {
         var aliases = Env.Current.StaticData.GetAliasesByName(new Alias
         {
             EntityId = 0,
             AliasType = AliasTypeCutOff,
             Source = AliasSourceCutOff,
             Name = name
         });
         if (aliases != null && aliases.Count > 0)
             return aliases[0].SourceReference;
     }
     return null;
 }
Example #2
0
        private void FillOptionInfo(TradeInfo info, FXOption fxo, OptionInfo optionInfo)
        {
            if (info.SecurityType.Equals(FxoInfo.SimpleFXO))
            {
                // european digital and european
                if (info.OptionStyle.Equals("D"))
                {
                    var dinfo = optionInfo as DigitalInfo;
                    if (dinfo == null)
                    {
                        dinfo = new DigitalInfo();
                        fxo.OptionInfo = dinfo;
                        dinfo.Option = fxo;
                    }
                    fxo.ExerciseType = OptionExerciseType.Digital;
                    dinfo.ExerciseType = OptionExerciseType.European;
                    dinfo.StartDate = info.Maturity;
                    dinfo.EndDate = info.Maturity;
                    if (fxo.OptionType == OptionType.Call)
                    {
                        dinfo.BarrierStrike = fxo.OptionStrike;
                        dinfo.BarrierType = OptionBarrierType.Touch;
                        dinfo.LowerBarrierStrike = 0;
                        dinfo.LowerBarrierType = OptionBarrierType.None;
                    }
                    else
                    {
                        dinfo.LowerBarrierStrike = fxo.OptionStrike;
                        dinfo.LowerBarrierType = OptionBarrierType.Touch;
                        dinfo.BarrierStrike = 0;
                        dinfo.BarrierType = OptionBarrierType.None;
                    }
                    // pay off, currency, and payout style: deferred or...
                }
                else
                    fxo.ExerciseType = OptionExerciseType.European;
                    // settle currency
            }
            /*
            else if (info.SecurityType.Equals(TradeInfo.BarrierFXO))
            {
                // barrier
                var binfo = optionInfo as BarrierInfo;
                if (binfo == null)
                {
                    binfo = new BarrierInfo();
                    fxo.OptionInfo = binfo;
                    binfo.Option = fxo;
                }
                binfo.ExerciseType = OptionExerciseType.European;
                // start/end date
                // barrier type and strike

            }
            else if (info.SecurityType.Equals(TradeInfo.TouchFXO))
            {
                // touch
                var tinfo = optionInfo as DigitalInfo;
                if (tinfo == null)
                {
                    tinfo = new DigitalInfo();
                    fxo.OptionInfo = tinfo;
                    tinfo.Option = fxo;
                }
                tinfo.ExerciseType = OptionExerciseType.American;
                // barrier strike and type
                // rebate amount
            }*/
        }
        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;
        }