Exemplo n.º 1
0
        public void TestSelfConsistency()
        {
            var result = new double[Rates.Length];

            for (var i = 0; i < Rates.Length; i++)
            {
                result[i] = Rates[i] * Times[i];
            }
            var vectorRatesTimes = new DoubleVector(result);

            vectorRatesTimes.Multiply(-1.0d);
            vectorRatesTimes.Apply(Math.Exp);

            var index = 0;

            foreach (var pointvalue in vectorRatesTimes)
            {
                var yearFraction = (decimal)Times[index];
                foreach (var comp in _compounding)
                {
                    var result2 = RateAnalytics.DiscountFactorToZeroRate(1.0m, (decimal)pointvalue, yearFraction, comp);
                    var result1 = RateAnalytics.ZeroRateToDiscountFactor(result2, yearFraction, comp);

                    Debug.WriteLine($"DFIn : {pointvalue} DFOut: {(double) result1}");
                    Assert.AreEqual((double)result1, pointvalue, .000000001);
                }
                index++;
            }
        }
Exemplo n.º 2
0
        public void DiscountFactorToZeroRateTest()
        {
            var result = new double[Rates.Length];

            for (var i = 0; i < Rates.Length; i++)
            {
                result[i] = Rates[i] * Times[i];
            }
            var vectorRatesTimes = new DoubleVector(result);

            vectorRatesTimes.Multiply(-1.0d);
            vectorRatesTimes.Apply(Math.Exp);
            var index = 0;

            foreach (var pointvalue in vectorRatesTimes)
            {
                var yearFraction = (decimal)Times[index];
                foreach (var comp in _compounding)
                {
                    var result2 = RateAnalytics.DiscountFactorToZeroRate(1.0m, (decimal)pointvalue, yearFraction, comp);
                    Debug.WriteLine($"Rate : {result2} Time: {yearFraction}");
                }
                index++;
            }
        }
Exemplo n.º 3
0
//        private double[] exp;


        /// <summary>
        /// Initialize this test case.
        /// </summary>
        protected static double[] SetUp()
        {
            double[] result = new double[_rates.Length];
            for (int i = 0; i < _rates.Length; i++)
            {
                result[i] = _rates[i] * _times[i];
            }
            var vectorRatesTimes = new DoubleVector(result);

            vectorRatesTimes.Multiply(-1.0d);
            return(vectorRatesTimes.Apply(Math.Exp).Vector);
        }
        /// <summary></summary>
        protected static void UpdateDiscreteDistribution( ref ChartControl chart, ProbabilityDistribution dist, List<string> titles, DistributionFunction function )
        {
            string xTitle = "x";
              string yTitle;

              int xmin = (int)Math.Floor( dist.InverseCDF( 0.0001 ) );
              int xmax = (int)Math.Ceiling( dist.InverseCDF( 0.9999 ) );
              DoubleVector x = new DoubleVector( xmax - xmin + 1, xmin, 1 );
              DoubleVector y;

              if( function == DistributionFunction.PDF )
              {
            yTitle = "Probability Mass Function";
            y = x.Apply( new Func<double, double>( dist.PDF ) );
              }
              else
              {
            yTitle = "Cumulative Distribution Function";
            y = x.Apply( new Func<double, double>( dist.CDF ) );
              }

              ChartSeries series = BindXY( x, y, ChartSeriesType.Column, ChartSymbolShape.None );

              Update( ref chart, series, titles, xTitle, yTitle );
        }