コード例 #1
0
        public void setUp()
        {
            Random      r    = new Random();
            List <IBar> bars = new List <IBar>();

            for (int i = 0; i < 1000; i++)
            {
                double   open     = r.NextDouble();
                double   close    = r.NextDouble();
                double   max      = Math.Max(close + r.NextDouble(), open + r.NextDouble());
                double   min      = Math.Min(0, Math.Min(close - r.NextDouble(), open - r.NextDouble()));
                DateTime dateTime = DateTime.Now;
                IBar     bar      = new BaseBar(dateTime, (decimal)open, (decimal)close, (decimal)max, (decimal)min, i);
                bars.Add(bar);
            }
            this.series = new BaseTimeSeries("test", bars);

            this.openPriceIndicator = new OpenPriceIndicator(this.series);
            this.minPriceIndicator  = new MinPriceIndicator(this.series);
            this.maxPriceIndicator  = new MaxPriceIndicator(this.series);
            this.volumeIndicator    = new VolumeIndicator(this.series);
            ClosePriceIndicator closePriceIndicator = new ClosePriceIndicator(this.series);

            this.emaIndicator = new EMAIndicator(closePriceIndicator, 20);
        }
コード例 #2
0
        /// <param name="series">a time series </param>
        /// <returns> a moving momentum strategy </returns>
        public static Strategy BuildStrategy(TimeSeries series)
        {
            if (series == null)
            {
                throw new System.ArgumentException("Series cannot be null");
            }

            var closePrice = new ClosePriceIndicator(series);

            // The bias is bullish when the shorter-moving average moves above the longer moving average.
            // The bias is bearish when the shorter-moving average moves below the longer moving average.
            var shortEma = new EMAIndicator(closePrice, 9);
            var longEma  = new EMAIndicator(closePrice, 26);

            var stochasticOscillK = new StochasticOscillatorKIndicator(series, 14);

            var macd    = new MACDIndicator(closePrice, 9, 26);
            var emaMacd = new EMAIndicator(macd, 18);

            // Entry rule
            var entryRule = (new OverIndicatorRule(shortEma, longEma)).And(new CrossedDownIndicatorRule(stochasticOscillK, Decimal.ValueOf(20))).And(new OverIndicatorRule(macd, emaMacd));             // Signal 2 -  Signal 1 -  Trend

            // Exit rule
            var exitRule = (new UnderIndicatorRule(shortEma, longEma)).And(new CrossedUpIndicatorRule(stochasticOscillK, Decimal.ValueOf(80))).And(new UnderIndicatorRule(macd, emaMacd));             // Signal 2 -  Signal 1 -  Trend

            return(new Strategy(entryRule, exitRule));
        }
コード例 #3
0
        /// <param name="series"> a time series </param>
        /// <returns> a global extrema strategy </returns>
        public static Strategy BuildStrategy(TimeSeries series)
        {
            if (series == null)
            {
                throw new ArgumentException("Series cannot be null");
            }

            var closePrices = new ClosePriceIndicator(series);

            // Getting the max price over the past week
            var maxPrices    = new MaxPriceIndicator(series);
            var weekMaxPrice = new HighestValueIndicator(maxPrices, NB_TICKS_PER_WEEK);
            // Getting the min price over the past week
            var minPrices    = new MinPriceIndicator(series);
            var weekMinPrice = new LowestValueIndicator(minPrices, NB_TICKS_PER_WEEK);

            // Going long if the close price goes below the min price
            var downWeek   = new MultiplierIndicator(weekMinPrice, Decimal.ValueOf("1.004"));
            var buyingRule = new UnderIndicatorRule(closePrices, downWeek);

            // Going short if the close price goes above the max price
            var upWeek      = new MultiplierIndicator(weekMaxPrice, Decimal.ValueOf("0.996"));
            var sellingRule = new OverIndicatorRule(closePrices, upWeek);

            return(new Strategy(buyingRule, sellingRule));
        }
