Esempio n. 1
0
        public void ResetsProperly()
        {
            var roc = new RateOfChange(50);
            foreach (var data in TestHelper.GetDataStream(51))
            {
                roc.Update(data);
            }
            Assert.IsTrue(roc.IsReady);

            roc.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(roc);
        }
Esempio n. 2
0
            private double[] GetReturns(QCAlgorithm algorithm, Symbol symbol)
            {
                var window       = new RollingWindow <double>(period);
                var rateOfChange = new RateOfChange(1);

                rateOfChange.Updated += (s, item) => window.Add((double)item.Value);

                foreach (var bar in algorithm.History(symbol, period, Resolution.Daily))
                {
                    rateOfChange.Update(bar.EndTime, bar.Close);
                }
                return(window.ToArray());
            }
Esempio n. 3
0
        public void ResetsProperly()
        {
            var roc = new RateOfChange(50);

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

            roc.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(roc);
        }
Esempio n. 4
0
        public void IndicatorValueIsNotZeroWhenReady()
        {
            var indicator = new RateOfChange(1);
            var time      = DateTime.Now;

            for (int i = 1; i <= indicator.WarmUpPeriod; i++)
            {
                indicator.Update(time, i);
                time = time.AddSeconds(1);

                Assert.AreEqual(i == indicator.WarmUpPeriod, indicator.IsReady);
            }

            Assert.IsTrue(indicator.Current > 0);
        }
Esempio n. 5
0
 /// <summary>
 /// Computes the next value for this indicator from the given state.
 /// </summary>
 /// <param name="input">The input given to the indicator</param>
 /// <returns>A new value for this indicator</returns>
 protected override decimal ComputeNextValue(IndicatorDataPoint input)
 {
     _roc.Update(input);
     return(_sharpeRatio);
 }
 public void Update(BaseData data)
 {
     ROC.Update(data.Time, data.Value);
 }
Esempio n. 7
0
 /// <summary>
 /// Updates the state of the RateOfChange with the given value and returns true
 /// if this indicator is ready, false otherwise
 /// </summary>
 /// <param name="time">The time associated with the value</param>
 /// <param name="value">The value to use to update this indicator</param>
 /// <returns>True if this indicator is ready, false otherwise</returns>
 public bool Update(DateTime time, decimal value)
 {
     return(_roc.Update(time, value));
 }
Esempio n. 8
0
        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">TradeBars IDictionary object with your stock data</param>
        public void OnData(TradeBars data)
        {
            barcount++;
            processingDate = this.Time;
            var time = this.Time;

            try
            {
                decimal val = ((data[symbol].High - data[symbol].Low) / 2) + data[symbol].Low;
                val = data[symbol].Close;
                Price.Add(idp(time, val));


                UpdateEma(time);
                UpdateOptimalTrackingFilter(time, data[symbol].High, data[symbol].Low);
                UpdateZema(time);
                priceOptimalDiff.Add(idp(time, Price[0].Value - OptimalTrackingFilter[0].Value));
                priceOptimalSign.Add(idp(time, Math.Sign(priceOptimalDiff[0].Value)));
                priceOptimalCross.Add(barcount > 1 ? idp(time, priceOptimalSign[0].Value - priceOptimalSign[1].Value) : idp(time, 0m));
                fudge.Add(idp(time, Math.Abs(priceOptimalDiff[0].Value / Price[0].Value)));

                UpdateInstantTrend(time);
                UpdateCyberCycle(time);
                UpdateCenterGravity(time);
                rvi.Update(data[symbol]);
                rviHistory.Add(rvi.Current);
                ROC.Update(OptimalTrackingFilter[0]);
                _ROCSign = Math.Sign(ROC.Current.Value);
                _nearMax = stochCyberCycleInverseFisher[0].Value > .75m;
                _nearMin = stochCyberCycleInverseFisher[0].Value < .1m;
                decimal trend = (instantTrend[0].Value - instantTrendTrigger[0].Value);
                trend = trend > 0 ? 1 : -1;

                Strategy(data);

                if (barcount > 2)
                {
                    string logmsg =
                        string.Format(
                            "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32},{33},{34},{35},{36},{37}",
                            time,
                            barcount,
                            data[symbol].Open,
                            data[symbol].High,
                            data[symbol].Low,
                            data[symbol].Close,
                            data[symbol].Volume,
                            Price[0].Value,
                            ema[0].Value,
                            zema[0].Value,
                            OptimalTrackingFilter[0].Value,
                            OptimalValue1[0].Value,
                            OmtimalValue2[0].Value,
                            lambda[0].Value,
                            alpha[0].Value,
                            priceOptimalDiff[0].Value,
                            priceOptimalSign[0].Value,
                            priceOptimalCross[0].Value,
                            fudge[0].Value,
                            instantTrend[0].Value,
                            instantTrendTrigger[0].Value,
                            trend,
                            Price[0].Value,
                            OptimalTrackingFilter[0].Value,
                            OptimalTrackingFilter[2].Value,
                            ROC.Current.Value,
                            cyberCycle[0].Value,
                            rvi.Current.Value,
                            centerGravity[0].Value,
                            rviHistory[1].Value,
                            stochCyberCycleValue1[0].Value,
                            stochCyberCycleValue2[0].Value,
                            stochCyberCycleFisher[0].Value,
                            stochCyberCycleInverseFisher[0].Value,
                            sharesOwned,
                            Portfolio.TotalPortfolioValue,
                            Portfolio[symbol].UnrealizedProfit,
                            ""
                            );
                    mylog.Debug(logmsg);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }