Exemplo n.º 1
0
        public void SuperSmootherComputesCorrectly()
        {
            int      _period = 5;
            DateTime time    = DateTime.Now;

            decimal[] actualValues = new decimal[20];

            SuperSmoother sSmoother = new SuperSmoother(_period);

            # region Arrays inputs
        /// <summary>
        /// Initializes a new instance of the <see cref="AutocorrelogramPeriodogram"/> class.
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="shortPeriod">The period of the low pass filter cut off frequency.</param>
        /// <param name="longPeriod">The period of the high pass filter cut off frequency.</param>
        /// <param name="correlationWidth">Number of pair observations used to estimate the autocorrelation coefficients.</param>
        public AutocorrelogramPeriodogram(string name, int shortPeriod, int longPeriod, int correlationWidth)
            : base(name, correlationWidth)
        {
            _shortPeriod      = shortPeriod;
            _longPeriod       = longPeriod;
            _bandwidth        = longPeriod - shortPeriod;
            _correlationWidth = correlationWidth;
            _decayFactor      = EstimateDecayFactor(_shortPeriod, _longPeriod);

            hpf             = new HighPassFilter(longPeriod);
            sSmoother       = new SuperSmoother(shortPeriod);
            sSmootherWindow = new RollingWindow <double>(longPeriod + _correlationWidth);

            R = Vector <double> .Build.Dense(_bandwidth + 1, 1d);
        }
Exemplo n.º 3
0
        public void ResetsProperly()
        {
            int _period = 5;
            DateTime time = DateTime.Now;

            SuperSmoother sSmoother = new SuperSmoother(_period);

            for (int i = 0; i < 6; i++)
            {
                sSmoother.Update(new IndicatorDataPoint(time, 1m));
                time.AddMinutes(1);
            }
            Assert.IsTrue(sSmoother.IsReady, "SuperSmoother ready");
            sSmoother.Reset();
            TestHelper.AssertIndicatorIsInDefaultState(sSmoother);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Called on each bar update event (incoming tick)
 /// </summary>
 protected override void OnBarUpdate()
 {
     if (CurrentBar < Poles)
     {
         SuperSmoother.Set(Input[0]);
         return;
     }
     if (FirstTickOfBar)
     {
         if (Poles == 2)
         {
             recurrentPart = coeff2 * Value[1] + coeff3 * Value[2];
         }
         else if (Poles == 3)
         {
             recurrentPart = coeff2 * Value[1] + coeff3 * Value[2] + coeff4 * Value[3];
         }
     }
     SuperSmoother.Set(recurrentPart + coeff1 * Input[0]);
 }
Exemplo n.º 5
0
        public void SuperSmootherComputesCorrectly()
        {
            int _period = 5;
            DateTime time = DateTime.Now;
            decimal[] actualValues = new decimal[20];

            SuperSmoother sSmoother = new SuperSmoother(_period);

            # region Arrays inputs
            decimal[] prices = new decimal[20]
            {
                /*
                 * Formula:
                 * prices[i] = 10 * sin(2 * pi / 20 * i) + 15
                 * i = [0, 1, 2,..., 19]
                 */
                15m, 18.09m, 20.88m, 23.09m, 24.51m, 25m, 24.51m, 23.09m, 20.88m, 18.09m,
                15m, 11.91m, 9.12m, 6.91m, 5.49m, 5m, 5.49m, 6.91m, 9.12m, 11.91m
            };

            decimal[] expectedValues = new decimal[20]
            {
                // Estimated with Python:
                15m, 18.09m, 19.5201m, 21.3652m, 23.261m, 24.5534m, 24.9032m, 24.2448m, 22.6636m, 20.3287m,
                17.4727m, 14.3764m, 11.3411m, 8.6643m, 6.6086m, 5.374m, 5.0812m, 5.7594m, 7.3412m, 9.6731m
            };
            # endregion

            for (int i = 0; i < prices.Length; i++)
            {
                sSmoother.Update(new IndicatorDataPoint(time, prices[i]));
                actualValues[i] = Math.Round(sSmoother.Current.Value, 4);
                Console.WriteLine(actualValues[i]);
                time.AddMinutes(1);
            }
            Assert.AreEqual(expectedValues, actualValues, "Estimation SuperSmoother(5)");
        }