private void SetProperties(NamedValueSet properties)
 {
     try
     {
         DataType     = "Trade";
         SourceSystem = PropertyHelper.ExtractSourceSystem(properties);
         var tradeId = properties.GetValue <string>(TradeProp.TradeId);
         Id               = tradeId;
         Domain           = SourceSystem + '.' + DataType;
         TradeDate        = properties.GetValue <DateTime>(TradeProp.TradeDate);
         TradeType        = EnumHelper.Parse <ItemChoiceType15>(properties.GetValue <string>(TradeProp.TradeType), true);
         ProductType      = ProductTypeSimpleScheme.ParseEnumString(properties.GetValue <string>(TradeProp.ProductType, false));
         Party1           = properties.GetValue <string>(TradeProp.Party1, false);
         Party2           = properties.GetValue <string>(TradeProp.Party2, false);
         BaseParty        = properties.GetValue <string>(TradeProp.BaseParty);
         CounterParty     = properties.GetValue <string>(TradeProp.CounterPartyId);
         UniqueIdentifier = BuildUniqueId(tradeId);
         if (properties.GetValue <string>(CurveProp.UniqueIdentifier) != null)
         {
             UniqueIdentifier = properties.GetValue <string>(CurveProp.UniqueIdentifier);
         }
         PropertyHelper.Update(Properties, CurveProp.UniqueIdentifier, UniqueIdentifier);
         PropertyHelper.Update(Properties, "Domain", Domain);
     }
     catch
     {
         throw new System.Exception("Invalid tradeid.");
     }
 }
