コード例 #1
0
        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));
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: FraPricer.cs プロジェクト: zhangz/Highlander.Net
        public string CreateFraTradeValuation(ILogger logger, ICoreCache cache,
                                              IRateCurve forwardCurve, IRateCurve discountCurve,
                                              IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                                              FraInputRange fraInputRange, string[] metrics,
                                              NamedValueSet properties, String nameSpace)
        {
            //get the balues reqired from the property bag.
            var valuationId       = new ValuationReportIdentifier(properties);
            var baseParty         = properties.GetString("BaseParty", true);
            var reportingCurrency = properties.GetString("ReportingCurrency", true);

            properties.Set("Function", "ValuationReport");
            properties.Set("Domain", "Orion.ValuationReport");
            //TODO add other properties
            //var fra = Cache.GetTrade(fraId);
            var fra = ProductFactory.GetFpMLFra(fraInputRange);
            //Get the curves and store.
            var marketFactory = new MarketFactory();
            var uniqueCurves  = new List <IRateCurve>();
            //var forwardCurve = (RateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.ForwardCurveId);
            //var discountCurve = (RateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.DiscountingCurveId);
            var market        = CreateMarket(discountCurve, forwardCurve);
            var agreement     = new FraPricer(logger, cache, null, null, fra, nameSpace);
            var modelData     = CreateInstrumentModelData(metrics, fraInputRange.ValuationDate, market, reportingCurrency);
            var asetValuation = agreement.Calculate(modelData);

            //  Add forward yield curve to the market environment ...
            //
            //var forwardCurve = (IRateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.ForwardCurveId);
            uniqueCurves.Add(forwardCurve);
            //  ... if discount curve is not the same as forward curve - add a discount curve too.
            //
            //if (fraInputRange.ForwardCurveId != fraInputRange.DiscountingCurveId)
            //{
            //    var discountingCurve = (IRateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.DiscountingCurveId);
            //    uniqueCurves.Add(discountingCurve);
            //}
            //TODO Add the FX curve if the reporting currency is different.
            foreach (var rateCurve in uniqueCurves)
            {
                // Add all unique curves into market
                //
                Pair <PricingStructure, PricingStructureValuation> pair = rateCurve.GetFpMLData();
                marketFactory.AddPricingStructure(pair);
            }
            var valuation = new Valuation();

            //  create ValuationReport and add it to in-memory collection.
            //
            valuation.CreateFraValuationReport(cache, nameSpace, valuationId.UniqueIdentifier, baseParty, fra, marketFactory.Create(), asetValuation, properties);
            return(valuationId.UniqueIdentifier);
        }
コード例 #6
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);
        }
