Пример #1
0
        public void TestBGMConvexityAdjustment()
        {
            //double[] futuresPrice = {0.0d, .05d};
            double[,] volatility    = { { 0, 0.2 } };
            double[, ,] correlation = new double[2, 2, 1];
            double[] shift     = { 0.0, 0.0 };
            double[] coverage  = { 0.25, 0.25 };
            double[] timeNodes = { 0, 0.25, 0.5 };

            double[] knownvalue = { 0.049993797154200, 0.050993548171811, 0.051993294354016, 0.052993035704439, 0.053992772226696, 0.054992503924403, 0.055992230801171, 0.056991952860608, 0.057991670106317, 0.058991382541898 };
            double   tolerance  = 1e-9;

            for (var j = 0; j < 2; j++)
            {
                for (var k = 0; k < 2; k++)
                {
                    correlation[j, k, 0] = 1;
                }
            }

            for (var i = 0; i < 10; i++)
            {
                var rate   = new[] { 0, (50.0 + i) * 0.001 };
                var result = CashForward.CalculateCashForward(rate, volatility, correlation, shift, coverage, timeNodes);
                Assert.AreEqual(knownvalue[i], result[i].x, tolerance);
                Debug.WriteLine(String.Format("rate : {0} implied: {1}", rate, result[1].x));//TODO the 1 needs to ba an i.
            }
        }
Пример #2
0
        ///<summary>
        /// The main function to calculate the adjusted forward.
        ///</summary>
        ///<param name="futuresPriceArray"> Vector of futures prices.</param>
        ///<param name="volatilityRange"> Vector of futures</param>
        ///<param name="correlationRange"> Correlation between forwards. Can be a
        /// scalar input or a correlation matrix.</param>
        ///<param name="shiftArray"> The shift parameters from the BGM
        /// calibration.</param>
        ///<param name="coverageArray"> The vector of time intervals between model
        /// time nodes.</param>
        ///<param name="timeNodesArray"> The model time nodes</param>
        ///<returns> Output, a 2-D array of ouput data. The first column is the
        /// vector of adjusted cash forwards. The second column is the error
        /// from the optimisation (the implied futures rate minus the market
        /// rate). The third column is the number of iterations taken by the
        /// optimisation routine to converge on each adjusted rate. In the first
        /// entry in the fourth and fifth column is the time taken to work
        /// through the whole set of time nodes, and the program version.</returns>
        public object[,] CalculateCashForward(Excel.Range futuresPriceArray,
                                              Excel.Range volatilityRange,
                                              Excel.Range correlationRange,
                                              Excel.Range shiftArray,
                                              Excel.Range coverageArray,
                                              Excel.Range timeNodesArray)
        {
            var futuresPrice = DataRangeHelper.StripDoubleRange(futuresPriceArray);
            var shift        = DataRangeHelper.StripDoubleRange(shiftArray);
            var coverage     = DataRangeHelper.StripDoubleRange(coverageArray);
            var timeNodes    = DataRangeHelper.StripDoubleRange(timeNodesArray);
            var volatility   = DataRangeHelper.ToMatrix <double>(volatilityRange);
            var correlation  = DataRangeHelper.ToMatrix <double>(correlationRange);
            var result       = CashForward.CalculateCashForward(futuresPrice.ToArray(), volatility,
                                                                correlation, shift.ToArray(), coverage.ToArray(), timeNodes.ToArray());

            return(DataRangeHelper.ToRange(result));
        }