コード例 #4
0
ファイル: RSI2Strategy.cs プロジェクト: jasonmnemonic/TA4N
        /// <param name="series"> a time series </param>
        /// <returns> a 2-period RSI strategy </returns>
        public static Strategy BuildStrategy(TimeSeries series)
        {
            if (series == null)
            {
                throw new ArgumentException("Series cannot be null");
            }

            var closePrice = new ClosePriceIndicator(series);
            var shortSma   = new SMAIndicator(closePrice, 5);
            var longSma    = new SMAIndicator(closePrice, 200);

            // We use a 2-period RSI indicator to identify buying
            // or selling opportunities within the bigger trend.
            var rsi = new RSIIndicator(closePrice, 2);

            // Entry rule
            // The long-term trend is up when a security is above its 200-period SMA.
            var entryRule = (new OverIndicatorRule(shortSma, longSma)).And(new CrossedDownIndicatorRule(rsi, Decimal.ValueOf(5))).And(new OverIndicatorRule(shortSma, closePrice));             // Signal 2 -  Signal 1 -  Trend

            // Exit rule
            // The long-term trend is down when a security is below its 200-period SMA.
            var exitRule = (new UnderIndicatorRule(shortSma, longSma)).And(new CrossedUpIndicatorRule(rsi, Decimal.ValueOf(95))).And(new UnderIndicatorRule(shortSma, closePrice));             // Signal 2 -  Signal 1 -  Trend

            return(new Strategy(entryRule, exitRule));
        }
コード例 #5
0
 public void SetUp()
 {
     _data       = GenerateTimeSeries.From(1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2);
     _timeFrame  = 3;
     _closePrice = new ClosePriceIndicator(_data);
     _sma        = new SmaIndicator(_closePrice, _timeFrame);
 }
コード例 #6
0
ファイル: StopLossRuleTest.cs プロジェクト: johndpope/TA4Net
 public void SetUp()
 {
     tradingRecord = new BaseTradingRecord();
     closePrice    = new ClosePriceIndicator(new MockTimeSeries(
                                                 100, 105, 110, 120, 100, 150, 110, 100
                                                 ));
 }
コード例 #7
0
        public void setUp()
        {
            ITimeSeries data = new MockTimeSeries(1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2);

            timeFrame  = 3;
            closePrice = new ClosePriceIndicator(data);
            sma        = new SMAIndicator(closePrice, timeFrame);
        }
コード例 #8
0
 public IIIIndicator(ITimeSeries series)
     : base(series)
 {
     _closePriceIndicator = new ClosePriceIndicator(series);
     _maxPriceIndicator   = new MaxPriceIndicator(series);
     _minPriceIndicator   = new MinPriceIndicator(series);
     _volumeIndicator     = new VolumeIndicator(series);
 }
コード例 #9
0
        public void TimeSeries()
        {
            ClosePriceIndicator cp = new ClosePriceIndicator(series);

            Assert.AreEqual(series, cp.TimeSeries);
            SMAIndicator sma = new SMAIndicator(cp, 3);

            Assert.AreEqual(series, sma.TimeSeries);
        }
コード例 #10
0
        public void CalculateLinearRegression()
        {
            var values    = new double[] { 1, 2, 1.3, 3.75, 2.25 };
            var indicator = new ClosePriceIndicator(GenerateTimeSeries.From(values));
            var reg       = new SimpleLinearRegressionIndicator(indicator, 5);

//			SimpleRegression origReg = buildSimpleRegression(values);
            TaTestsUtils.AssertDecimalEquals(reg.GetValue(4), 2.91);         //origReg.predict(4));
        }
コード例 #11
0
        public void GetTimeSeries()
        {
            var cp = new ClosePriceIndicator(_series);

            Assert.AreEqual(_series, cp.TimeSeries);
            var sma = new SmaIndicator(cp, 3);

            Assert.AreEqual(_series, sma.TimeSeries);
        }