Exemple #2
0
        //public static object[,] DoReport(TermDeposit termDeposit)
        //{
        //    if (termDeposit != null)
        //    {
        //        var result = new object[10, 2];
        //        result[0, 0] = "adjustedEffectiveDate";
        //        result[1, 0] = "fixedRate";
        //        result[2, 0] = "maturityDate";
        //        result[3, 0] = "dayCountFraction";
        //        result[4, 0] = "lenderPartyReference";
        //        result[5, 0] = "borrowerPartyReference";
        //        result[6, 0] = "currency";
        //        result[7, 0] = "notionalamount";
        //        result[8, 0] = "interest";
        //        result[9, 0] = "dayCount";

        //        result[0, 1] = termDeposit.startDate;
        //        result[1, 1] = termDeposit.fixedRate;
        //        result[2, 1] = termDeposit.maturityDate;
        //        result[3, 1] = termDeposit.dayCountFraction.Value;
        //        result[4, 1] = termDeposit.initialPayerReference.href;
        //        result[5, 1] = termDeposit.initialReceiverReference.href;
        //        result[6, 1] = termDeposit.principal.currency.Value;
        //        result[7, 1] = termDeposit.principal.amount;
        //        result[8, 1] = termDeposit.interest.amount;
        //        result[9, 1] = termDeposit.dayCountFraction.Value;

        //        return result;
        //    }
        //    return null;
        //}

        public override object[,] DoReport(Product product, NamedValueSet properties)
        {
            if (product is FxSwap fxswap)
            {
                var party1 = properties.GetValue <string>(TradeProp.Party1, true);
                var party2 = properties.GetValue <string>(TradeProp.Party2, true);
                var result = new object[7, 2];
                result[0, 0] = "payerPartyReference";
                result[1, 0] = "receiverPartyReference";
                result[2, 0] = "amount";
                result[3, 0] = "currency";
                result[4, 0] = "paymentDate";
                result[5, 0] = "party1";
                result[6, 0] = "party2";

                var temp1 = fxswap.nearLeg;
                result[0, 1] = temp1.exchangedCurrency1.payerPartyReference.href;
                result[1, 1] = temp1.exchangedCurrency1.receiverPartyReference.href;
                result[2, 1] = temp1.exchangedCurrency1.paymentAmount.amount;
                result[3, 1] = temp1.exchangedCurrency1.paymentAmount.currency.Value;
                var containdUnadjustedDate = AdjustableOrAdjustedDateHelper.Contains(temp1.exchangedCurrency1.paymentDate, ItemsChoiceType.unadjustedDate, out var unadjustedDate);
                if (containdUnadjustedDate)
                {
                    result[4, 1] = ((IdentifiedDate)unadjustedDate).Value;
                }
                result[5, 1] = party1;
                result[6, 1] = party2;

                return(result);
            }
            return(null);
        }
        public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] expiryTenors, Double[] strikes,
                                     Double[,] volSurface)
            : base(logger, cache, nameSpace, properties, expiryTenors, strikes, volSurface)
        {
            var assetClass = properties.GetString(CurveProp.AssetClass, true);
            var type       = EnumHelper.Parse <AssetClass>(assetClass);
            var assetId    = properties.GetValue <string>(CurveProp.AssetId, true);
            var baseDate   = properties.GetValue <DateTime>(CurveProp.BaseDate, true);

            PricingStructureData      = new PricingStructureData(CurveType.Parent, type);
            UnderlyingPriceableAssets = new List <IPriceableAssetController>();
            foreach (var tenor in expiryTenors)
            {
                var expiryTenor = PeriodHelper.Parse(tenor);
                var offset      = new Offset
                {
                    period           = expiryTenor.period,
                    periodMultiplier = expiryTenor.periodMultiplier,
                    periodSpecified  = true,
                    dayType          = DayTypeEnum.Calendar,
                    dayTypeSpecified = true
                };
                var expiryDate      = offset.Add(baseDate);
                var assetProperties = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, assetId, expiryDate);
                var asset           = PriceableAssetFactory.Create(logger, cache, nameSpace, null, assetProperties, null, null);
                UnderlyingPriceableAssets.Add(asset);
            }
        }
        //public static object[,] DoReport(TermDeposit termDeposit)
        //{
        //    if (termDeposit != null)
        //    {
        //        var result = new object[10, 2];
        //        result[0, 0] = "adjustedEffectiveDate";
        //        result[1, 0] = "fixedRate";
        //        result[2, 0] = "maturityDate";
        //        result[3, 0] = "dayCountFraction";
        //        result[4, 0] = "lenderPartyReference";
        //        result[5, 0] = "borrowerPartyReference";
        //        result[6, 0] = "currency";
        //        result[7, 0] = "notionalamount";
        //        result[8, 0] = "interest";
        //        result[9, 0] = "dayCount";

        //        result[0, 1] = termDeposit.startDate;
        //        result[1, 1] = termDeposit.fixedRate;
        //        result[2, 1] = termDeposit.maturityDate;
        //        result[3, 1] = termDeposit.dayCountFraction.Value;
        //        result[4, 1] = termDeposit.initialPayerReference.href;
        //        result[5, 1] = termDeposit.initialReceiverReference.href;
        //        result[6, 1] = termDeposit.principal.currency.Value;
        //        result[7, 1] = termDeposit.principal.amount;
        //        result[8, 1] = termDeposit.interest.amount;
        //        result[9, 1] = termDeposit.dayCountFraction.Value;
        //        return result;
        //    }
        //    return null;
        //}

        public override object[,] DoReport(Product product, NamedValueSet properties)
        {
            if (product is TermDeposit termDeposit)
            {
                var party1 = properties.GetValue <string>(TradeProp.Party1, true);
                var party2 = properties.GetValue <string>(TradeProp.Party2, true);
                var result = new object[11, 2];
                result[0, 0] = "adjustedEffectiveDate";
                result[1, 0] = "fixedRate";
                result[2, 0] = "maturityDate";
                result[3, 0] = "dayCountFraction";
                result[4, 0] = "lenderPartyReference";
                result[5, 0] = "borrowerPartyReference";
                result[6, 0] = "currency";
                result[7, 0] = "notionalAmount";
                //result[8, 0] = "interest";
                result[8, 0]  = "dayCount";
                result[9, 0]  = "party1";
                result[10, 0] = "party2";
                result[0, 1]  = termDeposit.startDate;
                result[1, 1]  = termDeposit.fixedRate;
                result[2, 1]  = termDeposit.maturityDate;
                result[3, 1]  = termDeposit.dayCountFraction.Value;
                result[4, 1]  = termDeposit.payerPartyReference.href;
                result[5, 1]  = termDeposit.receiverPartyReference.href;
                result[6, 1]  = termDeposit.principal.currency.Value;
                result[7, 1]  = termDeposit.principal.amount;
                //result[8, 1] = termDeposit.interest.amount;
                result[8, 1]  = termDeposit.dayCountFraction.Value;
                result[9, 1]  = party1;
                result[10, 1] = party2;
                return(result);
            }
            return(null);
        }
        //public static object[,] DoReport(BulletPayment bulletPayment)
        //{
        //    if (bulletPayment != null)
        //    {
        //        var result = new object[7, 2];
        //        result[0, 0] = "adjustedPaymentDate";
        //        result[1, 0] = "paymentAmount";
        //        result[2, 0] = "currency";
        //        result[3, 0] = "paymentType";
        //        result[4, 0] = "lenderPartyReference";
        //        result[5, 0] = "borrowerPartyReference";
        //        result[6, 0] = "currency";

        //        result[0, 1] = bulletPayment.payment.adjustedPaymentDate;
        //        result[1, 1] = bulletPayment.payment.paymentAmount.amount;
        //        result[2, 1] = bulletPayment.payment.paymentAmount.currency.Value;
        //        result[3, 1] = bulletPayment.payment.paymentType.Value;
        //        result[4, 1] = bulletPayment.payment.payerPartyReference.href;
        //        result[5, 1] = bulletPayment.payment.receiverPartyReference.href;
        //        result[6, 1] = bulletPayment.payment.presentValueAmount!= null ? bulletPayment.payment.presentValueAmount.amount : 0.0m;

        //        return result;
        //    }
        //    return null;
        //}

        public override object[,] DoReport(Product product, NamedValueSet properties)
        {
            if (product is BulletPayment payment)
            {
                var party1 = properties.GetValue <string>(TradeProp.Party1, true);
                var party2 = properties.GetValue <string>(TradeProp.Party2, true);
                var result = new object[7, 2];
                result[0, 0] = "payerPartyReference";
                result[1, 0] = "receiverPartyReference";
                result[2, 0] = "amount";
                result[3, 0] = "currency";
                result[4, 0] = "businessDayConvention";
                result[5, 0] = "party1";
                result[6, 0] = "party2";
                var temp = payment.payment;
                result[0, 1] = temp.payerPartyReference.href;
                result[1, 1] = temp.receiverPartyReference.href;
                result[2, 1] = temp.paymentAmount.amount;
                result[3, 1] = temp.paymentAmount.currency.Value;
                var containsBusinessCenters = AdjustableOrAdjustedDateHelper.Contains(temp.paymentDate, ItemsChoiceType.dateAdjustments, out var businessDayAdjustments);
                if (containsBusinessCenters && businessDayAdjustments != null)
                {
                    var businessDayConvention = ((BusinessDayAdjustments)businessDayAdjustments).businessDayConvention.ToString();
                    result[4, 1] = businessDayConvention;
                }
                else
                {
                    result[4, 1] = "NONE";
                }
                result[5, 1] = party1;
                result[6, 1] = party2;
                return(result);
            }
            return(null);
        }
 public override object[,] DoReport(Product product, NamedValueSet properties)
 {
     if (product is Fra forwardRateAgreement)
     {
         var party1 = properties.GetValue <string>(TradeProp.Party1, true);
         var party2 = properties.GetValue <string>(TradeProp.Party2, true);
         var result = new object[11, 2];
         result[0, 0]  = "adjustedEffectiveDate";
         result[1, 0]  = "fixedRate";
         result[2, 0]  = "paymentDate";
         result[3, 0]  = "calculationPeriodNumberOfDays";
         result[4, 0]  = "adjustedTerminationDate";
         result[5, 0]  = "buyerPartyReference";
         result[6, 0]  = "sellerPartyReference";
         result[7, 0]  = "currency";
         result[8, 0]  = "notionalAmount";
         result[9, 0]  = "party1";
         result[10, 0] = "party2";
         result[0, 1]  = forwardRateAgreement.adjustedEffectiveDate.Value;
         result[1, 1]  = forwardRateAgreement.fixedRate;
         result[2, 1]  = forwardRateAgreement.paymentDate.unadjustedDate.Value;
         result[3, 1]  = forwardRateAgreement.calculationPeriodNumberOfDays;
         result[4, 1]  = forwardRateAgreement.adjustedTerminationDate;
         result[5, 1]  = forwardRateAgreement.buyerPartyReference.href;
         result[6, 1]  = forwardRateAgreement.sellerPartyReference.href;
         result[7, 1]  = forwardRateAgreement.notional.currency.Value;
         result[8, 1]  = forwardRateAgreement.notional.amount;
         result[9, 1]  = party1;
         result[10, 1] = party2;
         return(result);
     }
     return(null);
 }
