예제 #1
0
        /// <summary>
        /// Perform Yule-Walker algorithm to the given timeseries data
        /// </summary>
        /// <param name="data"> input data </param>
        /// <param name="p"> YuleWalker Parameter </param>
        /// <returns> array of Auto-Regressive parameter estimates. Index 0 contains coefficient of lag 1 </returns>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: public static double[] fit(final double[] data, final int p)
        public static double[] fit(double[] data, int p)
        {
            int length = data.Length;

            if (length == 0 || p < 1)
            {
                throw new Exception("fitYuleWalker - Invalid Parameters" + "length=" + length + ", p = " + p);
            }

            double[] r = new double[p + 1];
            foreach (double aData in data)
            {
                r[0] += Math.Pow(aData, 2);
            }
            r[0] /= length;

            for (int j = 1; j < p + 1; j++)
            {
                for (int i = 0; i < length - j; i++)
                {
                    r[j] += data[i] * data[i + j];
                }
                r[j] /= (length);
            }

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsMatrix toeplitz = TimeSeries.Forecast.timeseries.timeseriesutil.ForecastUtil.initToeplitz(java.util.Arrays.copyOfRange(r, 0, p));
            InsightsMatrix toeplitz = ForecastUtil.initToeplitz(Utilities.CopyOfRange(r, 0, p));
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final TimeSeries.Forecast.matrix.InsightsVector rVector = new TimeSeries.Forecast.matrix.InsightsVector(java.util.Arrays.copyOfRange(r, 1, p + 1), false);
            InsightsVector rVector = new InsightsVector(Utilities.CopyOfRange(r, 1, p + 1), false);

            return(toeplitz.solveSPDIntoVector(rVector, ForecastUtil.maxConditionNumber).deepCopy());
        }
예제 #2
0
        public virtual void Arma2ma_test()
        {
            double[] ar  = new double[] { 1.0, -0.25 };
            double[] ma  = new double[] { 1.0, 2.0 };
            int      lag = 10;

            double[] ma_coeff   = ForecastUtil.ARMAtoMA(ar, ma, lag);
            double[] true_coeff = new double[] { 1.0, 2.0, 3.75, 3.25, 2.3125, 1.5, 0.921875, 0.546875, 0.31640625, 0.1796875 };

            Assert.Equal(ma_coeff, true_coeff); //$!!$, 1e-6);
            //Util.Equal(ma_coeff, true_coeff, 1e-6);
        }
예제 #3
0
        public static void Calc(Course request)
        {
            var result       = new CourseResult();
            var fund         = request.Amount;
            var periods      = request.StopAtPeriod.HasValue ? request.StopAtPeriod : request.Period;
            var forecast1    = ForecastUtil.Get(ForecastType.VariablePriceIndex);
            var forecast2    = ForecastUtil.Get(ForecastType.PriceIndex);
            var zeroInterest = forecast1.GetValue();

            for (int i = 0; i < periods; i++)
            {
                var priceIndex =
                    request.WithForecast ?
                    forecast2.GetValue(request.StartMonth + i) / 12 :
                    forecast2.GetValue(1) / 12;

                var baseInterest =
                    request.WithForecast ?
                    forecast1.GetValue(request.StartMonth + i) - zeroInterest :
                    0;

                var rate                      = (request.Interest + baseInterest) / 12;
                var pmt                       = -Utils.Pmt(rate / 100, request.Period - i, fund);
                var interestPayment           = fund * rate / 100;
                var fundPayment               = pmt - interestPayment;
                var fundPaymentWithPriceIndex = fundPayment * Math.Pow(1 + (priceIndex / 100), i + 1);

                var payment = new Payment
                {
                    Period = i + 1,
                    InterestMonthPercentage = Utils.Round4(rate),
                    InterestYearPercentage  = Utils.Round4(rate * 12),
                    PriceIndex                = Utils.Round4(priceIndex),
                    PriceIndexPayment         = Utils.Round2(fundPayment * (Math.Pow(1 + (priceIndex / 100), i + 1) - 1)),
                    InterestPayment           = Utils.Round2(interestPayment),
                    TotalFund                 = Utils.Round2(fund),
                    TotalFundWithPriceIndex   = Utils.Round2(fund * (1 + (priceIndex / 100))),
                    FundPayment               = Utils.Round2(fundPayment),
                    FundPaymentWithPriceIndex = Utils.Round2(fundPaymentWithPriceIndex),
                    TotalPayment              = Utils.Round2(fundPaymentWithPriceIndex + interestPayment),
                };

                result.Payments.Add(payment);
                fund = fund - payment.FundPayment;
            }

            request.Result = result;
        }
예제 #4
0
        public static void Calc(Course request)
        {
            var result   = new CourseResult();
            var fund     = request.Amount;
            var forecast = ForecastUtil.Get(ForecastType.Prime);

            request.StopAtPeriod = request.Recycle == null ? (int?)null : request.Recycle.FromMonth - 1;

            var periods     = request.StopAtPeriod.HasValue ? request.StopAtPeriod : request.Period;
            var boiInterest = forecast.GetValue();

            for (int i = 0; i < periods; i++)
            {
                var baseInterest = request.WithForecast ?
                                   forecast.GetValue(request.StartMonth + i) - boiInterest :
                                   0;

                var rate     = (baseInterest + request.Interest) / 12;
                var pmt      = -Utils.Pmt(rate / 100, request.Period - i, fund);
                var interest = fund * rate / 100;

                var payment = new Payment
                {
                    Period = i + request.StartMonth,
                    InterestMonthPercentage = Utils.Round4(rate),
                    InterestYearPercentage  = Utils.Round4(rate * 12),
                    TotalPayment            = Utils.Round2(pmt),
                    FundPayment             = Utils.Round2(pmt - interest),
                    InterestPayment         = Utils.Round2(interest),
                    TotalFund = Utils.Round2(fund),
                };

                payment.TotalFundWithPriceIndex   = payment.TotalFund;
                payment.FundPaymentWithPriceIndex = payment.FundPayment;

                result.Payments.Add(payment);
                fund = fund - payment.FundPayment;
            }

            request.Result = result;

            if (request.Recycle != null)
            {
                Recycle(request);
            }
        }
예제 #5
0
 /// <summary>
 /// Set Sigma2(RMSE) and Predication Interval for forecast result.
 /// </summary>
 /// <param name="params"> ARIMA parameters </param>
 /// <param name="forecastResult"> MODIFIED. forecast result </param>
 /// <param name="forecastSize"> size of forecast </param>
 /// <returns> max normalized variance </returns>
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
 //ORIGINAL LINE: public static double setSigma2AndPredicationInterval(final TimeSeries.Forecast.TimeSeries.Arima.struct.ArimaParams params, final TimeSeries.Forecast.TimeSeries.Arima.struct.ForecastResult forecastResult, final int forecastSize)
 public static double setSigma2AndPredicationInterval(ArimaParams @params, ForecastResult forecastResult, int forecastSize)
 {
     //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
     //ORIGINAL LINE: final double[] coeffs_AR = params.getCurrentARCoefficients();
     double[] coeffs_AR = @params.CurrentARCoefficients;
     //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
     //ORIGINAL LINE: final double[] coeffs_MA = params.getCurrentMACoefficients();
     double[] coeffs_MA = @params.CurrentMACoefficients;
     return(forecastResult.SetConfInterval(ForecastUtil.confidence_constant_95pct, ForecastUtil.getCumulativeSumOfCoeff(ForecastUtil.ARMAtoMA(coeffs_AR, coeffs_MA, forecastSize))));
 }