コード例 #12
0
        public void setUp()
        {
            ITimeSeries data = new MockTimeSeries(
                0.73M, 0.72M, 0.86M, 0.72M, 0.62M,
                0.76M, 0.84M, 0.69M, 0.65M, 0.71M,
                0.53M, 0.73M, 0.77M, 0.67M, 0.68M
                );

            closePrice = new ClosePriceIndicator(data);
        }
コード例 #13
0
        public void setUp()
        {
            ITimeSeries data = new MockTimeSeries(
                10, 12, 15, 14, 17,
                20, 21, 20, 20, 19,
                20, 17, 12, 12, 9,
                8, 9, 10, 9, 10
                );

            closePrice = new ClosePriceIndicator(data);
        }
コード例 #14
0
        public void setUp()
        {
            ITimeSeries mockSeries = new MockTimeSeries(
                29.49M, 28.30M, 27.74M, 27.65M, 27.60M, 28.70M, 28.60M,
                28.19M, 27.40M, 27.20M, 27.28M, 27.00M, 27.59M, 26.20M,
                25.75M, 24.75M, 23.33M, 24.45M, 24.25M, 25.02M, 23.60M,
                24.20M, 24.28M, 25.70M, 25.46M, 25.10M, 25.00M, 25.00M,
                25.85M);

            seriesManager = new TimeSeriesManager(mockSeries);
            closePrice    = new ClosePriceIndicator(mockSeries);
        }
コード例 #15
0
        public void setUp()
        {
            ITimeSeries series = new MockTimeSeries(
                22.27M, 22.19M, 22.08M, 22.17M, 22.18M, 22.13M,
                22.23M, 22.43M, 22.24M, 22.29M, 22.15M, 22.39M,
                22.38M, 22.61M, 23.36M, 24.05M, 23.75M, 23.83M,
                23.95M, 23.63M, 23.82M, 23.87M, 23.65M, 23.19M,
                23.10M, 23.33M, 22.68M, 23.10M, 21.40M, 20.17M
                );

            closePriceIndicator = new ClosePriceIndicator(series);
        }
コード例 #16
0
        [Test] // calculate()
        public void Calculate()
        {
            var series = GenerateTimeSeries.From(1d, 2d, 3d, 4d, 5d, 6d);
            IIndicator <Decimal> close        = new ClosePriceIndicator(series);
            IIndicator <Decimal> wmaIndicator = new WmaIndicator(close, 3);

            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(1), 1.6667);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(2), 2.3333);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(3), 3.3333);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(4), 4.3333);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(5), 5.3333);
        }
コード例 #17
0
ファイル: WMAIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void Calculate()
        {
            MockTimeSeries       series       = new MockTimeSeries(1, 2, 3, 4, 5, 6);
            IIndicator <decimal> close        = new ClosePriceIndicator(series);
            IIndicator <decimal> wmaIndicator = new WMAIndicator(close, 3);

            Assert.AreEqual(wmaIndicator.GetValue(0), 1);
            Assert.AreEqual(wmaIndicator.GetValue(1), 1.6666666666666666666666666667M);
            Assert.AreEqual(wmaIndicator.GetValue(2), 2.3333333333333333333333333333M);
            Assert.AreEqual(wmaIndicator.GetValue(3), 3.3333333333333333333333333333M);
            Assert.AreEqual(wmaIndicator.GetValue(4), 4.3333333333333333333333333333M);
            Assert.AreEqual(wmaIndicator.GetValue(5), 5.3333333333333333333333333333M);
        }
コード例 #18
0
        public void WmaWithTimeFrameGreaterThanSeriesSize()
        {
            var series = GenerateTimeSeries.From(1d, 2d, 3d, 4d, 5d, 6d);
            IIndicator <Decimal> close        = new ClosePriceIndicator(series);
            IIndicator <Decimal> wmaIndicator = new WmaIndicator(close, 55);

            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(1), 1.6667);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(2), 2.3333);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(3), 3);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(4), 3.6666);
            TaTestsUtils.AssertDecimalEquals(wmaIndicator.GetValue(5), 4.3333);
        }