Exemple #7
0
        public static void LoadPricingStructures(ILogger logger, ICoreCache targetClient, string nameSpace)
        {
            logger.LogDebug("Loading pricing structures...");
            Assembly     assembly = Assembly.GetExecutingAssembly();
            const string prefix   = "FpML.V5r10.ConfigData.PricingStructures";
            Dictionary <string, string> chosenFiles = ResourceHelper.GetResources(assembly, prefix, "xml");

            if (chosenFiles.Count == 0)
            {
                throw new InvalidOperationException("Missing Pricing Structures");
            }

            foreach (KeyValuePair <string, string> file in chosenFiles)
            {
                var    market     = XmlSerializerHelper.DeserializeFromString <Market>(file.Value);
                string nvs        = ResourceHelper.GetResource(assembly, file.Key.Replace(".xml", ".nvs"));
                var    extraProps = new NamedValueSet(nvs);
                string idSuffix   =
                    $"{extraProps.GetValue<string>(CurveProp.Market)}.{extraProps.GetValue<string>(CurveProp.PricingStructureType)}.{extraProps.GetValue<string>(CurveProp.CurveName)}";
                ItemInfo itemInfo = MakePricingStructureConfigProps("PricingStructures", idSuffix, extraProps, nameSpace);
                logger.LogDebug("  {0} ...", idSuffix);
                targetClient.SaveObject(market, itemInfo.ItemName, itemInfo.ItemProps, false, TimeSpan.MaxValue);
            } // foreach file
            logger.LogDebug("Loaded {0} pricing structures.", chosenFiles.Count);
        }
 private void SetProperties(NamedValueSet properties)
 {
     try
     {
         DataType      = FunctionProp.ValuationReport.ToString();
         SourceSystem  = PropertyHelper.ExtractSourceSystem(properties);
         PortfolioId   = properties.GetValue <string>(ValueProp.PortfolioId, false);
         TradeId       = properties.GetValue <string>(TradeProp.TradeId, true);
         TradeType     = properties.GetValue <string>(TradeProp.TradeType, true);
         Id            = SourceSystem + "." + TradeType + "." + TradeId;
         Market        = PropertyHelper.ExtractMarket(Properties);
         MarketAndDate = PropertyHelper.ExtractMarketAndDate(Properties);
         MarketName    = properties.GetValue <string>(ValueProp.MarketName, false) ?? MarketAndDate;
         DateTime?marketDate = PropertyHelper.ExtractMarketDate(Properties);
         MarketDate          = marketDate ?? MarketDate;
         Domain              = SourceSystem + '.' + DataType;
         CalculationDateTime = properties.GetValue <DateTime>(ValueProp.CalculationDateTime);
         BaseParty           = properties.GetValue <string>(ValueProp.BaseParty);
         CalculationDateTime = properties.GetValue <DateTime>(ValueProp.CalculationDateTime);
         UniqueIdentifier    = BuildUniqueId();
         if (properties.GetValue <string>(ValueProp.UniqueIdentifier) != null)
         {
             UniqueIdentifier = properties.GetValue <string>(ValueProp.UniqueIdentifier);
         }
         Scenario = properties.GetValue <string>(ValueProp.Scenario);
         PropertyHelper.Update(Properties, ValueProp.UniqueIdentifier, UniqueIdentifier);
         PropertyHelper.Update(Properties, "Domain", Domain);
     }
     catch
     {
         throw new System.Exception("Invalid tradeId.");
     }
 }
Exemple #9
0
 public override object[,] DoReport(Product product, NamedValueSet properties)
 {
     if (product is PropertyTransaction propertyTransaction)
     {
         var party1 = properties.GetValue <string>(TradeProp.Party1, true);
         var party2 = properties.GetValue <string>(TradeProp.Party2, true);
         var result = new object[9, 2];
         result[0, 0] = "buyerPartyReference";
         result[1, 0] = "sellerPartyReference";
         result[2, 0] = "numberOfUnits";
         result[3, 0] = "unitPriceCurrency";
         result[4, 0] = "unitPriceAmount";
         result[5, 0] = "id";
         result[6, 0] = "paryt1";
         result[7, 0] = "party2";
         result[8, 0] = "description";
         var temp = propertyTransaction.property;
         result[0, 1] = propertyTransaction.buyerPartyReference.href;
         result[1, 1] = propertyTransaction.sellerPartyReference.href;
         result[2, 1] = propertyTransaction.purchasePrice.amount;
         result[3, 1] = temp.currency.Value;
         result[4, 1] = propertyTransaction.purchasePrice.amount;
         result[5, 1] = temp.id;
         result[6, 1] = party1;
         result[7, 1] = party2;
         result[8, 1] = temp.description;
         return(result);
     }
     return(null);
 }
Exemple #10
0
        private void SendAlertSignalEmail(InternalSignal signal, NamedValueSet props)
        {
            try
            {
                var smtpHost = props.GetValue <string>(AlertRule.MailHost);
                IEnumerable <string> recipients = ResolveMultipleEmailAddresses(props.GetArray <string>(AlertRule.MailTo));
                string sender      = ResolveSingleEmailAddress(props.GetValue <string>(AlertRule.MailFrom));
                var    email       = new MailMessage();
                string instanceMsg = GetInstanceMsg(signal.ReminderCount);
                signal.ReminderCount += 1;
                email.Subject         =
                    $"QDS Alert {EnvHelper.EnvName(IntClient.Target.ClientInfo.ConfigEnv)}. {signal.RuleName}: {signal.Status}";

                if (signal.Status == AlertStatus.Alerted)
                {
                    email.Subject += $"({instanceMsg})";
                }
                var body = new StringBuilder(signal.SignalMessage);
                if (props.GetValue <bool>("rule.DebugEnabled", false))
                {
                    body.AppendLine();
                    body.AppendLine();
                    body.AppendLine("[debug-begin]");
                    props.LogValues(text => body.AppendLine("  " + text));
                    body.AppendLine("[debug-end]");
                }
                email.Body = body.ToString();
                SendEmail(smtpHost, email, sender, recipients);
            }
            catch (Exception excp)
            {
                ReportUncaughtError("EmailAlertSignal", signal.RuleName, excp, props);
            }
        }
Exemple #11
0
        /// <summary>
        /// Create a series of CapFloor engines from a raw volatility grid and a DF curve
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="properties">The properties of the engine, including the reference handle to access this engine collection</param>
        /// <param name="instruments">An array of instrument types.</param>
        /// <param name="rawVolatilityGrid">The raw grid used to build the engines. Assume that all volatility and strike values are 100x true</param>
        /// <param name="dfDataTimeGrid">The discount factor dates array.</param>
        /// <param name="dfGrid">The discount factors required for bootstrapping</param>
        /// <returns>The engine handle or an error message</returns>
        public string CreateCapFloorATMCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties,
                                             String[] instruments, Decimal[] rawVolatilityGrid, DateTime[] dfDataTimeGrid, Decimal[] dfGrid)
        {
            var volatilityCheck = CheckVolatilities(rawVolatilityGrid);

            if (volatilityCheck != null)
            {
                throw new ArgumentException(volatilityCheck);
            }
            var id            = properties.GetString("EngineHandle", true);
            var baseDate      = properties.GetValue <DateTime>("BaseDate", true);
            var valuationDate = properties.GetValue("ValuationDate", DateTime.MinValue);

            if (valuationDate == DateTime.MinValue)
            {
                properties.Set("ValuationDate", baseDate);
            }
            properties.Set("PricingStructureType", PricingStructureTypeEnum.CapVolatilityCurve.ToString());
            var strikeQuoteUnits = properties.GetString("StrikeQuoteUnits", null);

            if (strikeQuoteUnits == null)
            {
                properties.Set("StrikeQuoteUnits", StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString());
            }
            var measureType = properties.GetString("MeasureType", null);

            if (measureType == null)
            {
                properties.Set("MeasureType", MeasureTypesEnum.Volatility.ToString());
            }
            var quoteUnits = properties.GetString("QuoteUnits", null);

            if (quoteUnits == null)
            {
                properties.Set("QuoteUnits", QuoteUnitsEnum.LogNormalVolatility.ToString());
            }
            var algorithm = properties.GetString("Algorithm", null);

            if (algorithm == null)
            {
                properties.Set("Algorithm", "Default");
            }
            InterpolationMethod interp = InterpolationMethodHelper.Parse("LogLinearInterpolation");
            // Check there are valid strikes
            IRateCurve discountCurve =
                new SimpleDiscountFactorCurve(baseDate, interp, true, dfDataTimeGrid, dfGrid);

            // Create the engines and either add to, or overwrite the existing, collection
            if (_capFloorEngine.ContainsKey(id))
            {
                _capFloorEngine[id] = CreateCurves(logger, cache, nameSpace, properties, discountCurve, discountCurve, instruments, rawVolatilityGrid);
            }
            else
            {
                _capFloorEngine.Add(id, CreateCurves(logger, cache, nameSpace, properties, discountCurve, discountCurve, instruments, rawVolatilityGrid));
            }
            return(id);
        }
Exemple #12
0
        /// <summary>
        /// Create a series of CapFloor engines from a raw volatility grid and a DF curve
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="properties">The properties of the engine, including the reference handle to access this engine collection</param>
        /// <param name="instruments">An array of instrument types.</param>
        /// <param name="rawVolatilityGrid">The raw grid used to build the engines. Assume that all volatility and strike values are 100x true</param>
        /// <returns>The engine handle or an error message</returns>
        public string CreateCapFloorATMCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties,
                                             String[] instruments, Decimal[] rawVolatilityGrid)
        {
            var volatilityCheck = CheckVolatilities(rawVolatilityGrid);

            if (volatilityCheck != null)
            {
                throw new ArgumentException(volatilityCheck);
            }
            var id            = properties.GetString("EngineHandle", true);
            var baseDate      = properties.GetValue <DateTime>("BaseDate", true);
            var valuationDate = properties.GetValue("ValuationDate", DateTime.MinValue);

            if (valuationDate == DateTime.MinValue)
            {
                properties.Set("ValuationDate", baseDate);
            }
            properties.Set("PricingStructureType", PricingStructureTypeEnum.CapVolatilityCurve.ToString());
            var strikeQuoteUnits = properties.GetString("StrikeQuoteUnits", null);

            if (strikeQuoteUnits == null)
            {
                properties.Set("StrikeQuoteUnits", StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString());
            }
            var measureType = properties.GetString("MeasureType", null);

            if (measureType == null)
            {
                properties.Set("MeasureType", MeasureTypesEnum.Volatility.ToString());
            }
            var quoteUnits = properties.GetString("QuoteUnits", null);

            if (quoteUnits == null)
            {
                properties.Set("QuoteUnits", QuoteUnitsEnum.LogNormalVolatility.ToString());
            }
            var algorithm = properties.GetString("Algorithm", null);

            if (algorithm == null)
            {
                properties.Set("Algorithm", "Default");
            }
            var referenceDiscountCurve = properties.GetString("ReferenceCurveUniqueId", true);
            var referenceForecastCurve = properties.GetString("ReferenceCurrency2CurveId", referenceDiscountCurve);
            var discountCurve          = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, null, null, referenceDiscountCurve);
            var forecastCurve          = CurveLoader.LoadInterestRateCurve(logger, cache, nameSpace, null, null, referenceForecastCurve);

            // Create the engines and either add to, or overwrite the existing, collection
            if (_capFloorEngine.ContainsKey(id))
            {
                _capFloorEngine[id] = CreateCurves(logger, cache, nameSpace, properties, discountCurve, forecastCurve, instruments, rawVolatilityGrid);
            }
            else
            {
                _capFloorEngine.Add(id, CreateCurves(logger, cache, nameSpace, properties, discountCurve, forecastCurve, instruments, rawVolatilityGrid));
            }
            return(id);
        }
Exemple #13
0
        /// <summary>
        /// A helper to extract properties from a named value set..
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static string ExtractMarket(NamedValueSet properties)
        {
            string market = properties.GetValue(CurveProp.Market, "");

            if (string.IsNullOrEmpty(market))
            {
                market = properties.GetValue(CurveProp.MarketAndDate, "Unspecified");
            }
            return(market);
        }
