Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CapVolatilityCurve"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 ///  <param name="nameSpace">The client namespace</param>
 /// <param name="curveIdentifier">The curveIdentifier.</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="rollCalendar">The rollCalendar.</param>
 public CapVolatilityCurve(ILogger logger, ICoreCache cache, string nameSpace,
                           VolatilitySurfaceIdentifier curveIdentifier, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
     : base(logger, cache, nameSpace, curveIdentifier, fixingCalendar, rollCalendar)
 {
     BootstrapperName            = "CapFloorBootstrapper";
     UnderlyingInterpolatedCurve = "CapVolatilityCurve";
 }
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="surfaceId">The id to use with this matrix</param>
        /// <param name="nameSpace">The namespace</param>
        /// <param name="expiryTenors">An array of expiry definitions</param>
        /// <paparam name="strike">An array of strike descriptions</paparam>
        /// <param name="strikes">The strike array.</param>
        /// <param name="volSurface">A 2d array of volatilities.
        /// This must be equal to (expiry.Count x (1 &lt;= y &lt;= term.Count) x strike.Count </param>
        /// <param name="cache">The cache</param>
        protected ExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, String[] expiryTenors, Double[] strikes, Double[,] volSurface,
                                                    VolatilitySurfaceIdentifier surfaceId)
        {
            Algorithm = surfaceId.Algorithm;
            PricingStructureIdentifier = surfaceId;
            var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));

            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            var points = ProcessRawSurface(expiryTenors, strikes, volSurface, surfaceId.StrikeQuoteUnits, surfaceId.UnderlyingAssetReference);

            PricingStructure          = CreateVolatilityRepresentation(surfaceId);
            PricingStructureValuation = CreateDataPoints(points, surfaceId);
            var expiries = new double[expiryTenors.Length];
            var index    = 0;

            foreach (var term in expiryTenors)//TODO include business day holidays and roll conventions.
            {
                expiries[index] = PeriodHelper.Parse(term).ToYearFraction();
                index++;
            }
            // Record the row/column sizes of the inputs
            _matrixRowCount = expiryTenors.Length;
            // Columns includes expiry and term (tenor) if it exists.
            _matrixColumnCount = strikes.Length + 1;
            // Generate an interpolator to use
            Interpolator = new VolSurfaceInterpolator(expiries, strikes, new Matrix(volSurface), curveInterpolationMethod, true);
        }
        /// <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>
        protected ExtendedExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties)
        {
            var surfaceId = new VolatilitySurfaceIdentifier(properties);

            Algorithm = surfaceId.Algorithm;
            PricingStructureIdentifier = surfaceId;
            var data   = (VolatilityMatrix)fpmlData.Second;
            var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            //Get the forwards from the surface.
            var adjustments = new ParametricAdjustment();

            if (data.adjustment != null)
            {
                //assume the forwards are the first parameter set.
                adjustments = data.adjustment[0];
            }
            //Creates the property collection. This should be backward compatable with V1.
            PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties);
            var xDimensionInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("xDimensionInterpolation"));
            var yDimensionInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("yDimensionInterpolation"));

            // Generate an interpolator to use
            if (adjustments?.datapoint != null)
            {
                Interpolator = new ExtendedVolatilitySurfaceInterpolator(data.dataPoints, adjustments.datapoint, xDimensionInterpolationMethod.Value, yDimensionInterpolationMethod.Value);
            }
            SetFpMLData(fpmlData);
            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            ProcessVolatilityRepresentation();
        }