コード例 #19
0
ファイル: WMAIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void wmaWithTimeFrameGreaterThanSeriesSize()
        {
            MockTimeSeries       series       = new MockTimeSeries(1, 2, 3, 4, 5, 6);
            IIndicator <decimal> close        = new ClosePriceIndicator(series);
            IIndicator <decimal> wmaIndicator = new WMAIndicator(close, 55);

            Assert.AreEqual(1, wmaIndicator.GetValue(0));
            Assert.AreEqual(1.6666666666666666666666666667M, wmaIndicator.GetValue(1));
            Assert.AreEqual(2.3333333333333333333333333333M, wmaIndicator.GetValue(2));
            Assert.AreEqual(3, wmaIndicator.GetValue(3));
            Assert.AreEqual(3.6666666666666666666666666667M, wmaIndicator.GetValue(4));
            Assert.AreEqual(4.3333333333333333333333333333M, wmaIndicator.GetValue(5));
        }
コード例 #20
0
ファイル: RSIIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void onlineExampleTest()
        { // throws exception
          // from http://cns.bu.edu/~gsc/CN710/fincast/Technical%20_indicators/Relative%20Strength%20Index%20(RSI).htm
          // which uses a different calculation of RSI than ta4j
            ITimeSeries series = new MockTimeSeries(
                46.1250M,
                47.1250M, 46.4375M, 46.9375M, 44.9375M, 44.2500M, 44.6250M, 45.7500M,
                47.8125M, 47.5625M, 47.0000M, 44.5625M, 46.3125M, 47.6875M, 46.6875M,
                45.6875M, 43.0625M, 43.5625M, 44.8750M, 43.6875M);
            // ta4j RSI uses MMA for average gain and loss
            // then uses simple division of the two for RS
            IIndicator <decimal> indicator = getIndicator(new ClosePriceIndicator(
                                                              series), 14);
            IIndicator <decimal> close = new ClosePriceIndicator(series);
            IIndicator <decimal> gain  = new GainIndicator(close);
            IIndicator <decimal> loss  = new LossIndicator(close);
            // this site uses SMA for average gain and loss
            // then uses ratio of MMAs for RS (except for first calculation)
            IIndicator <decimal> avgGain = new SMAIndicator(gain, 14);
            IIndicator <decimal> avgLoss = new SMAIndicator(loss, 14);

            // first online calculation is simple division
            decimal onlineRs = avgGain.GetValue(14).DividedBy(avgLoss.GetValue(14));

            Assert.AreEqual(0.5848214285714285714285714286M, avgGain.GetValue(14));
            Assert.AreEqual(0.5446428571428571428571428571M, avgLoss.GetValue(14));
            Assert.AreEqual(1.0737704918032786885245901641M, onlineRs);
            decimal onlineRsi = 100M - (100M / (1M + onlineRs));

            // difference in RSI values:
            Assert.AreEqual(51.778656126482213438735177869M, onlineRsi);
            Assert.AreEqual(52.130477585417047385335308781M, indicator.GetValue(14));

            // strange, online average gain and loss is not a simple moving average!
            // but they only use them for the first RS calculation
            // Assert.AreEqual(0.5430, avgGain.getValue(15));
            // Assert.AreEqual(0.5772, avgLoss.getValue(15));
            // second online calculation uses MMAs
            // MMA of average gain
            decimal dividend = avgGain.GetValue(14).MultipliedBy(13M).Plus(gain.GetValue(15)).DividedBy(14M);
            // MMA of average loss
            decimal divisor = avgLoss.GetValue(14).MultipliedBy(13M).Plus(loss.GetValue(15)).DividedBy(14M);

            onlineRs = dividend / divisor;
            Assert.AreEqual(0.940883977900552486187845304M, onlineRs);
            onlineRsi = 100M - (100M / (1M + onlineRs));
            // difference in RSI values:
            Assert.AreEqual(48.477085112439510389980074014M, onlineRsi);
            Assert.AreEqual(47.37103140045740279363506511M, indicator.GetValue(15));
        }