Exemple #14
0
        public CapVolatilityCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, QuotedAssetSet instrumentData,
                                  IRateCurve discountCurve, IRateCurve forecastCurve, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : this(logger, cache, nameSpace, new VolatilitySurfaceIdentifier(properties), fixingCalendar, rollCalendar)
        {
            DiscountCurve = discountCurve;
            ForecastCurve = forecastCurve;
            var curveId  = GetCurveId();
            var volCurve = SetConfigurationData();

            //TODO This for backwards compatability. AnalyticalResults is the current interface.
            Handle           = properties.GetString(CurveProp.EngineHandle, null);
            BootstrapResults = new VolCurveBootstrapResults();
            //Set the underlying asset information.
            var instrument = properties.GetString(CurveProp.Instrument, true);

            Asset = new AnyAssetReference {
                href = instrument
            };
            UnderlyingAssetDetails = CreateUnderlyingAssetWithProperties();
            var extrapolationPermitted = ExtrapolationPermittedInput ?? ExtrapolationPermitted;

            PriceableOptionAssets    = PriceableAssetFactory.CreatePriceableRateOptionAssets(logger, cache, nameSpace, curveId.BaseDate, instrumentData, fixingCalendar, rollCalendar);
            BootstrapResults.Results = CapFloorBootstrapper.Bootstrap(PriceableOptionAssets, properties, DiscountCurve, ForecastCurve, curveId.BaseDate, extrapolationPermitted,
                                                                      InterpolationMethod, Tolerance);
            IsBootstrapSuccessful = true;
            InitialiseVolatilities(curveId.BaseDate, BootstrapResults.Results);
            QuoteUnits       = EnumHelper.Parse <QuoteUnitsEnum>(properties.GetValue(CurveProp.QuoteUnits, QuoteUnitsEnum.LogNormalVolatility.ToString()));
            MeasureType      = EnumHelper.Parse <MeasureTypesEnum>(properties.GetValue(CurveProp.MeasureType, MeasureTypesEnum.Volatility.ToString()));
            StrikeQuoteUnits = EnumHelper.Parse <StrikeQuoteUnitsEnum>(properties.GetValue(CurveProp.StrikeQuoteUnits, StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString()));
            //If there is a strike specified for the curve, use it!
            IsATMBootstrap = true;
            Strike         = curveId.Strike;
            if (Strike != null)
            {
                ValidateStrike((decimal)Strike);
                IsFixedStrikeBootstrap = true;
                IsATMBootstrap         = false;
            }
            if (StrikeQuoteUnits == StrikeQuoteUnitsEnum.ATMFlatMoneyness || StrikeQuoteUnits == StrikeQuoteUnitsEnum.ATMMoneyness)
            {
                IsFixedStrikeBootstrap = false;
            }
            //The points use tenor strings for expiry.
            var termTenors = new List <String>();

            foreach (var daysDifference in VolatilityOffsets)
            {
                termTenors.Add(daysDifference + "D");
            }
            volCurve.point = ProcessRawSurface(termTenors, Strike, VolatilityValues, curveId.StrikeQuoteUnits, curveId.UnderlyingAssetReference);
            // Interpolate the curve based on the respective curve interpolation
            SetInterpolator(volCurve, curveId.Algorithm, curveId.PricingStructureType);
            CreatePricingStructure(curveId, volCurve, instrumentData);
        }
Exemple #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FXCurveTerms"/> class.
        /// </summary>
        /// <param name="terms">The terms.</param>
        public FXCurveTerms(IDictionary <string, object> terms)
        {
            Terms = terms;
            var nvs = new NamedValueSet();

            nvs.Add(terms);
            Market                   = nvs.GetValue <string>("Market", null);
            Currency1                = nvs.GetValue <string>("Currency1", null);
            Currency2                = nvs.GetValue <string>("Currency2", null);
            ReferenceKey             = BuildKey();
            CurveReferenceIdentifier = null;
        }
Exemple #16
0
        /// <summary>
        /// Create a series of Volatility engines from a raw volatility grid
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="properties">The properties of the engine, including the reference handle to access this engine collection</param>
        /// <param name="instruments">An array of instrument types.</param>
        /// <param name="rawVolatilityGrid">The raw grid used to build the engines. Assume that all volatility and strike values are 100x true</param>
        /// <returns>The engine handle or an error message</returns>
        public string CreateATMVolatilityCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties,
                                               String[] instruments, Decimal[] rawVolatilityGrid)
        {
            var volatilityCheck = CheckVolatilties(rawVolatilityGrid);

            if (volatilityCheck != null)
            {
                throw new ArgumentException(volatilityCheck);
            }
            var id            = properties.GetString(CurveProp.EngineHandle, true);
            var baseDate      = properties.GetValue <DateTime>(CurveProp.BaseDate, true);
            var valuationDate = properties.GetValue(CurveProp.ValuationDate, DateTime.MinValue);

            if (valuationDate == DateTime.MinValue)
            {
                properties.Set(CurveProp.ValuationDate, baseDate);
            }
            var strikeQuoteUnits = properties.GetString(CurveProp.StrikeQuoteUnits, null);

            if (strikeQuoteUnits == null)
            {
                properties.Set(CurveProp.StrikeQuoteUnits, StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString());
            }
            var measureType = properties.GetString(CurveProp.MeasureType, null);

            if (measureType == null)
            {
                properties.Set(CurveProp.MeasureType, MeasureTypesEnum.Volatility.ToString());
            }
            var quoteUnits = properties.GetString(CurveProp.QuoteUnits, null);

            if (quoteUnits == null)
            {
                properties.Set(CurveProp.QuoteUnits, QuoteUnitsEnum.LogNormalVolatility.ToString());
            }
            var algorithm = properties.GetString(CurveProp.Algorithm, null);

            if (algorithm == null)
            {
                properties.Set(CurveProp.Algorithm, "Default");
            }
            // Create the engines and either add to, or overwrite the existing, collection
            if (_volCurveEngines.ContainsKey(id))
            {
                _volCurveEngines[id] = VolatilityCurveCreate(logger, cache, nameSpace, properties, instruments, rawVolatilityGrid);
            }
            else
            {
                _volCurveEngines.Add(id, VolatilityCurveCreate(logger, cache, nameSpace, properties, instruments, rawVolatilityGrid));
            }
            return(id);
        }
