/// <summary>
        /// Generate an array of PricingStructurePoint from a set of input arrays
        /// The array can then be added to the Matrix
        /// </summary>
        /// <param name="expiry">Expiry values to use</param>
        /// <param name="strike">Strike values to use</param>
        /// <param name="volatility">An array of volatility values</param>
        /// <returns></returns>
        private static PricingStructurePoint[] ProcessRawSurface(String[] expiry, Double[] strike, double[,] volatility)
        {
            var expiryLength = expiry.Length;
            var strikeLength = strike.Length;
            var pointIndex   = 0;
            var points       = new PricingStructurePoint[expiryLength * strikeLength];

            for (var expiryIndex = 0; expiryIndex < expiryLength; expiryIndex++)
            {
                for (var strikeIndex = 0; strikeIndex < strikeLength; strikeIndex++)
                {
                    // Extract the row,column indexed volatility
                    var vol = (decimal)volatility[expiryIndex, strikeIndex];

                    // Add the value to the points array (dataPoints entry in the matrix)
                    var coordinates = new PricingDataPointCoordinate[1];
                    coordinates[0] = PricingDataPointCoordinateFactory.Create(expiry[expiryIndex], null, (Decimal)strike[strikeIndex]);
                    var pt = new PricingStructurePoint {
                        value = vol, valueSpecified = true, coordinate = coordinates
                    };
                    points[pointIndex++] = pt;
                }
            }
            return(points);
        }
예제 #2
0
        private static PricingStructurePoint[] ProcessRawSurface(string[] expiries, string[] tenors, decimal[] strikes, decimal[,] volatility, PriceQuoteUnits strikeQuoteUnits, AssetReference underlyingAssetReference)
        {
            var expiryLength = expiries.Length;
            var strikeLength = strikes.Length;
            var tenorLength  = tenors.Length;
            var points       = new List <PricingStructurePoint>();

            for (var expiryIndex = 0; expiryIndex < expiryLength; expiryIndex++)
            {
                for (var strikeIndex = 0; strikeIndex < strikeLength; strikeIndex++)
                {
                    for (var tenorIndex = 0; tenorIndex < tenorLength; tenorIndex++)
                    {
                        // Extract the row,column indexed volatility
                        var vol = volatility[expiryIndex + tenorIndex * expiryLength, strikeIndex];

                        // Add the value to the points array (dataPoints entry in the matrix)
                        var coordinates = new PricingDataPointCoordinate[1];
                        coordinates[0] = PricingDataPointCoordinateFactory.Create(expiries[expiryIndex], tenors[tenorIndex],
                                                                                  strikes[strikeIndex]);
                        var point = new PricingStructurePoint
                        {
                            value                    = vol,
                            valueSpecified           = true,
                            coordinate               = coordinates,
                            underlyingAssetReference = underlyingAssetReference,
                            quoteUnits               = strikeQuoteUnits
                        };
                        points.Add(point);
                    }
                }
            }
            return(points.ToArray());
        }
        /// <summary>
        /// Generate an array of PricingStructurePoint from a set of input arrays
        /// The array can then be added to the Matrix
        /// </summary>
        /// <param name="expiry">Expiry values to use</param>
        /// <param name="tenors">Tenor values to use</param>
        /// <param name="volatility">An array of volatility values</param>
        /// <param name="underlyingAssetReference">The underlying asset references.</param>
        /// <returns></returns>
        private PricingStructurePoint[] ProcessRawSurface(String[] expiry, String[] tenors, double[,] volatility, AssetReference underlyingAssetReference)
        {
            var expiryLength = expiry.Length;
            var tenorsLength = tenors.Length;
            var pointIndex   = 0;
            var points       = new PricingStructurePoint[expiryLength * tenorsLength];

            for (var expiryIndex = 0; expiryIndex < expiryLength; expiryIndex++)
            {
                // extract the current expiry
                var expiryKeyPart = expiry[expiryIndex];
                for (var strikeIndex = 0; strikeIndex < tenorsLength; strikeIndex++)
                {
                    // Extract the strike to use in the helper key
                    var tenorKeyPart = tenors[strikeIndex];
                    // Extract the row,column indexed volatility
                    var vol = (decimal)volatility[expiryIndex, strikeIndex];
                    var key = new ExpiryTenorStrikeKey(expiryKeyPart, tenorKeyPart);
                    _matrixIndexHelper.Add(key, pointIndex);
                    // Add the value to the points array (dataPoints entry in the matrix)
                    var coordinates = new PricingDataPointCoordinate[1];
                    coordinates[0] = PricingDataPointCoordinateFactory.Create(expiry[expiryIndex], tenors[strikeIndex], null, "ATMSurface");
                    var pt = new PricingStructurePoint {
                        value                    = vol,
                        valueSpecified           = true,
                        coordinate               = coordinates,
                        underlyingAssetReference = underlyingAssetReference
                    };
                    points[pointIndex++] = pt;
                }
            }
            return(points);
        }