コード例 #21
0
        /// <summary>
        /// Builds an additional JFreeChart dataset from a ta4j time series. </summary>
        /// <param name="series"> a time series </param>
        /// <returns> an additional dataset </returns>
        private static TimeSeriesCollection createAdditionalDataset(TimeSeries series)
        {
            ClosePriceIndicator  indicator = new ClosePriceIndicator(series);
            TimeSeriesCollection dataset   = new TimeSeriesCollection();

            org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries("Btc price");
            for (int i = 0; i < series.TickCount; i++)
            {
                Tick tick = series.getTick(i);
                chartTimeSeries.add(new Second(tick.EndTime.toDate()), indicator.getValue(i).toDouble());
            }
            dataset.addSeries(chartTimeSeries);
            return(dataset);
        }
コード例 #22
0
        public void WithoutInitialLimitUsingClosePrice()
        {
            var price = new ClosePriceIndicator(_data);
            var tsl   = new TrailingStopLossIndicator(price, Decimal.ValueOf(4));

            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(1), 15);
            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(2), 19);
            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(3), 19);

            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(8), 19);
            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(9), 21);
            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(10), 22);
            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(11), 25);
            TaTestsUtils.AssertDecimalEquals(tsl.GetValue(12), 25);
        }
コード例 #23
0
ファイル: MMAIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void stackOverflowError()
        { // throws exception
            List <IBar> bigListOfBars = new List <IBar>();

            for (int i = 0; i < 10000; i++)
            {
                bigListOfBars.Add(new MockBar(i));
            }
            MockTimeSeries       bigSeries       = new MockTimeSeries(bigListOfBars);
            ClosePriceIndicator  closePrice      = new ClosePriceIndicator(bigSeries);
            IIndicator <decimal> actualIndicator = getIndicator(closePrice, 10);

            // if a StackOverflowError is thrown here, then the RecursiveCachedIndicator does not work as intended.
            Assert.AreEqual(9990.0M, actualIndicator.GetValue(9999));
        }
コード例 #24
0
        public void StackOverflowError()
        {
            IList <Tick> bigListOfTicks = new List <Tick>();

            for (var i = 0; i < 10000; i++)
            {
                bigListOfTicks.Add(GenerateTick.From(i));
            }
            var bigSeries  = GenerateTimeSeries.From(bigListOfTicks);
            var closePrice = new ClosePriceIndicator(bigSeries);
            var ema        = new EmaIndicator(closePrice, 10);

            // If a StackOverflowError is thrown here, then the RecursiveCachedIndicator
            // does not work as intended.
            TaTestsUtils.AssertDecimalEquals(ema.GetValue(9999), 9994.5);
        }
コード例 #25
0
ファイル: RSIIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void xlsTest()
        {
            IIndicator <decimal> xlsClose = new ClosePriceIndicator(xls.getSeries());
            IIndicator <decimal> indicator;

            indicator = getIndicator(xlsClose, 1);
            //  Assert.AreEqual(xls.getIndicator(1), indicator);
            Assert.AreEqual(100.0M, indicator.GetValue(indicator.TimeSeries.GetEndIndex()));

            indicator = getIndicator(xlsClose, 3);
            //  Assert.AreEqual(xls.getIndicator(3), indicator);
            Assert.AreEqual(67.045374582390542029793809567M, indicator.GetValue(indicator.TimeSeries.GetEndIndex()));

            indicator = getIndicator(xlsClose, 13);
            //  Assert.AreEqual(xls.getIndicator(13), indicator);
            Assert.AreEqual(52.587681858903097357018319486M, indicator.GetValue(indicator.TimeSeries.GetEndIndex()));
        }