Exemple #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericVolatilityCurve"/> class.
        /// This constructor is used to clone perturbed copies of a base curve.
        /// </summary>
        /// <param name="priceableRateOptionAssets">The priceableRateAssets.</param>
        /// <param name="pricingStructureAlgorithmsHolder">The pricingStructureAlgorithmsHolder.</param>
        /// <param name="curveProperties">The Curve Properties.</param>
        /// <param name="discountCurve">The discount rate curve.</param>
        /// <param name="forecastCurve">The forecast rate curve.</param>
        public GenericVolatilityCurve(NamedValueSet curveProperties, List <IPriceableOptionAssetController> priceableRateOptionAssets,
                                      IRateCurve discountCurve, IRateCurve forecastCurve, PricingStructureAlgorithmsHolder pricingStructureAlgorithmsHolder)
            : base(curveProperties, pricingStructureAlgorithmsHolder)
        {
            DiscountCurve = discountCurve;
            ForecastCurve = forecastCurve;
            var curveId  = GetCurveId();
            var volCurve = SetConfigurationData();

            Handle           = curveProperties.GetString(CurveProp.EngineHandle, null);
            BootstrapResults = new VolCurveBootstrapResults();
            //Set the underlying asset information.
            var instrument = curveProperties.GetString(CurveProp.Instrument, true);

            Asset = new AnyAssetReference {
                href = instrument
            };
            UnderlyingAssetDetails   = CreateUnderlyingAssetWithProperties();
            PriceableOptionAssets    = priceableRateOptionAssets;
            BootstrapResults.Results = VolatilityCurveBootstrapper.Bootstrap(PriceableOptionAssets);
            IsBootstrapSuccessful    = true;
            InitialiseVolatilities(curveId.BaseDate, BootstrapResults.Results);
            QuoteUnits       = EnumHelper.Parse <QuoteUnitsEnum>(curveProperties.GetValue(CurveProp.QuoteUnits, QuoteUnitsEnum.LogNormalVolatility.ToString()));
            MeasureType      = EnumHelper.Parse <MeasureTypesEnum>(curveProperties.GetValue(CurveProp.MeasureType, MeasureTypesEnum.Volatility.ToString()));
            StrikeQuoteUnits = EnumHelper.Parse <StrikeQuoteUnitsEnum>(curveProperties.GetValue(CurveProp.StrikeQuoteUnits, StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString()));
            //If there is a strike specified for the curve, use it!
            Strike = curveId.Strike;
            if (Strike != null)
            {
                ValidateStrike((decimal)Strike);
                IsFixedStrikeBootstrap = true;
            }
            if (StrikeQuoteUnits == StrikeQuoteUnitsEnum.ATMFlatMoneyness || StrikeQuoteUnits == StrikeQuoteUnitsEnum.ATMMoneyness)
            {
                IsATMBootstrap         = true;
                IsFixedStrikeBootstrap = false;
            }
            //The points use tenor strings for expiry.
            var termTenors = new List <String>();

            foreach (var daysDifference in VolatilityOffsets)
            {
                termTenors.Add(daysDifference + "D");
            }
            volCurve.point = ProcessRawSurface(termTenors, Strike, VolatilityValues, curveId.StrikeQuoteUnits, curveId.UnderlyingAssetReference);
            // Interpolate the curve based on the respective curve interpolation
            SetInterpolator(volCurve, curveId.Algorithm, curveId.PricingStructureType);
            CreatePricingStructure(curveId, volCurve, PriceableOptionAssets);
        }
        private static TimeSpan GetLifetime(NamedValueSet publishProperties)
        {
            int expiryInterval = publishProperties.GetValue("ExpiryIntervalInMins", 60);
            var lifetime       = new TimeSpan(0, expiryInterval, 0);

            return(lifetime);
        }
Exemple #19
0
 private void SetProperties(NamedValueSet properties)
 {
     try
     {
         var baseDate = PropertyHelper.ExtractDateTimeProperty(CurveProp.BaseDate, properties);
         if (baseDate != null)
         {
             BaseDate = (DateTime)baseDate;
         }
         Id = PropertyHelper.ExtractStringProperty("AssetId", properties);
         //AssetType property - make sure it exists.
         var assetType = PropertyHelper.ExtractStringProperty("AssetType", properties);
         if (assetType != null)
         {
             AssetType = EnumHelper.Parse <AssetTypesEnum>(assetType);
         }
         Coupon           = PropertyHelper.ExtractDecimalProperty("Coupon", properties);
         MaturityDate     = PropertyHelper.ExtractDateTimeProperty("Maturity", properties);
         UniqueIdentifier = properties.GetValue <string>(CurveProp.UniqueIdentifier) ?? BuildUniqueId();
         PropertyHelper.Update(Properties, CurveProp.UniqueIdentifier, UniqueIdentifier);
     }
     catch
     {
         throw new Exception("Invalid asset id.");
     }
 }
Exemple #20
0
        private void AddPricingStructure(PricingStructure ps, PricingStructureValuation psv, NamedValueSet nvs)
        {
            var triple     = new Triplet <PricingStructure, PricingStructureValuation, NamedValueSet>(ps, psv, nvs);
            var identifier = nvs.GetValue <string>("UniqueIdentifier");

            _curves.Add(identifier, triple);
        }
Exemple #21
0
        //Backs out the implied quotes for the asset provided and adds the spread to it.
        //
        protected static QuotedAssetSet MappedQuotedAssetSet(ILogger logger, ICoreCache cache,
                                                             string nameSpace, IInterpolatedSpace referenceCurve, QuotedAssetSet spreadValues,
                                                             NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
        {
            var index    = 0;
            var baseDate = properties.GetValue <DateTime>(CurveProp.BaseDate);

            //Find the backed out implied quote for each asset.
            //
            foreach (var asset in spreadValues.instrumentSet.Items)
            {
                NamedValueSet namedValueSet = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, asset.id, baseDate);
                var           quote         = spreadValues.assetQuote[index];
                //Get the implied quote to use as the input market quote. Make sure it is rate controller.
                var priceableAsset = (PriceableRateAssetController)PriceableAssetFactory.Create(logger, cache, nameSpace, quote, namedValueSet, fixingCalendar, rollCalendar);
                var value          = priceableAsset.CalculateImpliedQuote(referenceCurve);
                //Replace the market quote in the bav and remove the spread.
                var quotes       = new List <BasicQuotation>(quote.quote);
                var impliedQuote = MarketQuoteHelper.ReplaceQuotationByMeasureType("MarketQuote", quotes, value);
                var marketQuote  = new List <BasicQuotation>(impliedQuote);
                spreadValues.assetQuote[index].quote = MarketQuoteHelper.MarketQuoteRemoveSpreadAndNormalise(marketQuote);
                index++;
            }
            return(spreadValues);
        }
        private static WorkflowOutput <HandlerResponse> RunStressGenerator(NamedValueSet properties)
        {
            var          wfGenerateStressCurve = new WFGenerateStressedCurve();
            IWorkContext context = new WorkContext(Engine.Logger, Engine.Cache, "UnitTest");

            wfGenerateStressCurve.Initialise(context);
            var request = new StressedCurveGenRequest
            {
                RequestId   = Guid.NewGuid().ToString(),
                RequesterId = new UserIdentity
                {
                    Name        = Engine.Cache.ClientInfo.Name,
                    DisplayName = "Unit Test Agent"
                },
                BaseDate      = properties.GetValue <DateTime>("BaseDate", true),
                CurveSelector = new[] { new CurveSelection
                                        {
                                            NameSpace  = properties.GetString("NameSpace", true),
                                            CurveName  = properties.GetString("CurveName", true),
                                            CurveType  = properties.GetString("PricingStructureType", true),
                                            MarketName = properties.GetString("MarketName", true)
                                        } }
            };

            return(wfGenerateStressCurve.Execute(request));
        }
Exemple #23
0
        /// <summary>
        /// Helper method used by the Caplet Bootstrap Engine to compute the
        /// discount factor from the Calculation Date to some date beyond
        /// or equal to the Calculation Date.
        /// </summary>
        /// <param name="capletBootstrapSettings">The Caplet Bootstrap
        /// settings object that stores the Calculation Date.</param>
        /// <param name="offsets">Array of offsets (number of days) from
        /// the Calculation Date.</param>
        /// <param name="discountFactors">Array of discount factors.</param>
        /// <param name="endDate">Target date.
        /// Precondition: End date cannot be before the Calculation Date.</param>
        /// <returns>Discount factor.</returns>
        public static decimal ComputeDiscountFactor
            (NamedValueSet capletBootstrapSettings,
            double[] offsets,
            double[] discountFactors,
            DateTime endDate)
        {
            // Compute and validate the offset from the start date to the
            // end date.
            var calcDate = capletBootstrapSettings.GetValue("Calculation Date", DateTime.MinValue);
            var timeDiff =
                endDate - calcDate;
            var          offset       = (double)timeDiff.Days;
            const string errorMessage =
                "End date for a discount factor cannot be before Calculation Date";

            DataQualityValidator.ValidateMinimum
                (offset, 0.0d, errorMessage, true);
            // Compute the discount factor by interpolation at the target.
            var discountFactor = 1.0m;

            if (offset > 0.0d)
            {
                var interpObj =
                    new Analytics.Interpolations.LinearInterpolation();
                interpObj.Initialize(offsets, discountFactors);
                discountFactor = (decimal)interpObj.ValueAt(offset, true);
            }
            return(discountFactor);
        }