Exemplo n.º 4
0
        ///// <summary>
        ///// Takes a range of volatilities, an array of tenor expiries and an
        ///// array of strikes to create a VolatilitySurface
        ///// </summary>
        ///// <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="properties">The properties.</param>
        //public EquityVolatilitySurface(NamedValueSet properties, String[] instrumentIds, String[] expiryTenors, Double[] strikes, Double[,] values)
        //    : base(properties, expiryTenors, strikes, MapFromFxPremiums(instrumentIds, values))//TODO map into the volsurface.
        //{}

        /// <summary>
        /// Takes a range of volatilities, an array of tenor expiries and an
        /// array of strikes to create a VolatilitySurface
        /// </summary>
        /// <param name="nameSpace">The nameSpace</param>
        /// <param name="expiryTenors">the expiry tenors.</param>
        /// <param name="strikes">The strikes.</param>
        /// <param name="volSurface">The vol surface.</param>
        /// <param name="surfaceId">The id.</param>
        /// <param name="logger"></param>
        /// <param name="cache">The cache.</param>
        /// <param name="forwards">The array of forwards. The first element is the spot value. Consequently, the length of this array is expiryTenors.Length + 1.</param>
        public ExtendedEquityVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, String[] expiryTenors,
                                               Double[] strikes, Double[] forwards, Double[,]
                                               volSurface,
                                               VolatilitySurfaceIdentifier surfaceId)
            : base(logger, cache, nameSpace, expiryTenors, strikes, forwards, volSurface, surfaceId)
        {
            PricingStructureData = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Equity);
        }
        /// <summary>
        /// Takes a range of volatilities, an array of tenor expiries and an
        /// array of strikes to create a VolatilitySurface
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="expiryTenors"></param>
        /// <param name="strikes"></param>
        /// <param name="volSurface"></param>
        /// <param name="surfaceId"></param>
        /// <param name="logger"></param>
        /// <param name="cache">The cache.</param>
        /// <param name="forwards">The array of forwards. The first element is the spot value. Conseuently, the length of this array is expiryTenors.Length + 1.</param>
        protected ExtendedExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, String[] expiryTenors, Double[] strikes, Double[] forwards, Double[,]
                                                            volSurface, VolatilitySurfaceIdentifier surfaceId)
        {
            Algorithm = surfaceId.Algorithm;
            PricingStructureIdentifier = surfaceId;
            //Build the parameteric adjustment set from th3e forwards.
            var parametricAdjustment = GenerateForwards(forwards);
            var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var xDimensionInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("xDimensionInterpolation"));
            var yDimensionInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("yDimensionInterpolation"));

            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            var points = ProcessRawSurface(expiryTenors, strikes, volSurface, surfaceId.StrikeQuoteUnits, surfaceId.UnderlyingAssetReference);

            PricingStructure = new VolatilityRepresentation
            {
                name     = surfaceId.Name,
                id       = surfaceId.Id,
                currency = surfaceId.Currency,
                asset    = new AnyAssetReference {
                    href = surfaceId.Instrument
                },
            };
            var datapoints = new MultiDimensionalPricingData {
                point = points
            };

            PricingStructureValuation = new VolatilityMatrix
            {
                dataPoints = datapoints
                ,
                adjustment = parametricAdjustment
                ,
                objectReference = new AnyAssetReference {
                    href = surfaceId.Instrument
                }
                ,
                baseDate = new IdentifiedDate {
                    Value = surfaceId.BaseDate
                }
                , buildDateTime          = DateTime.Now
                , buildDateTimeSpecified = true
            };
            var expiries = new double[expiryTenors.Length];
            var index    = 0;

            foreach (var term in expiryTenors)//TODO include business day holidays and roll conventions.
            {
                expiries[index] = PeriodHelper.Parse(term).ToYearFraction();
                index++;
            }
            // Record the row/column sizes of the inputs
            _matrixRowCount = expiryTenors.Length;
            // Columns includes expiry and term (tenor) if it exists.
            _matrixColumnCount = strikes.Length + 1;
            // Generate an interpolator to use
            Interpolator = new ExtendedVolatilitySurfaceInterpolator(expiries, strikes, forwards, new Matrix(volSurface), xDimensionInterpolationMethod.Value, yDimensionInterpolationMethod.Value);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create a surface from an FpML
 /// </summary>
 /// <param name="fpmlData"></param>
 /// <param name="properties"></param>
 public VolatilityCube(Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties)
     : base(fpmlData)
 {
     PricingStructureData       = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Rates);//TODO Need to set for the different underlyers.
     PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties);
     SetInterpolator();
     _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
     ProcessVolatilityRepresentation();
 }
 private static VolatilityRepresentation CreateVolatilityRepresentation(VolatilitySurfaceIdentifier surfaceId)
 {
     return(new VolatilityRepresentation
     {
         name = surfaceId.Name,
         id = surfaceId.Id,
         currency = surfaceId.Currency,
         asset = new AnyAssetReference {
             href = surfaceId.Instrument
         },
     });
 }
        /// <summary>
        /// Create a surface from an FpML
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fpmlData"></param>
        /// <param name="properties"></param>
        public ExpiryTermTenorStrikeVolatilityCube(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties)
        {
            var surfaceId = new VolatilitySurfaceIdentifier(properties);

            Algorithm = surfaceId.Algorithm;
            PricingStructureIdentifier = surfaceId;
            var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);

            Algorithm = "Linear"; //Add as a propert in the id.
            var      curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));
            var      data     = (VolatilityMatrix)fpmlData.Second;
            DateTime baseDate = data.baseDate.Value;

            Interpolator = new VolSurfaceInterpolator(data.dataPoints, curveInterpolationMethod, true, baseDate);
            SetFpMLData(fpmlData);
        }
