示例#1
0
 /// <summary>
 /// Constructor for <see cref="ExpiryInterpolatedVolatility"/>
 /// class.
 /// </summary>
 /// <param name="bootstrapEngine">The Bootstrap Engine
 /// that contains the results of the bootstrap.
 /// Precondition: IsCapletBootstrapSuccessful method applied to the
 /// Caplet bootstrap engine returns "true".</param>
 /// <param name="expiryInterpolationType">Type of one dimensional
 /// interpolation that will be applied to the expiry.</param>
 public ExpiryInterpolatedVolatility
     (VolatilityCurve bootstrapEngine,
     ExpiryInterpolationType expiryInterpolationType)
 {
     ValidateConstructorArguments(bootstrapEngine);
     InitialisePrivateFields
         (bootstrapEngine, expiryInterpolationType);
 }
 /// <summary>
 /// Constructor for <see cref="CapletExpiryInterpolatedVolatility"/>
 /// class.
 /// </summary>
 /// <param name="capletBootstrapEngine">The Caplet Bootstrap Engine
 /// that contains the results of the bootstrap.
 /// Precondition: IsCapletBootstrapSuccessful method applied to the
 /// Caplet bootstrap engine returns "true".</param>
 /// <param name="expiryInterpolationType">Type of one dimensional
 /// interpolation that will be applied to the expiry.</param>
 public CapletExpiryInterpolatedVolatility
     (CapVolatilityCurve capletBootstrapEngine,
     ExpiryInterpolationType expiryInterpolationType)
 {
     ValidateConstructorArguments(capletBootstrapEngine);
     InitialisePrivateFields
         (capletBootstrapEngine, expiryInterpolationType);
 }
示例#3
0
 /// <summary>
 /// Constructor for the class <see cref="CapletSmileCalibrationSettings"/>.
 /// </summary>
 /// <param name="beta">SABR parameter Beta used to calibrate the Caplet
 /// smile at each expiry.</param>
 /// <param name="expiryInterpolationType">Interpolation type applied in
 /// the expiry dimension.</param>
 /// <param name="handle">Unique name used to identify the settings
 /// object that will be instantiated.</param>
 public CapletSmileCalibrationSettings
     (decimal beta,
     ExpiryInterpolationType expiryInterpolationType,
     string handle)
 {
     // Map arguments to the correct private field.
     Beta = beta;
     ExpiryInterpolationType = expiryInterpolationType;
     Handle = handle;
 }
示例#4
0
        /// <summary>
        /// Helper function used to initialise the private fields.
        /// </summary>
        /// <param name="volatilityCurve">The Bootstrap engine
        /// that contains the results of the bootstrap.</param>
        /// <param name="expiryInterpolationType">Type of the expiry
        /// interpolation.
        /// Example: Linear interpolation.</param>
        private void InitialisePrivateFields
            (VolatilityCurve volatilityCurve,
            ExpiryInterpolationType expiryInterpolationType)
        {
            // Initialise the Calculation Date.
            _calculationDate =
                volatilityCurve.GetBaseDate();
            // Set the x and y arrays for the one dimensional interpolation.
            var results
                = volatilityCurve.BootstrapResults.Results;
            IDayCounter dayCountObj = Actual365.Instance;
            var         tempXArray  = new List <double>();
            var         tempYArray  = new List <double>();
            var         count       = 1;

            foreach (var expiry in results.Keys)
            {
                var timeToExpiry = dayCountObj.YearFraction
                                       (_calculationDate, expiry);
                tempXArray.Add(timeToExpiry);
                tempYArray.Add(decimal.ToDouble(results[expiry]));
                // Record the first and last time to expiry and available
                // bootstrap Caplet volatility.
                if (count == 1)
                {
                    _firstExpiry     = (decimal)timeToExpiry;
                    _firstVolatility = results[expiry];
                }
                _lastVolatility = results[expiry];
                _lastExpiry     = (decimal)timeToExpiry;
                ++count;
            }
            double[] xArray = tempXArray.ToArray();
            double[] yArray = tempYArray.ToArray();
            // Initialise the one dimensional interpolation object.
            switch (expiryInterpolationType)
            {
            case ExpiryInterpolationType.CubicHermiteSpline:
                _expiryInterpolationObj =
                    new CubicHermiteSplineInterpolation();
                _expiryInterpolationObj.Initialize(xArray, yArray);
                break;

            default:     // Linear interpolation
                _expiryInterpolationObj = new LinearInterpolation();
                _expiryInterpolationObj.Initialize(xArray, yArray);
                break;
            }
        }