Exemple #24
0
        private void Initialize(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, IRateCurve baseCurve, IRateCurve quoteCurve,
                                string[] instruments, decimal[] values, FxCurve fxCurve, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
        {
            var curveId = (RateCurveIdentifier)PricingStructureIdentifier;

            BaseCurve  = baseCurve;
            QuoteCurve = quoteCurve;
            //Holder = new PricingStructureAlgorithmsHolder(logger, cache, curveId.PricingStructureType, curveId.Algorithm);
            Initialize(properties, Holder);
            var currency = properties.GetValue <string>(CurveProp.Currency1);

            if (fxCurve != null && baseCurve == null)
            {
                var holder = new GenericRateCurveAlgorithmHolder(logger, cache, nameSpace);
                // Create discount factors, without any input points
                RateCurve basisAdjustedDiscountCurve = CreateBasisAdjustedDiscountCurve(fxCurve, quoteCurve, currency, curveId.BaseDate, holder);
                TermCurve discountCurve = ((YieldCurveValuation)basisAdjustedDiscountCurve.PricingStructureValuation).discountFactorCurve;
                CreateYieldCurve();
                GetYieldCurveValuation().discountFactorCurve = discountCurve;
                SetInterpolator(discountCurve, curveId.Algorithm, PricingStructureTypeEnum.RateSpreadCurve);
                // Put FX curve into inputs
                var assetQuotes = new List <BasicAssetValuation>();
                BasicAssetValuation[] fxAssetQuotes = ((FxCurveValuation)fxCurve.GetFpMLData().Second).spotRate.assetQuote;
                foreach (BasicAssetValuation assetQuote in fxAssetQuotes)
                {
                    BasicAssetValuation clonedAssetQuote = XmlSerializerHelper.Clone(assetQuote);
                    clonedAssetQuote.definitionRef = FxCurveName;
                    assetQuotes.Add(clonedAssetQuote);
                }
                AddQuoteCurveInputs(assetQuotes);
                ((YieldCurveValuation)PricingStructureValuation).inputs = new QuotedAssetSet {
                    assetQuote = assetQuotes.ToArray()
                };
            }
            else
            {
                List <IPriceableRateAssetController> swaps
                    = PriceableAssetFactory.CreatePriceableRateAssets(logger, cache, nameSpace, curveId.BaseDate, instruments, values, null, fixingCalendar, rollCalendar);
                if (fxCurve == null)
                {
                    // only use the input swaps
                    PriceableRateAssets = swaps;
                }
                else
                {
                    var holder = new GenericRateCurveAlgorithmHolder(logger, cache, nameSpace);
                    // Add synthetic input points
                    RateCurve basisAdjustedDiscountCurve = CreateBasisAdjustedDiscountCurve(fxCurve, quoteCurve, currency, curveId.BaseDate, holder);
                    //TODO Add some extra short end point: 1D and 1W
                    string[] syntheticSwapPoints = { "1M", "2M", "3M", "6M", "9M" };
                    PriceableRateAssets = CreateSyntheticSwaps(logger, cache, nameSpace, BaseCurve, basisAdjustedDiscountCurve,
                                                               currency, curveId.BaseDate, syntheticSwapPoints, fixingCalendar, rollCalendar);
                    PriceableRateAssets.AddRange(swaps);
                }
                // bootstrap to create the discount factors
                PriceableRateAssets = PriceableRateAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
                Bootstrap((YieldCurveValuation)GetFpMLData().Second);
            }
        }
        public string PublishLpmCapFloorVolMatrix(object[][] structurePropertiesRange, object[][] publishPropertiesRange, object[][] valuesRange, object[][] rateCurveFiltersRange)
        {
            // Translate into useful objects
            NamedValueSet structureProperties = structurePropertiesRange.ToNamedValueSet();

            object[,] values = valuesRange.ConvertArrayToMatrix();
            string[] columnNames = Array.ConvertAll(values.GetRow(0), Convert.ToString);
            object[] ppd         = values.GetColumn(1);
            for (int index = 0; index < ppd.Length; index++)
            {
                ppd[index] = ppd[index] is Double?Convert.ToDouble(ppd[index]) / 100 : ppd[index];
            }
            values.SetColumn(1, ppd);
            object[][] data = values.GetRows(1, values.RowCount());
            // Create matrix
            var baseDate = structureProperties.GetValue <DateTime>(CurveProp.BaseDate, false);

            if (baseDate == DateTime.MinValue)
            {
                baseDate = structureProperties.GetValue <DateTime>(CurveProp.BuildDateTime, false).Date;
                if (baseDate == DateTime.MinValue)
                {
                    baseDate = DateTime.Today;
                }
            }
            string sourceName = structureProperties.GetString("Source", true);
            string currency   = structureProperties.GetString(CurveProp.Currency1, true);
            string marketName = structureProperties.GetString(CurveProp.MarketAndDate, true);
            string indexName  = structureProperties.GetString(CurveProp.IndexName, true);
            int    year       = baseDate.Year;
            int    weekOfYear = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(baseDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            string id         = $"LPMCapFloorCurve.{currency}.{baseDate:yyyy-MM-dd}";
            var    matrix     = new CapFloorATMMatrix(columnNames, data, structurePropertiesRange, baseDate, id);
            // Load underlying curve
            Market market = GetCurve(Logger.Target, Cache, NameSpace, rateCurveFiltersRange);
            // Create the capFloors and properties
            Market capFloors = LPMCapFloorCurve.ProcessCapFloor(Logger.Target, Cache, NameSpace, market, matrix);
            string newId     = $"{marketName}.{indexName}.CapFloor.{currency}.{sourceName}.{year}.Week{weekOfYear}";
            string name      = $"CapFloor-{currency}-{sourceName}-{baseDate:dd/MM/yyyy}";

            structureProperties.Set("Identifier", newId);
            structureProperties.Set("Name", name);
            // Save
            Publish(capFloors, "Market." + newId, structureProperties, publishPropertiesRange);
            return(newId);
        }
Exemple #26
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static PriceQuoteUnits ExtractStrikeQuoteUnits(NamedValueSet properties)
        {
            string value = properties.GetValue("StrikeQuoteUnits", "ATMFlatMoneyness");

            return(new PriceQuoteUnits {
                Value = value
            });
        }
        ///// <summary>
        /////  An id for a ratecurve.
        ///// </summary>
        ///// <param name="sourceSystem">The source system.</param>
        ///// <param name="baseParty">The base Party.</param>
        ///// <param name="reportId">The report Id.</param>
        ///// <param name="calculationDateTime">The calculationDateTime</param>
        //public ValuationReportIdentifier(String sourceSystem, string baseParty, string reportId, DateTime calculationDateTime)
        //{
        //    SetProperties(sourceSystem, baseParty, reportId, calculationDateTime);
        //}

        private void SetProperties(NamedValueSet properties)
        {
            try
            {
                DataType            = "ValuationReport";
                SourceSystem        = PropertyHelper.ExtractSourceSystem(properties);
                Id                  = properties.GetValue <string>(ValueProp.PortfolioId, false);
                TradeId             = properties.GetValue <string>(TradeProp.TradeId, true);
                MarketName          = properties.GetValue <string>(ValueProp.MarketName, false);
                Domain              = SourceSystem + '.' + DataType;
                CalculationDateTime = properties.GetValue <DateTime>("CalculationDateTime");
                BaseParty           = properties.GetValue <string>(ValueProp.BaseParty);
                UniqueIdentifier    = BuildUniqueId();
                if (properties.GetValue <string>(CurveProp.UniqueIdentifier) != null)
                {
                    UniqueIdentifier = properties.GetValue <string>(CurveProp.UniqueIdentifier);
                }
                PropertyHelper.Update(Properties, CurveProp.UniqueIdentifier, UniqueIdentifier);
                PropertyHelper.Update(Properties, "Domain", Domain);
            }
            catch
            {
                throw new System.Exception("Invalid tradeid.");
            }
        }
 public override object[,] DoReport(Product product, NamedValueSet properties)
 {
     if (product is FutureTransaction futureTransaction)
     {
         var party1 = properties.GetValue <string>(TradeProp.Party1, true);
         var party2 = properties.GetValue <string>(TradeProp.Party2, true);
         var result = new object[10, 2];
         result[0, 0] = "buyerPartyReference";
         result[1, 0] = "sellerPartyReference";
         result[2, 0] = "numberOfUnits";
         result[3, 0] = "currency";
         result[4, 0] = "amount";
         result[5, 0] = "maturity";
         result[6, 0] = "id";
         result[7, 0] = "paryt1";
         result[8, 0] = "party2";
         result[9, 0] = "exchangeId";
         var temp = futureTransaction.future;
         result[0, 1] = futureTransaction.buyerPartyReference.href;
         result[1, 1] = futureTransaction.sellerPartyReference.href;
         result[2, 1] = futureTransaction.numberOfUnits;
         result[3, 1] = futureTransaction.unitPrice.currency.Value;
         result[4, 1] = 0.0m;
         if (futureTransaction.unitPrice.amountSpecified)
         {
             result[4, 1] = futureTransaction.unitPrice.amount;
         }
         result[5, 1] = DateTime.MinValue;
         if (temp.maturitySpecified)
         {
             result[5, 1] = temp.maturity;
         }
         result[6, 1] = temp.id;
         result[7, 1] = party1;
         result[8, 1] = party2;
         result[9, 1] = "Unknown";
         if (futureTransaction.future.exchangeId != null)
         {
             result[9, 1] = futureTransaction.future.exchangeId.Value;
         }
         return(result);
     }
     return(null);
 }
Exemple #29
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static PricingStructureTypeEnum ExtractPricingStructureType(NamedValueSet properties)
        {
            var pricingStructureType = properties.GetValue <string>(CurveProp.PricingStructureType, true);

            if (!EnumHelper.TryParse(pricingStructureType, true, out PricingStructureTypeEnum pricingStructureTypeEnum))
            {
                throw new ArgumentException($"PricingStructureType '{pricingStructureType}' not recognized.");
            }
            return(pricingStructureTypeEnum);
        }
Exemple #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VolatilitySurfaceTerms"/> class.
        /// </summary>
        /// <param name="terms">The terms.</param>
        public VolatilitySurfaceTerms(IDictionary <string, object> terms)
        {
            Terms = terms;
            var nvs = new NamedValueSet();

            nvs.Add(terms);
            if (nvs.Get(CurveProp.Market, false) != null)
            {
                Market = nvs.GetValue <string>(CurveProp.Market, null);
            }
            else if (nvs.Get("Market", false) != null)
            {
                Market = nvs.GetValue <string>("Market", null);
            }
            Currency     = nvs.GetValue <string>(CurveProp.Currency1, null);
            BaseDate     = nvs.GetValue(CurveProp.BaseDate, DateTime.MinValue);
            ReferenceKey = BuildKey();
            SurfaceReferenceIdentifier = null;
        }