コード例 #7
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static string ExtractCurveName(NamedValueSet properties)
        {
            var    dictionaryKeys = properties.ToDictionary();
            object value;

            if (dictionaryKeys.TryGetValue(CurveProp.CurveName, out value))
            {
                return(value.ToString());
            }
            if (dictionaryKeys.TryGetValue("PricingStructureName", out value))
            {
                return(value.ToString());
            }
            string currency   = ExtractCurrency(properties);
            string indexTenor = properties.GetString(CurveProp.IndexTenor, false);
            string index      = ExtractIndex(properties);

            if (!string.IsNullOrEmpty(currency) && !string.IsNullOrEmpty(index))
            {
                if (!string.IsNullOrEmpty(indexTenor))
                {
                    return($"{currency}-{index}-{indexTenor}");
                }
                string instrument = ExtractInstrument(properties);
                if (!string.IsNullOrEmpty(instrument))
                {
                    return($"{currency}-{index}-{instrument}");
                }
                return($"{currency}-{index}");
            }
            return(null);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        /// <summary>
        /// A helper to extract properties from anamed value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static string ExtractCapFrequency(NamedValueSet properties)
        {
            // 3M by default
            string value = properties.GetString("CapFrequency", "3M");

            return(value);
        }
コード例 #10
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static QuotedCurrencyPair ExtractQuotedCurrencyPair(NamedValueSet properties)
        {
            string currency      = ExtractCurrency(properties);
            string quoteCurrency = ExtractCurrency2(properties);

            if (string.IsNullOrEmpty(currency) || string.IsNullOrEmpty(quoteCurrency))
            {
                string currencyPair = properties.GetString(CurveProp.CurrencyPair, false);
                if (!string.IsNullOrEmpty(currencyPair))
                {
                    if (!GetCurrencyPair(currencyPair, out currency, out quoteCurrency))
                    {
                        throw new ArgumentException("Currency pair is invalid, it should be of the type XXX-YYY");
                    }
                }
                else
                {
                    currencyPair = properties.GetString("CurveName", false);
                    if (!string.IsNullOrEmpty(currencyPair))
                    {
                        if (!GetCurrencyPair(currencyPair, out currency, out quoteCurrency))
                        {
                            throw new ArgumentException("CurveName is invalid, it should be of the type XXX-YYY");
                        }
                    }
                    else
                    {
                        string id = properties.GetString("Identifier", false);
                        if (!string.IsNullOrEmpty(currencyPair) && id.Split('.').Length < 2)
                        {
                            currencyPair = id.Split('.').Last();
                            if (!GetCurrencyPair(currencyPair, out currency, out quoteCurrency))
                            {
                                throw new ArgumentException("Identifier is invalid, it should be of the type XXX-YYY");
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Mandatory field CurrencyPair or QuoteCurrency, not set.");
                        }
                    }
                }
            }
            QuoteBasisEnum quoteBasis = ExtractQuoteBasis(properties);

            return(QuotedCurrencyPair.Create(currency, quoteCurrency, quoteBasis));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        /// <summary>
        /// Create a surface from an FpML
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The nameSpace</param>
        /// <param name="fpmlData">The data.</param>
        /// <param name="properties">The properties.</param>
        public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties)
            : base(logger, cache, nameSpace, fpmlData, properties)
        {
            var assetClass = properties.GetString(CurveProp.AssetClass, true);
            var type       = EnumHelper.Parse <AssetClass>(assetClass);

            PricingStructureData = new PricingStructureData(CurveType.Parent, type);
        }
コード例 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace"></param>
        /// <param name="properties"></param>
        /// <param name="expiries"></param>
        /// <param name="vols"></param>
        /// <param name="inputInstruments"></param>
        /// <param name="inputSwapRates"></param>
        /// <param name="blackVolatilities"></param>
        public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, DateTime[] expiries, double[] vols,
                                     string[] inputInstruments, double[] inputSwapRates, double[] blackVolatilities)
            : base(logger, cache, nameSpace, properties, expiries, vols, inputInstruments, inputSwapRates, blackVolatilities)
        {
            var assetClass = properties.GetString(CurveProp.AssetClass, true);
            var type       = EnumHelper.Parse <AssetClass>(assetClass);

            PricingStructureData = new PricingStructureData(CurveType.Parent, type);
        }
コード例 #14
0
        /// <summary>
        /// Takes a range of volatilities, an array of tenor expiries and an
        /// array of strikes to create a VolatilitySurface
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="instrumentIds">A set of valid instrumentIds</param>
        /// <param name="expiryTenors">the expiry tenors.</param>
        /// <param name="strikes">The strikes.</param>
        /// <param name="values">The values.</param>
        /// <param name="nameSpace">The nameSpace</param>
        /// <param name="properties">The properties.</param>
        public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] instrumentIds,
                                     String[] expiryTenors, Double[] strikes, Double[,] values)
            : base(logger, cache, nameSpace, properties, expiryTenors, strikes, MapFromRatePremiums(instrumentIds, values))//TODO map into the volsurface.
        {
            var assetClass = properties.GetString(CurveProp.AssetClass, true);
            var type       = EnumHelper.Parse <AssetClass>(assetClass);

            PricingStructureData = new PricingStructureData(CurveType.Parent, type);
        }
コード例 #15
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static string ExtractTradeIdentifier(NamedValueSet properties)
        {
            string identifier = properties.GetString(TradeProp.TradeId, false);

            if (string.IsNullOrEmpty(identifier))
            {
                identifier = "Unknown Trade Identifier.";
            }
            return(identifier);
        }
コード例 #16
0
 /// <summary>
 /// PreCondition, check the initialCurvePorperties
 /// </summary>
 /// <param name="initialCurvePorperties"></param>
 /// <param name="numOfShockedInsturments"></param>
 private void SetPropertiesOfShockedCurves(NamedValueSet initialCurvePorperties, int numOfShockedInsturments)
 {
     ShockedCurvesProperties = new List <NamedValueSet>();
     for (int i = 0; i < numOfShockedInsturments; ++i)
     {
         NamedValueSet newProperties = initialCurvePorperties.Clone();
         string        curveName     = initialCurvePorperties.GetString(CurveProp.CurveName, false);
         if (!string.IsNullOrEmpty(curveName))
         {
             newProperties.Set(CurveProp.CurveName, curveName + "ShockedCurve-" + i);
         }
         string id = initialCurvePorperties.GetString("Identifier", false);
         if (!string.IsNullOrEmpty(id))
         {
             newProperties.Set(CurveProp.CurveName, id + "ShockedCurve-" + i);
         }
         ShockedCurvesProperties.Add(newProperties);
     }
 }