Exemplo n.º 9
0
        public void PricingStructureIdTestWithProperties14()
        {
            NamedValueSet props = new NamedValueSet();

            props.Set(CurveProp.PricingStructureType, "CommodityCurve");
            props.Set(CurveProp.CurveName, "AUD-Dummey-SydneyDesk");
            props.Set("BuildDateTime", baseDate);
            props.Set(CurveProp.BaseDate, baseDate);
            props.Set("Algorithm", "Default");
            props.Set("Identifier", "Alex");
            props.Set("CommodityAsset", "Wheat");
            var curveId = new VolatilitySurfaceIdentifier(props);

            Debug.Print("RateCurveIdentifier : {0} BuildDateTime : {1} CurveName : {2} PricingStructureType : {3} Algorithm : {4}Currency : {5} BaseDate : {6} Source : {7} Domain : {8} UniqueId : {9} Market : {10} Instrument : {11}",
                        curveId.Id, curveId.BuildDateTime, curveId.CurveName, curveId.PricingStructureType,
                        curveId.Algorithm, curveId.Currency.Value, curveId.BaseDate, curveId.Domain, curveId.SourceSystem, curveId.UniqueIdentifier, curveId.Market, curveId.Instrument);
        }
        /// <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>
        protected ExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties)
        {
            var data = (VolatilityMatrix)fpmlData.Second;

            Algorithm = "Linear";//Add as a property in the id.
            //Creates the property collection. This should be backward compatable with V1.
            var surfaceId = new VolatilitySurfaceIdentifier(properties);

            PricingStructureIdentifier = surfaceId;
            var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));

            Interpolator = new VolSurfaceInterpolator(data.dataPoints, curveInterpolationMethod, true, PricingStructureIdentifier.BaseDate);
            SetFpmlData(fpmlData);
            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            ProcessVolatilityRepresentation();
        }
        /// <summary>
        /// Takes a range of volatilities, an array of tenor expiries and an
        /// array of strikes to create a VolatilitySurface
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="expiryTenors"></param>
        /// <param name="strikes"></param>
        /// <param name="volSurface"></param>
        /// <param name="surfaceId"></param>
        public ExpiryTermTenorStrikeVolatilityCube(ILogger logger, ICoreCache cache, String nameSpace, String[] expiryTenors, Double[] strikes, Double[,] volSurface,
                                                   VolatilitySurfaceIdentifier surfaceId)
        {
            Algorithm = surfaceId.Algorithm;
            var holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));
            var points = ProcessRawSurface(expiryTenors, strikes, volSurface);

            PricingStructure = new VolatilityRepresentation {
                name  = surfaceId.Name,
                id    = surfaceId.Id,
                asset = new AnyAssetReference {
                    href = "Unknown"
                },
            };
            var datapoints = new MultiDimensionalPricingData {
                point = points
            };

            PricingStructureValuation = new VolatilityMatrix
            {
                dataPoints        = datapoints
                , objectReference = new AnyAssetReference {
                    href = PricingStructure.id
                }
                ,
                baseDate = new IdentifiedDate {
                    Value = surfaceId.BaseDate
                }
                , buildDateTime          = DateTime.Now
                , buildDateTimeSpecified = true
            };
            var expiries = new double[expiryTenors.Length];
            var index    = 0;

            foreach (var term in expiryTenors)//TODO include business day holidays and roll conventions.
            {
                expiries[index] = PeriodHelper.Parse(term).ToYearFraction();
                index++;
            }
            // Generate an interpolator to use
            Interpolator = new VolSurfaceInterpolator(expiries, strikes, new Matrix(volSurface), curveInterpolationMethod, true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Construct a VolatilityCube from points
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="points"></param>
        public VolatilityCube(NamedValueSet properties, PricingStructurePoint[] points)
        {
            properties.Set(EnvironmentProp.Function, FunctionProp.Market.ToString());
            PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties);
            var surfaceId = (VolatilitySurfaceIdentifier)PricingStructureIdentifier;

            PricingStructureData = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Rates);//TODO Need to set for the different underlyers.
            SetInterpolator();
            foreach (PricingStructurePoint point in points)
            {
                point.underlyingAssetReference = surfaceId.UnderlyingAssetReference;
                point.quoteUnits = surfaceId.StrikeQuoteUnits;
            }
            PricingStructure = new VolatilityRepresentation
            {
                name     = surfaceId.Name,
                id       = surfaceId.Id,
                currency = surfaceId.Currency,
                asset    = new AnyAssetReference {
                    href = surfaceId.Instrument
                },
            };
            var datapoints = new MultiDimensionalPricingData {
                point = points
            };

            PricingStructureValuation = new VolatilityMatrix
            {
                dataPoints      = datapoints,
                objectReference = new AnyAssetReference {
                    href = surfaceId.Instrument
                },
                baseDate = new IdentifiedDate {
                    Value = surfaceId.BaseDate
                },
                buildDateTime          = DateTime.Now,
                buildDateTimeSpecified = true
            };
            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            ProcessVolatilityRepresentation();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Unpack a raw surface and create a VolatilitySurface
        /// The object array is assumed to be zero based when it is passed to the constructor
        /// (That is any Excel idiosyncrasies have been expunged)
        /// We'll test and modify if necessary to zero base the array
        /// </summary>
        /// <param name="rawSurface"></param>
        /// <param name="surfaceId"></param>
        /// <param name="date"></param>
        /// <param name="buildDateTime"></param>
        //       /// <param name="algorithm">The algorithm for interpolation. Not implemented yet.</param>
        public VolatilitySurface(object[,] rawSurface, VolatilitySurfaceIdentifier surfaceId, DateTime date, DateTime buildDateTime)
        {
            PricingStructureIdentifier = surfaceId;
            IDayCounter dc         = Actual365.Instance;
            var         termPoints = new List <TermPoint>
            {
                TermPointFactory.Create(1.0m, new DateTime()),
                TermPointFactory.Create(0.99m, new DateTime().AddDays(10)),
                TermPointFactory.Create(0.97m, new DateTime().AddDays(100))
            };
            var termCurve = TermCurve.Create(new DateTime(), new InterpolationMethod {
                Value = "LinearInterpolation"
            }, true, termPoints);

            Interpolator = new TermCurveInterpolator(termCurve, date, dc);//TODO need to create a surfaceinterpolator.
            var zeroedRawSurface = rawSurface.GetLowerBound(0) == 1 ? RedimensionRawSurface(rawSurface) : rawSurface;

            _algorithm = "Linear";
            // An ugly trick to find out if this is a cube or a surface
            bool isCube = !double.TryParse(zeroedRawSurface[1, 1].ToString(), out _);
            // Extract the strikes/tenors/expiries and build the surface
            var expiry     = ExtractExpiryFromRawSurface(zeroedRawSurface);
            var term       = ExtractTenorFromRawSurface(zeroedRawSurface, isCube);
            var strike     = ExtractStrikeFromRawSurface(zeroedRawSurface, isCube);
            var volatility = ExtractVolatilitiesFromRawSurface(zeroedRawSurface, isCube);

            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            var points = ProcessRawSurface(expiry, term, strike, volatility);

            PricingStructure = new VolatilityRepresentation
            {
                name  = surfaceId.Name,
                id    = surfaceId.Id,
                asset = new AnyAssetReference {
                    href = "Unknown"
                },
            };
            PricingStructureValuation
                = new VolatilityMatrix
                {
                dataPoints = new MultiDimensionalPricingData {
                    point = points
                },
                objectReference = new AnyAssetReference {
                    href = PricingStructure.id
                },
                baseDate = new IdentifiedDate {
                    Value = date
                },
                buildDateTime          = buildDateTime,
                buildDateTimeSpecified = true
                };
            // Record the row/column sizes of the inputs
            _matrixRowCount  = expiry.Length;
            _matrixRowCount *= term?.Length ?? 1;
            // Columns includes expiry and term (tenor) if it exists.
            _matrixColumnCount  = strike.Length + 1;
            _matrixColumnCount += term != null ? 1 : 0;
            // Generate an interpolator to use
            if (term == null || term.Length == 0)
            {
                _interpolation = new BilinearInterpolator();
            }
            else
            {
                _interpolation = new TrilinearInterpolator();
            }
        }
 /// <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="nameSpace">The nameSpace</param>
 /// <param name="expiryTenors"></param>
 /// <param name="tenors"></param>
 /// <param name="volSurface"></param>
 /// <param name="surfaceId"></param>
 /// <param name="baseDate"></param>
 /// <param name="algorithm">The algorithm for interpolation.</param>
 public RateATMVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, String[] expiryTenors, String[] tenors, Double[,] volSurface, VolatilitySurfaceIdentifier surfaceId, DateTime baseDate,
                                 string algorithm)
     : base(logger, cache, nameSpace, expiryTenors, tenors, volSurface, surfaceId, baseDate, algorithm)
 {
     PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Rates);
 }
        private static VolatilityMatrix CreateDataPoints(PricingStructurePoint[] points, VolatilitySurfaceIdentifier surfaceId)
        {
            var datapoints = new MultiDimensionalPricingData
            {
                point             = points,
                businessCenter    = surfaceId.BusinessCenter,
                timing            = surfaceId.QuoteTiming,
                currency          = surfaceId.Currency,
                cashflowType      = surfaceId.CashflowType,
                informationSource = surfaceId.InformationSources,
                measureType       = surfaceId.MeasureType,
                quoteUnits        = surfaceId.QuoteUnits
            };

            if (surfaceId.ExpiryTime != null)
            {
                datapoints.expiryTime          = (DateTime)surfaceId.ExpiryTime;
                datapoints.expiryTimeSpecified = true;
            }
            if (surfaceId.ValuationDate != null)
            {
                datapoints.valuationDate          = (DateTime)surfaceId.ValuationDate;
                datapoints.valuationDateSpecified = true;
            }
            else
            {
                datapoints.valuationDate          = surfaceId.BaseDate;
                datapoints.valuationDateSpecified = true;
            }
            if (surfaceId.Time != null)
            {
                datapoints.time          = (DateTime)surfaceId.Time;
                datapoints.timeSpecified = true;
            }
            if (surfaceId.QuotationSide != null)
            {
                datapoints.side          = (QuotationSideEnum)surfaceId.QuotationSide;
                datapoints.sideSpecified = true;
            }
            var pricingStructureValuation = new VolatilityMatrix
            {
                dataPoints      = datapoints,
                objectReference = new AnyAssetReference {
                    href = surfaceId.Instrument
                },
                baseDate = new IdentifiedDate {
                    Value = surfaceId.BaseDate
                },
                buildDateTime          = surfaceId.BuildDateTime,
                buildDateTimeSpecified = true,
                definitionRef          = surfaceId.CapFrequency
            };

            return(pricingStructureValuation);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="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="inputBlackVolRates"></param>
        protected ExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, DateTime[] expiries, double[] vols,
                                                    string[] inputInstruments, double[] inputSwapRates, double[] inputBlackVolRates)
        {
            Algorithm = PropertyHelper.ExtractAlgorithm(properties);
            PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties);
            var surfaceId    = (VolatilitySurfaceIdentifier)PricingStructureIdentifier;
            var expiryLength = expiries.Length;
            var pointIndex   = 0;
            var points       = new PricingStructurePoint[expiryLength];

            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            for (var expiryIndex = 0; expiryIndex < expiryLength; expiryIndex++)
            {
                // extract the current expiry
                var expiryKeyPart = expiries[expiryIndex];
                var key           = new ExpiryTenorStrikeKey(expiryKeyPart.ToString(CultureInfo.InvariantCulture), 0);
                _matrixIndexHelper.Add(key, pointIndex);
                // Add the value to the points array (dataPoints entry in the matrix)
                var coordinates = new PricingDataPointCoordinate[1];
                coordinates[0] = new PricingDataPointCoordinate {
                    expiration = new TimeDimension[1]
                };
                coordinates[0].expiration[0] = new TimeDimension {
                    Items = new object[] { expiries[expiryIndex] }
                };
                var pt = new PricingStructurePoint
                {
                    value          = (decimal)vols[expiryIndex],
                    valueSpecified = true,
                    coordinate     = coordinates,
                };
                points[pointIndex++] = pt;
            }
            // Record the row/column sizes of the inputs
            _matrixRowCount           = expiries.Length;
            _matrixColumnCount        = 1;
            PricingStructure          = CreateVolatilityRepresentation(surfaceId);
            PricingStructureValuation = CreateDataPoints(points, surfaceId);
            if (inputInstruments != null)
            {
                int inputCount  = inputInstruments.GetUpperBound(0);
                var assetQuotes = new List <BasicAssetValuation>();
                var assetSet    = new List <Asset>();
                var itemsList   = new List <ItemsChoiceType19>();
                for (int i = 0; i <= inputCount; i++)
                {
                    var assetProperties = new PriceableAssetProperties(inputInstruments[i]);
                    assetSet.Add(new SimpleIRSwap {
                        id = inputInstruments[i], term = assetProperties.TermTenor
                    });
                    var rateQuote = BasicQuotationHelper.Create((decimal)inputSwapRates[i], AssetMeasureEnum.MarketQuote, PriceQuoteUnitsEnum.DecimalRate);
                    var volQuote  = BasicQuotationHelper.Create((decimal)inputBlackVolRates[i], AssetMeasureEnum.Volatility, PriceQuoteUnitsEnum.LogNormalVolatility);
                    assetQuotes.Add(new BasicAssetValuation
                    {
                        objectReference = new AnyAssetReference {
                            href = inputInstruments[i]
                        },
                        definitionRef = assetProperties.TermTenor.ToString(),
                        quote         = new[] { rateQuote, volQuote }
                    });
                    itemsList.Add(ItemsChoiceType19.simpleIrSwap);//TODO NOt actually correct.
                }
                var instrumentSet = new InstrumentSet {
                    Items = assetSet.ToArray(), ItemsElementName = itemsList.ToArray()
                };
                ((VolatilityMatrix)PricingStructureValuation).inputs
                    = new QuotedAssetSet {
                    assetQuote = assetQuotes.ToArray(), instrumentSet = instrumentSet
                    };
            }
            // Generate an interpolator to use
            double[] expiryTerms = expiries.Select(a => (surfaceId.BaseDate - a).TotalDays / 365d).ToArray();
            var      holder      = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var      curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));

            Interpolator = new VolSurfaceInterpolator(expiryTerms, new double[] { 1 }, new Matrix(vols), curveInterpolationMethod, true);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Takes a range of volatilities, an array of tenor expiries and an
 /// array of strikes to create a VolatilitySurface
 /// </summary>
 /// <param name="nameSpace"></param>
 /// <param name="expiryTenors"></param>
 /// <param name="strikes"></param>
 /// <param name="volSurface"></param>
 /// <param name="surfaceId"></param>
 /// <param name="logger"></param>
 /// <param name="cache">The cache.</param>
 public RateVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, String[] expiryTenors, Double[] strikes, Double[,] volSurface, VolatilitySurfaceIdentifier surfaceId)
     : base(logger, cache, nameSpace, expiryTenors, strikes, volSurface, surfaceId)
 {
     PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Rates);
 }
        /// <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="expiryTenors">the expiry tenors.</param>
        /// <param name="tenors">The tenors.</param>
        /// <param name="volSurface">The vol surface.</param>
        /// <param name="nameSpace">The namespace</param>
        /// <param name="properties">The properties.</param>
        protected ExpiryTermTenorATMVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] expiryTenors, String[] tenors, Double[,] volSurface)
        {
            Algorithm = PropertyHelper.ExtractAlgorithm(properties);
            PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties);
            var surfaceId = (VolatilitySurfaceIdentifier)PricingStructureIdentifier;
            var holder    = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));

            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            var points = ProcessRawSurface(expiryTenors, tenors, volSurface, surfaceId.UnderlyingAssetReference);

            PricingStructure = new VolatilityRepresentation
            {
                name     = surfaceId.Name,
                id       = surfaceId.Id,
                currency = surfaceId.Currency,
                asset    = new AnyAssetReference {
                    href = surfaceId.Instrument
                },
            };
            var datapoints = new MultiDimensionalPricingData {
                point             = points,
                businessCenter    = surfaceId.BusinessCenter,
                timing            = surfaceId.QuoteTiming,
                currency          = surfaceId.Currency,
                cashflowType      = surfaceId.CashflowType,
                informationSource = surfaceId.InformationSources,
                measureType       = surfaceId.MeasureType,
                quoteUnits        = surfaceId.QuoteUnits
            };

            if (surfaceId.ExpiryTime != null)
            {
                datapoints.expiryTime          = (DateTime)surfaceId.ExpiryTime;
                datapoints.expiryTimeSpecified = true;
            }
            if (surfaceId.ValuationDate != null)
            {
                datapoints.valuationDate          = (DateTime)surfaceId.ValuationDate;
                datapoints.valuationDateSpecified = true;
            }
            if (surfaceId.Time != null)
            {
                datapoints.time          = (DateTime)surfaceId.Time;
                datapoints.timeSpecified = true;
            }
            if (surfaceId.QuotationSide != null)
            {
                datapoints.side          = (QuotationSideEnum)surfaceId.QuotationSide;
                datapoints.sideSpecified = true;
            }
            PricingStructureValuation = new VolatilityMatrix
            {
                dataPoints      = datapoints,
                objectReference = new AnyAssetReference {
                    href = surfaceId.Instrument
                },
                baseDate = new IdentifiedDate {
                    Value = surfaceId.BaseDate
                },
                buildDateTime          = surfaceId.BuildDateTime,
                buildDateTimeSpecified = true
            };
            var expiries = new double[expiryTenors.Length];
            var index    = 0;

            foreach (var term in expiryTenors)//TODO include business day holidays and roll conventions.
            {
                expiries[index] = PeriodHelper.Parse(term).ToYearFraction();
                index++;
            }
            var tenor = new double[tenors.Length];

            index = 0;
            foreach (var term in tenors)//TODO include business day holidays and roll conventions.
            {
                tenor[index] = PeriodHelper.Parse(term).ToYearFraction();
                index++;
            }
            // Record the row/column sizes of the inputs
            _matrixRowCount  = expiryTenors.Length;
            _matrixRowCount *= tenors.Length;
            // Columns includes expiry and term (tenor) if it exists.
            _matrixColumnCount = 1;
            // Generate an interpolator to use
            Interpolator = new VolSurfaceInterpolator(expiries, tenor, new Matrix(volSurface), curveInterpolationMethod, true);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Unpack a raw surface and create a VolatilitySurface
 /// The object array is assumed to be zero based when it is passed to the constructor
 /// (That is any Excel idiosyncrasies have been expunged)
 /// We'll test and modify if necessary to zero base the array
 /// </summary>
 /// <param name="rawSurface"></param>
 /// <param name="surfaceId"></param>
 /// <param name="date"></param>
 //       /// <param name="algorithm">The algorithm for interpolation. Not implemented yet.</param>
 public VolatilitySurface(object[,] rawSurface, VolatilitySurfaceIdentifier surfaceId, DateTime date)
     : this(rawSurface, surfaceId, date, DateTime.Now)
 {
 }