コード例 #26
0
        public void Kama()
        {
            var closePrice = new ClosePriceIndicator(_data);
            var kama       = new KamaIndicator(closePrice, 10, 2, 30);

            TaTestsUtils.AssertDecimalEquals(kama.GetValue(9), 109.2400);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(10), 109.2449);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(11), 109.2165);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(12), 109.1173);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(13), 109.0981);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(14), 109.0894);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(15), 109.1240);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(16), 109.1376);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(17), 109.2769);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(18), 109.4365);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(19), 109.4569);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(20), 109.4651);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(21), 109.4612);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(22), 109.3904);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(23), 109.3165);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(24), 109.2924);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(25), 109.1836);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(26), 109.0778);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(27), 108.9498);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(28), 108.4230);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(29), 108.0157);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(30), 107.9967);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(31), 108.0069);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(32), 108.2596);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(33), 108.4818);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(34), 108.9119);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(35), 109.6734);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(36), 110.4947);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(37), 111.1077);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(38), 111.4622);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(39), 111.6092);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(40), 111.5663);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(41), 111.5491);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(42), 111.5425);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(43), 111.5426);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(44), 111.5457);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(45), 111.5658);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(46), 111.5688);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(47), 111.5522);
            TaTestsUtils.AssertDecimalEquals(kama.GetValue(48), 111.5595);
        }
コード例 #27
0
ファイル: KAMAIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void kama()
        {
            ClosePriceIndicator closePrice = new ClosePriceIndicator(data);
            KAMAIndicator       kama       = new KAMAIndicator(closePrice, 10, 2, 30);

            Assert.AreEqual(109.2400M, kama.GetValue(9));
            Assert.AreEqual(109.24494010269916663279218767M, kama.GetValue(10));
            Assert.AreEqual(109.21649206276841440999776905M, kama.GetValue(11));
            Assert.AreEqual(109.11734972710342211716767785M, kama.GetValue(12));
            Assert.AreEqual(109.09810134973597420440184007M, kama.GetValue(13));
            Assert.AreEqual(109.08936998973940855209941847M, kama.GetValue(14));
            Assert.AreEqual(109.12403978156193935651315289M, kama.GetValue(15));
            Assert.AreEqual(109.13756204250952330536959206M, kama.GetValue(16));
            Assert.AreEqual(109.27686418803908486966927279M, kama.GetValue(17));
            Assert.AreEqual(109.43648216217104405819633459M, kama.GetValue(18));
            Assert.AreEqual(109.45685613079237171155132013M, kama.GetValue(19));
            Assert.AreEqual(109.46509570376888770557290122M, kama.GetValue(20));
            Assert.AreEqual(109.46116616313538190569128400M, kama.GetValue(21));
            Assert.AreEqual(109.39044547674048512711012086M, kama.GetValue(22));
            Assert.AreEqual(109.31652898432021430706081888M, kama.GetValue(23));
            Assert.AreEqual(109.29240858974055892248708537M, kama.GetValue(24));
            Assert.AreEqual(109.18361180648975107005053951M, kama.GetValue(25));
            Assert.AreEqual(109.07778091699571761795278118M, kama.GetValue(26));
            Assert.AreEqual(108.94981829788806808134609833M, kama.GetValue(27));
            Assert.AreEqual(108.42295278454941484155641075M, kama.GetValue(28));
            Assert.AreEqual(108.01574214187734934138252762M, kama.GetValue(29));
            Assert.AreEqual(107.99671169314084224582280455M, kama.GetValue(30));
            Assert.AreEqual(108.00685949100256851025453849M, kama.GetValue(31));
            Assert.AreEqual(108.25959109860509061377027655M, kama.GetValue(32));
            Assert.AreEqual(108.48177011138185589650375147M, kama.GetValue(33));
            Assert.AreEqual(108.91193568467020647487181761M, kama.GetValue(34));
            Assert.AreEqual(109.67339750026027475804243407M, kama.GetValue(35));
            Assert.AreEqual(110.49473967676459478770164988M, kama.GetValue(36));
            Assert.AreEqual(111.10765042335075159844801457M, kama.GetValue(37));
            Assert.AreEqual(111.46215852199056860124169871M, kama.GetValue(38));
            Assert.AreEqual(111.60915915140772719047221803M, kama.GetValue(39));
            Assert.AreEqual(111.56631600497264919232848064M, kama.GetValue(40));
            Assert.AreEqual(111.54914734893005196836010061M, kama.GetValue(41));
            Assert.AreEqual(111.54245421864753042795343867M, kama.GetValue(42));
            Assert.AreEqual(111.54261253765774928769157712M, kama.GetValue(43));
            Assert.AreEqual(111.54566829869648938056962958M, kama.GetValue(44));
            Assert.AreEqual(111.56582628748782023199328810M, kama.GetValue(45));
            Assert.AreEqual(111.56882879828005850001393743M, kama.GetValue(46));
            Assert.AreEqual(111.55223531573535020144693432M, kama.GetValue(47));
            Assert.AreEqual(111.55954365475172419965852203M, kama.GetValue(48));
        }
