Example #1
0
        /// <summary>
        /// Create a surface from an FpML
        /// </summary>
        /// <param name="fpmlData"></param>
        public VolatilitySurface(Pair <PricingStructure, PricingStructureValuation> fpmlData)
        {
            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, new DateTime(), dc);//TODO need to create a surfaceinterpolator.
            _algorithm   = "Linear";
            SetFpMLData(fpmlData);
//            var holder = new PricingStructureAlgorithmsHolder();
            bool doBuild = GetVolatilityMatrix().dataPoints.point == null;

            if (doBuild)
            {
                //               var bootstrapperName = holder.GetValue(PricingStructureType.RateVolatilityMatrix, _algorithm, "Bootstrapper");

                //               Bootstrapper = Bootstrap(bootstrapperName, PricingStructure, PricingStructureValuation);
            }

            //           SetInterpolator(PricingStructureValuation.baseDate.Value, _algorithm, holder);
            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            ProcessVolatilityRepresentation();
        }
Example #2
0
        private void SetInterpolator()
        {
            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, new DateTime(), dc);
        }
Example #3
0
        //TODO this is not yet implemented. FIX IT!
        internal void SetSpreadInterpolator(TermCurve discountFactorCurve, string algorithm, PricingStructureTypeEnum psType)
        {
            var curveId = (RateCurveIdentifier)PricingStructureIdentifier;

            // The underlying curve and associated compounding frequency (compounding frequency required when underlying curve is a ZeroCurve)
            CompoundingFrequency        = EnumHelper.Parse <CompoundingFrequencyEnum>(Holder.GetValue("CompoundingFrequency"));
            UnderlyingInterpolatedCurve = Holder.GetValue("UnderlyingCurve"); //TODO this redundant.
            var interpDayCounter = Actual365.Instance;
            var underlyingCurve  = ParseUnderlyingCurve(UnderlyingInterpolatedCurve);

            // interpolate the DiscountFactor curve based on the respective curve interpolation
            if (underlyingCurve != UnderlyingCurveTypes.ZeroCurve)
            {
                Interpolator = new TermCurveInterpolator(discountFactorCurve, GetBaseDate(), interpDayCounter);
            }
            // otherwise interpolate our underlying curve will be a zero curve
            else
            {
                var zeroCurve = new ZeroRateCurve
                {
                    rateCurve = YieldCurveAnalytics.ToZeroCurve(discountFactorCurve,
                                                                GetBaseDate(),
                                                                CompoundingFrequency, DayCounter)
                };
                zeroCurve.rateCurve.interpolationMethod = InterpolationMethodHelper.Parse(Holder.GetValue("CurveInterpolation"));
                zeroCurve.compoundingFrequency          = FpML.V5r3.Reporting.CompoundingFrequency.Create(CompoundingFrequency);
                GetYieldCurveValuation().zeroCurve      = zeroCurve;
                if (curveId.Algorithm == "SpreadInterpolation")
                {
                }
                else
                {
                    Interpolator =
                        new TermCurveInterpolator(GetYieldCurveValuation().zeroCurve.rateCurve, GetBaseDate(), interpDayCounter);
                }//TODO this is where to add the spread stuff.
            }
        }
Example #4
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();
            }
        }
Example #5
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="assetRef">The Asset this volatility models</param>
        /// <param name="name">The id to use with this matrix</param>
        /// <param name="date">The value date relating to this surface</param>
        /// <param name="expiry">An array of expiry definitions</param>
        /// <param name="term">An array of tenors or null if there is no term dimension.</param>
        /// <paparam name="strike">An array of strike descriptions</paparam>
        /// <param name="strike">The strike array.</param>
        /// <param name="volatility">A 2d array of volatilities.
        /// This must be equal to (expiry.Count x (1 &lt;= y &lt;= term.Count) x strike.Count </param>
        public VolatilitySurface(string assetRef, string name, DateTime date, string[] expiry, string[] term,
                                 string[] strike, double[,] volatility)
        {
            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.
            _algorithm         = "Linear";
            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            var points = ProcessRawSurface(expiry, term, strike, volatility);

            PricingStructure = new VolatilityRepresentation {
                name = name
                ,
                id = name + date.ToString("yyyyMMdd")
                ,
                asset = new AnyAssetReference {
                    href = assetRef
                }
            };
            PricingStructureValuation = new VolatilityMatrix
            {
                dataPoints = new MultiDimensionalPricingData {
                    point = points
                }
                ,
                objectReference = new AnyAssetReference {
                    href = PricingStructure.id
                }
                ,
                baseDate = new IdentifiedDate {
                    Value = date
                }
                ,
                buildDateTime = DateTime.Now
                ,
                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;
            //TODO
            // Generate an interpolator to use
            if (term == null || term.Length == 0)
            {
                _interpolation = new BilinearInterpolator();
            }
            else
            {
                _interpolation = new TrilinearInterpolator();
            }
        }
        internal void SetSpreadInterpolator(TermCurve discountFactorCurve, string algorithm)
        {
            var interpDayCounter = Actual365.Instance;

            Interpolator = new TermCurveInterpolator(discountFactorCurve, GetBaseDate(), interpDayCounter);
        }