示例#5
0
        /// <summary>
        /// Process a CapFloor ATM parvVols structure.
        /// The process Bootstraps the parVols using the supplied ratecurve
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace"></param>
        /// <param name="rateCurve"></param>
        /// <param name="capFloor"></param>
        /// <returns></returns>
        private static Market ProcessCapFloorATM(ILogger logger, ICoreCache cache, string nameSpace, Market rateCurve, CapFloorATMMatrix capFloor)
        {
            var id     = capFloor.id;
            var expiry = capFloor.GetExpiries();
            var vols   = capFloor.GetVolatilities();
            var mkt    = rateCurve;
            var curve  = new SimpleRateCurve(mkt);
            var discountFactorDates = curve.GetDiscountFactorDates();
            var discountFactors     = curve.GetDiscountFactors();
            var volType             = capFloor.GetVolatilityTypes();
            var atmVols             = new Dictionary <string, decimal>();
            var settings            = CreateCapFloorProperties(capFloor.GetVolatilitySettings());
            // Create an internal matrix object from the raw data
            var matrix = new CapFloorVolatilityMatrix(id, expiry, volType, vols, null,
                                                      discountFactorDates, ArrayUtilities.ArrayToDecimal(discountFactors));
            // Create an ATM engine from the matrix
            var engines = CreateEngines(logger, cache, nameSpace, id, matrix, settings);
            // Add the default interpolation to use
            const ExpiryInterpolationType volatilityInterpolation = ExpiryInterpolationType.Linear;

            if (engines != null)
            {
                var vol = new CapletExpiryInterpolatedVolatility(engines[0], volatilityInterpolation);
                // List the values so we can build our ATM vols
                var keys = ExpiryKeys.Split(',');
                // Create a calendar to use to modify the date
                var businessCalendar = settings.GetValue("BusinessCalendar", "AUSY");
                var bc = BusinessCenterHelper.ToBusinessCalendar(cache, new[] { businessCalendar }, nameSpace);
                // Use some logic to get the spot date to use
                // LPM Spot lag is 2 days (modfollowing)
                var spotDate       = curve.GetSpotDate();
                var rollConvention = settings.GetValue("RollConvention", BusinessDayConventionEnum.FOLLOWING);
                spotDate = spotDate == curve.GetBaseDate() ? bc.Roll(spotDate.Add(new TimeSpan(2, 0, 0, 0)), rollConvention) : spotDate;
                //// Extract each surface and build an ATM engine therefrom
                //// Build a list of all possible engines
                foreach (var key in keys)
                {
                    // Calculate the volatility for each target key
                    var tv     = PeriodHelper.Parse(key);
                    var target = tv.period == PeriodEnum.D ? bc.Roll(spotDate.AddDays(Convert.ToInt32(tv.periodMultiplier)), rollConvention) :
                                 bc.Roll(spotDate.AddMonths(Convert.ToInt32(tv.periodMultiplier)), rollConvention);
                    atmVols.Add(key, vol.ComputeCapletVolatility(target));
                }
            }
            var outputVols = new object[atmVols.Count + 1, 2];
            var i          = 1;

            //Expiry	0
            outputVols[0, 0] = "Expiry";
            outputVols[0, 1] = "0";
            foreach (var key in atmVols.Keys)
            {
                outputVols[i, 0] = key;
                outputVols[i, 1] = atmVols[key];
                i++;
            }
            DateTime buildDateTime = rateCurve.Items1[0].buildDateTime;
            var      volSurface    = new VolatilitySurface(outputVols, new VolatilitySurfaceIdentifier(id), curve.BaseDate, buildDateTime);

            return(CreateMarketDocument(volSurface.GetFpMLData()));
        }