コード例 #17
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);
        }
コード例 #18
0
        public string PublishLpmSwaptionVolMatrix(object[][] structurePropertiesRange, object[][] publishPropertiesRange, object[][] valuesRange, object[][] rateCurveFiltersRange)
        {
            NamedValueSet structureProperties = structurePropertiesRange.ToNamedValueSet();

            object[,] values = valuesRange.ConvertArrayToMatrix();
            string[]   tenors      = Array.ConvertAll(values.GetRow(0).Skip(1).ToArray(), Convert.ToString);
            string[]   expiries    = Array.ConvertAll(values.GetColumn(0).Skip(1).ToArray(), Convert.ToString);
            object[][] dataObjects = values.GetRows(1, values.RowCount(), 1, values.ColumnCount());
            object[][] data        = dataObjects.Select(a => a.Select(b => b).ToArray()).ToArray();
            // Setup base values needed to build
            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         = $"LPMSwaptionCurve.{currency}.{baseDate:yyyy-MM-dd}";
            var    ppdGrid    = new SwaptionPPDGrid(expiries, tenors, data);
            // Load underlying curve
            Market market = GetCurve(Logger.Target, Cache, NameSpace, rateCurveFiltersRange);
            Market matrix = LPMSwaptionCurve.ProcessSwaption(Logger.Target, Cache, market, ppdGrid, id, NameSpace);
            string newId  = $"{marketName}.{indexName}.Swaption.{currency}.{sourceName}.{year}.Week{weekOfYear}";
            string name   = $"Swaption-{currency}-{sourceName}-{baseDate:dd/MM/yyyy}";

            structureProperties.Set("Identifier", newId);
            structureProperties.Set("Name", name);
            // Save
            Publish(matrix, "Market." + newId, structureProperties, publishPropertiesRange);
            return(newId);
        }
コード例 #19
0
        /// <summary>
        /// Clones the curve.
        /// </summary>
        /// <returns></returns>
        public object Clone()//THis does not instantiate any priceable assets or bootstrap the curve. This means no evaluation of component assets.
        {
            //Clone the properties and set values.
            //
            NamedValueSet properties  = GetProperties().Clone();
            string        baseCurveId = properties.GetString(CurveProp.UniqueIdentifier, true);
            string        id          = baseCurveId + ".Clone";

            properties.Set(CurveProp.UniqueIdentifier, id);
            //Clone the curve data.
            //
            Pair <PricingStructure, PricingStructureValuation> fpml = GetFpMLData();
            var fxCurve = new FxCurve(null, null, null, CloneCurve(fpml, id), properties, null, null, false);

            return(fxCurve);
        }
コード例 #20
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static PriceQuoteUnits ExtractQuoteUnits(NamedValueSet properties)
        {
            string value = properties.GetString("QuoteUnits", false);
            var    priceQuoteUnitsEnum = PriceQuoteUnitsEnum.DecimalRate;

            if (!string.IsNullOrEmpty(value))
            {
                if (!PriceQuoteUnitsScheme.TryParseEnumString(value, out priceQuoteUnitsEnum))
                {
                    throw new InvalidCastException($"Cannot cast {value} to PriceQuoteUnitsEnum");
                }
            }
            return(new PriceQuoteUnits {
                Value = PriceQuoteUnitsScheme.GetEnumString(priceQuoteUnitsEnum)
            });
        }
