Ejemplo n.º 1
0
 public void ComputesCorrectly()
 {
     var mom =  new Momentum(5);
     foreach (var data in TestHelper.GetDataStream(5))
     {
         mom.Update(data);
         Assert.AreEqual(data.Value, mom.Current.Value);
     }
 }
Ejemplo n.º 2
0
        public void ComputesCorrectly()
        {
            var mom = new Momentum(5);

            foreach (var data in TestHelper.GetDataStream(5))
            {
                mom.Update(data);
                Assert.AreEqual(data.Value, mom.Current.Value);
            }
        }
Ejemplo n.º 3
0
        public void WarmsUpProperly()
        {
            var mom        = new Momentum(5);
            var period     = ((IIndicatorWarmUpPeriodProvider)mom).WarmUpPeriod;
            var dataStream = TestHelper.GetDataStream(period).ToArray();

            for (var i = 0; i < period; i++)
            {
                mom.Update(dataStream[i]);
                Assert.AreEqual(i == period - 1, mom.IsReady);
            }
        }
Ejemplo n.º 4
0
        public void ResetsProperly()
        {
            var mom = new Momentum(5);
            foreach (var data in TestHelper.GetDataStream(6))
            {
                mom.Update(data);
            }
            Assert.IsTrue(mom.IsReady);

            mom.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(mom);
        }
Ejemplo n.º 5
0
        public void ResetsProperly()
        {
            var mom = new Momentum(5);

            foreach (var data in TestHelper.GetDataStream(6))
            {
                mom.Update(data);
            }
            Assert.IsTrue(mom.IsReady);

            mom.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(mom);
        }
Ejemplo n.º 6
0
        private void DrawMomentum(Graphics graphics, DrawF draw)
        {
            ArrayList history   = new ArrayList();
            PointF2D  point     = new PointF2D(-4.0f, 2.0f);
            Function2 fun       = new Function2();
            Momentum  optimizer = new Momentum(0.07f, 0.9f);

            for (int index = 0; index < 30; index++)
            {
                PointF2D xyPoint = draw.getBlockPoint(point.X, point.Y);
                history.Add(xyPoint);
                PointF2D diff = fun.DiffFormula(point.X, point.Y);
                optimizer.Update(point, diff);
            }

            PointF2D prePoint = ((PointF2D)history[0]);

            for (int index = 0; index < 30; index++)
            {
                draw.drawPoint(graphics, Brushes.Blue, ((PointF2D)history[index]));
                draw.drawLine(graphics, prePoint, ((PointF2D)history[index]));
                prePoint = ((PointF2D)history[index]);
            }
        }
Ejemplo n.º 7
0
        public Sig10Strategy(SecurityHolding sym, Indicator priceIdentity, int trendPeriod, decimal lossThreshhold, decimal tolerance, decimal revertPct)
        {

            trendArray = new decimal[trendPeriod + 1];       // initialized to 0.  Add a period for Deserialize to make IsReady true

            symbol = sym.Symbol;
            _holding = sym;
            _price = priceIdentity;
            _period = trendPeriod;
            _lossThreshhold = lossThreshhold;
            _tolerance = tolerance;
            RevPct = revertPct;
            Trend = new InstantaneousTrend(sym.Symbol.Value, 7, .24m).Of(priceIdentity);
            TrendMomentum = new Momentum(2).Of(Trend);
            MomentumWindow = new RollingWindow<decimal>(2);
            ActualSignal = OrderSignal.doNothing;

            Trend.Updated += (object sender, IndicatorDataPoint updated) =>
            {
                Barcount++;
                UpdateTrendArray(Trend.Current.Value);
                nTrig = Trend.Current.Value;
                if (Trend.IsReady)
                {
                    TrendMomentum.Update(Trend.Current);
                }
                if (TrendMomentum.IsReady) 
                    MomentumWindow.Add(TrendMomentum.Current.Value);
                if (MomentumWindow.IsReady) 
                    CheckSignal();
            };
        }