예제 #4
0
        /// <summary>
        /// Creates a PricingDataPointCoordinate.
        /// </summary>
        /// <param name="expiryDate"></param>
        /// <param name="maturityDate"></param>
        /// <param name="maturityTerm"></param>
        /// <param name="strike"></param>
        /// <param name="generic"></param>
        /// <returns></returns>
        public static PricingDataPointCoordinate Create(DateTime expiryDate,
                                                        DateTime maturityDate, Period maturityTerm, decimal strike, string generic)
        {
            var coordinate            = new PricingDataPointCoordinate();
            var pMaturityTerm         = maturityTerm;
            var pStrike               = strike;
            GenericDimension pGeneric = null;

            if (generic != null)
            {
                pGeneric = new GenericDimension {
                    name = generic, Value = generic
                };
            }
            coordinate.expiration    = new TimeDimension[1];
            coordinate.expiration[0] = TimeDimensionFactory.Create(expiryDate);
            coordinate.term          = new TimeDimension[1];
            coordinate.term[0]       = TimeDimensionFactory.Create(maturityDate, pMaturityTerm);
            coordinate.strike        = new[] { pStrike };
            if (pGeneric != null)
            {
                coordinate.generic = new[] { pGeneric }
            }
            ;
            return(coordinate);
        }
    }
예제 #5
0
        /// <summary>
        /// Creates a PricingDataPointCoordinate.
        /// </summary>
        /// <param name="expiry"></param>
        /// <param name="term"></param>
        /// <param name="strike"></param>
        /// <param name="generic"></param>
        /// <returns></returns>
        public static PricingDataPointCoordinate Create(string expiry, string term, decimal strike, string generic)
        {
            var coordinate = new PricingDataPointCoordinate();
            var pExpiry    = expiry != null?PeriodHelper.Parse(expiry) : null;

            var pTerm = term != null?PeriodHelper.Parse(term) : null;

            var pStrike = strike;
            GenericDimension pGeneric = null;

            if (generic != null)
            {
                pGeneric = new GenericDimension {
                    name = generic, Value = generic
                };
            }
            coordinate.expiration    = new TimeDimension[1];
            coordinate.expiration[0] = new TimeDimension {
                Items = new object[] { pExpiry }
            };
            if (pTerm != null)
            {
                coordinate.term    = new TimeDimension[1];
                coordinate.term[0] = new TimeDimension {
                    Items = new object[] { pTerm }
                };
            }
            coordinate.strike = new[] { pStrike };
            if (pGeneric != null)
            {
                coordinate.generic = new[] { pGeneric }
            }
            ;
            return(coordinate);
        }
예제 #6
0
        /// <summary>
        /// Maps from double arrays to an IPoint list. The number of values is equal to the multiplication of xCoords and yCoords.
        /// </summary>
        /// <param name="pt">A PricingStructurePoint.</param>
        public static double[] To3DArray(PricingDataPointCoordinate pt)
        {
            //TODO trap the generic. Also add baseDate for carry calculations.
            if (pt.expiration == null || pt.strike == null)
            {
                return(null);
            }
            const double value      = 0.0;
            var          expiry     = pt.expiration[0].Items[0] as Period;
            var          strike     = (double)pt.strike[0];
            var          point      = new double[] { };
            var          expiryTime = expiry.ToYearFraction();

            if (pt.term != null)
            {
                var term     = pt.term[0].Items[0] as Period;
                var termTime = term.ToYearFraction();
                point = new[]
                {
                    expiryTime,
                    termTime,
                    strike,
                    value,
                };
            }
            return(point);
        }
        /// <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);
        }
예제 #8
0
 /// <summary>
 /// An FpML constructor.
 /// </summary>
 /// <param name="pt"></param>
 public PricingDataPoint2D(PricingDataPointCoordinate pt)
     : base(PointHelpers.To2DArray(pt))
 {
     PricingDataPointCoordinate = pt;
 }
예제 #9
0
 ///<summary>
 ///</summary>
 ///<param name="pt"></param>
 public Coordinate(PricingDataPointCoordinate pt)
 {
     PricingDataCoordinate = pt;
 }