コード例 #21
0
        ///  <summary>
        ///  Examples of values are:
        /// <Property name = "Tolerance" > 1E-10</Property >
        /// < Property name="Bootstrapper">SimpleRateBootstrapper</Property>
        /// <Property name = "BootstrapperInterpolation" > LinearRateInterpolation</Property >
        /// < Property name="CurveInterpolation">LinearInterpolation</Property>
        /// <Property name = "UnderlyingCurve" > ZeroCurve</Property >
        /// < Property name="CompoundingFrequency">Continuous</Property>
        /// <Property name = "ExtrapolationPermitted" > true </Property >
        /// < Property name="DayCounter">ACT/365.FIXED</Property>
        ///  </summary>
        ///  <returns></returns>
        public static Algorithm CreateAlgorithm(NamedValueSet algorithmProperties)
        {
            var properties = new List <Property>
            {
                new Property {
                    name = "Tolerance", Value = algorithmProperties.GetString("Tolerance", "1E-10")
                },
                new Property {
                    name = "Bootstrapper", Value = algorithmProperties.GetString("Bootstrapper", "FastBootstrapper")
                },
                new Property {
                    name = "BootstrapperInterpolation", Value = algorithmProperties.GetString("BootstrapperInterpolation", "LinearRateInterpolation")
                },
                new Property {
                    name = "CurveInterpolation", Value = algorithmProperties.GetString("CurveInterpolation", "LinearInterpolation")
                },
                new Property {
                    name = "UnderlyingCurve", Value = algorithmProperties.GetString("UnderlyingCurve", "ZeroCurve")
                },
                new Property {
                    name = "CompoundingFrequency", Value = algorithmProperties.GetString("CompoundingFrequency", "Quarterly")
                },
                new Property {
                    name = "ExtrapolationPermitted", Value = algorithmProperties.GetString("ExtrapolationPermitted", "true")
                },
                new Property {
                    name = "DayCounter", Value = algorithmProperties.GetString("DayCounter", "ACT/365.FIXED")
                },
                new Property {
                    name = "DateGenerationRule", Value = algorithmProperties.GetString("DateGenerationRule", "12")
                }
            };
            var algorithm = new Algorithm {
                Properties = properties.ToArray()
            };

            return(algorithm);
        }
コード例 #22
0
        /// <summary>
        /// Index is a short name such as Swap or LIBOR-BBA
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static string ExtractIndex(NamedValueSet properties)
        {
            string index = properties.GetString("Index", "");

            if (string.IsNullOrEmpty(index))
            {
                string indexName = ExtractIndexName(properties);
                if (!string.IsNullOrEmpty(indexName))
                {
                    List <string> parts = indexName.Split('-').ToList();
                    if (parts.Count > 1)
                    {
                        parts.RemoveAt(0);
                        index = string.Join("-", parts.ToArray());
                    }
                    else if (parts.Count == 1)
                    {
                        index = indexName;
                    }
                }
            }
            return(index);
        }
コード例 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericVolatilityCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The nameSpace</param>
        /// <param name="fpmlData">The FPML data.</param>
        /// <param name="properties">The properties for the pricing structure.</param>
        /// <param name="fixingCalendar">The fixingCalendar. If the curve is already bootstrapped, then this can be null.</param>
        /// <param name="rollCalendar">The rollCalendar. If the curve is already bootstrapped, then this can be null.</param>
        public GenericVolatilityCurve(ILogger logger, ICoreCache cache, String nameSpace,
                                      Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties,
                                      IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, fpmlData, properties, fixingCalendar, rollCalendar)
        {
            PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Rates, properties);
            var curveId = GetCurveId();

            Initialize(properties, Holder);
            //Set the underlying asset information.
            if (properties != null)
            {
                var instrument = properties.GetString("Instrument", false);
                Asset = new AnyAssetReference {
                    href = instrument
                };
            }
            if (fpmlData == null)
            {
                return;
            }
            FixingCalendar  = fixingCalendar;
            PaymentCalendar = rollCalendar;
            if (DayCounter == null)
            {
                DayCounter = DayCounterHelper.Parse("ACT/365.FIXED");
                if (Holder != null)
                {
                    string dayCountBasis = Holder.GetValue("DayCounter");
                    DayCounter = DayCounterHelper.Parse(dayCountBasis);
                }
            }
            // the curve is already built, so don't rebuild
            //Process the matrix
            SetInterpolator(((VolatilityMatrix)PricingStructureValuation).dataPoints, curveId.Algorithm, curveId.PricingStructureType);
            SetFpMLData(fpmlData, false);
        }
コード例 #24
0
        public GenericVolatilityCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, QuotedAssetSet expiryTenorsWithVols,
                                      IRateCurve discountCurve, IRateCurve forecastCurve, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, new VolatilitySurfaceIdentifier(properties), fixingCalendar, rollCalendar)
        {
            DiscountCurve = discountCurve;
            ForecastCurve = forecastCurve;
            var curveId  = GetCurveId();
            var volCurve = SetConfigurationData();

            if (properties != null)
            {
                var assetClass = properties.GetString(CurveProp.AssetClass, "Rates");
                var asset      = EnumHelper.Parse <AssetClass>(assetClass);
                PricingStructureData = new PricingStructureData(CurveType.Parent, asset, properties);
                var quoteUnits = properties.GetValue(CurveProp.StrikeQuoteUnits, StrikeQuoteUnitsEnum.ATMFlatMoneyness.ToString());
                IsFixedStrikeBootstrap = EnumHelper.Parse <StrikeQuoteUnitsEnum>(quoteUnits) == StrikeQuoteUnitsEnum.ATMFlatMoneyness;
                if (!IsFixedStrikeBootstrap)
                {
                    IsATMBootstrap = true;
                }
                //Set the underlying asset information.
                var instrument = properties.GetString(CurveProp.Instrument, true);
                Asset = new AnyAssetReference {
                    href = instrument
                };
                UnderlyingAssetDetails = CreateUnderlyingAssetWithProperties();
                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()));
                IsFixedStrikeBootstrap = true;
                IsATMBootstrap         = false;
                if (StrikeQuoteUnits == StrikeQuoteUnitsEnum.ATMFlatMoneyness || StrikeQuoteUnits == StrikeQuoteUnitsEnum.ATMMoneyness)
                {
                    IsFixedStrikeBootstrap = false;
                    IsATMBootstrap         = true;
                }
                Handle = properties.GetString(CurveProp.EngineHandle, null);
            }
            //If there is a strike specified for the curve, use it!
            Strike = curveId.Strike;
            if (Strike != null)
            {
                ValidateStrike((decimal)Strike);
                IsFixedStrikeBootstrap = true;
                IsATMBootstrap         = false;
            }
            BootstrapResults         = new VolCurveBootstrapResults();
            PriceableOptionAssets    = PriceableAssetFactory.CreatePriceableOptionAssets(logger, cache, nameSpace, curveId.BaseDate, Asset?.href, discountCurve, forecastCurve, Strike, expiryTenorsWithVols, fixingCalendar, rollCalendar);
            BootstrapResults.Results = VolatilityCurveBootstrapper.Bootstrap(PriceableOptionAssets);
            IsBootstrapSuccessful    = true;
            InitialiseVolatilities(curveId.BaseDate, BootstrapResults.Results);
            //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, expiryTenorsWithVols);
        }
コード例 #25
0
        /// <summary>
        /// Create a Sortedlist of bootstrap engines from the data matrix
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace"></param>
        /// <param name="engineHandle">The engine collection name</param>
        /// <param name="matrix">The internal data structure used in conversion</param>
        /// <param name="properties">The properties object to use</param>
        /// <returns></returns>
        private static SortedList <decimal, CapVolatilityCurve> CreateEngines(ILogger logger, ICoreCache cache,
                                                                              string nameSpace, string engineHandle, CapFloorVolatilityMatrix matrix, NamedValueSet properties)
        {
            var engines = new SortedList <decimal, CapVolatilityCurve>();

            //  Check there is a valid settings object
            if (properties == null)
            {
                return(null);
            }
            var currency = properties.GetString("Currency", true);
            var baseDate = properties.GetValue("Calculation Date", DateTime.MinValue);

            properties.Set("EngineHandle", engineHandle);
            matrix.ValuationDate = baseDate;
            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");
            var dfs = matrix.DiscountFactorsAsDoubles();
            // Check there are valid strikes
            IRateCurve discountCurve =
                new SimpleDiscountFactorCurve(baseDate, interp, true, dfs);
            //TODO
            //The quoted asset set
            var volTypes    = matrix.CapVolatilities();
            var instruments = new List <string>();
            var volatilties = new List <decimal>();

            foreach (var volType in volTypes)
            {
                string tempName;
                string tenor;
                var    type = volType.VolatilityType;
                if (type == VolatilityDataType.ETO)
                {
                    tempName = currency + "-Caplet-";
                    tenor    = volType.Expiry + "D-90D";
                }
                else
                {
                    tempName = currency + "-IRCap-";
                    tenor    = volType.Expiry + "Y";
                }
                instruments.Add(tempName + tenor);
                volatilties.Add(volType.Volatility);
            }
            var qas = AssetHelper.Parse(instruments.ToArray(), volatilties.ToArray());
            //The volatilities
            // Create a new ATM CapletBootstrap engine. The default decimal should be 0
            var engine = new CapVolatilityCurve(logger, cache, nameSpace, properties, qas, discountCurve, discountCurve,
                                                null, null);

            // Add engine
            engines.Add(0, engine);
            return(engines);
        }
コード例 #26
0
        /// <summary>
        /// A helper to extract properties from a named value set.
        /// </summary>
        /// <param name="properties">The collection of properties.</param>
        public static string ExtractAlgorithm(NamedValueSet properties)
        {
            string algorithm = properties.GetString("Algorithm", "Default");

            return(algorithm);
        }