コード例 #28
0
ファイル: MMAIndicatorTest.cs プロジェクト: johndpope/TA4Net
        public void testAgainstExternalData()
        { // throws exception
            IIndicator <decimal> xlsClose = new ClosePriceIndicator(xls.getSeries());
            IIndicator <decimal> actualIndicator;

            actualIndicator = getIndicator(xlsClose, 1);
            //Assert.AreEqual(xls.getIndicator(1), actualIndicator);
            Assert.AreEqual(329.0M, actualIndicator.GetValue(actualIndicator.TimeSeries.GetEndIndex()));

            actualIndicator = getIndicator(xlsClose, 3);
            //Assert.AreEqual(xls.getIndicator(3), actualIndicator);
            Assert.AreEqual(327.29004419236330590585252094M, actualIndicator.GetValue(actualIndicator.TimeSeries.GetEndIndex()));

            actualIndicator = getIndicator(xlsClose, 13);
            //Assert.AreEqual(xls.getIndicator(13), actualIndicator);
            Assert.AreEqual(326.96964401585614734632198306M, actualIndicator.GetValue(actualIndicator.TimeSeries.GetEndIndex()));
        }
コード例 #29
0
        public void externalData()
        { // throws exception
            IIndicator <decimal> xlsClose = new ClosePriceIndicator(xls.getSeries());
            IIndicator <decimal> actualIndicator;

            actualIndicator = getIndicator(xlsClose, 1);
            //  Assert.AreEqual(xls.getIndicator(1), actualIndicator);
            Assert.AreEqual(329.0M, actualIndicator.GetValue(actualIndicator.TimeSeries.GetEndIndex()));

            actualIndicator = getIndicator(xlsClose, 3);
            //Assert.AreEqual(xls.getIndicator(3), actualIndicator);
            Assert.AreEqual(326.63333333333333333333333333M, actualIndicator.GetValue(actualIndicator.TimeSeries.GetEndIndex()));

            actualIndicator = getIndicator(xlsClose, 13);
            //Assert.AreEqual(xls.getIndicator(13), actualIndicator);
            Assert.AreEqual(327.78461538461538461538461538M, actualIndicator.GetValue(actualIndicator.TimeSeries.GetEndIndex()));
        }
コード例 #30
0
        public void Dpo()
        {
            var dpo       = new DpoIndicator(_series, 9);
            var cp        = new ClosePriceIndicator(_series);
            var sma       = new SmaIndicator(cp, 9);
            int timeShift = 9 / 2 + 1;

            for (int i = _series.Begin; i <= _series.End; i++)
            {
                TaTestsUtils.AssertDecimalEquals(dpo.GetValue(i), cp.GetValue(i).Minus(sma.GetValue(i - timeShift)));
            }

            TaTestsUtils.AssertDecimalEquals(dpo.GetValue(9), 0.111999);
            TaTestsUtils.AssertDecimalEquals(dpo.GetValue(10), -0.02);
            TaTestsUtils.AssertDecimalEquals(dpo.GetValue(11), 0.21142857142);
            TaTestsUtils.AssertDecimalEquals(dpo.GetValue(12), 0.169999999999999);
        }