コード例 #1
0
        public void VarianceShouldBeZeroWhenTimeFrameIs1()
        {
            var variance = new VarianceIndicator(new ClosePriceIndicator(_data), 1);

            TaTestsUtils.AssertDecimalEquals(variance.GetValue(3), 0);
            TaTestsUtils.AssertDecimalEquals(variance.GetValue(8), 0);
        }
コード例 #2
0
        public void BollingerBandWidthUsingSmaAndStandardDeviation()
        {
            var sma = new SmaIndicator(_closePrice, 5);
            var standardDeviation = new StandardDeviationIndicator(_closePrice, 5);

            var bbmSma = new BollingerBandsMiddleIndicator(sma);
            var bbuSma = new BollingerBandsUpperIndicator(bbmSma, standardDeviation);
            var bblSma = new BollingerBandsLowerIndicator(bbmSma, standardDeviation);

            var bandwidth = new BollingerBandWidthIndicator(bbuSma, bbmSma, bblSma);

            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(0), 0.0);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(1), 36.3636);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(2), 66.6423);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(3), 60.2443);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(4), 71.0767);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(5), 69.9394);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(6), 62.7043);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(7), 56.0178);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(8), 27.683);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(9), 12.6491);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(10), 12.6491);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(11), 24.2956);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(12), 68.3332);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(13), 85.1469);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(14), 112.8481);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(15), 108.1682);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(16), 66.9328);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(17), 56.5194);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(18), 28.1091);
            TaTestsUtils.AssertDecimalEquals(bandwidth.GetValue(19), 32.5362);
        }
コード例 #3
0
        public void ShouldBeZeroWhenTimeFrameIs1()
        {
            var se = new StandardErrorIndicator(new ClosePriceIndicator(_data), 1);

            TaTestsUtils.AssertDecimalEquals(se.GetValue(1), 0);
            TaTestsUtils.AssertDecimalEquals(se.GetValue(3), 0);
        }
コード例 #4
0
        public void UsingTimeFrame5UsingClosePriceAndVolume()
        {
            var coef = new CorrelationCoefficientIndicator(_close, _volume, 5);

            Assert.IsTrue(coef.GetValue(0).NaN);

            TaTestsUtils.AssertDecimalEquals(coef.GetValue(1), 1);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(2), 0.8773);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(3), 0.9073);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(4), 0.9219);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(5), 0.9205);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(6), 0.4565);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(7), -0.4622);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(8), 0.05747);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(9), 0.1442);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(10), -0.1263);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(11), -0.5345);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(12), -0.7275);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(13), 0.1676);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(14), 0.2506);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(15), -0.2938);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(16), -0.3586);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(17), 0.1713);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(18), 0.9841);
            TaTestsUtils.AssertDecimalEquals(coef.GetValue(19), 0.9799);
        }
コード例 #5
0
 public void ConstantIndicator()
 {
     TaTestsUtils.AssertDecimalEquals(_multiplierIndicator.GetValue(10), "4.5");
     TaTestsUtils.AssertDecimalEquals(_multiplierIndicator.GetValue(1), "4.5");
     TaTestsUtils.AssertDecimalEquals(_multiplierIndicator.GetValue(0), "4.5");
     TaTestsUtils.AssertDecimalEquals(_multiplierIndicator.GetValue(30), "4.5");
 }
コード例 #6
0
        public void MeanDeviationShouldBeZeroWhenTimeFrameIs1()
        {
            var meanDeviation = new MeanDeviationIndicator(new ClosePriceIndicator(_data), 1);

            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(2), 0);
            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(7), 0);
        }
コード例 #7
0
        public void PercentBUsingSmaAndStandardDeviation()
        {
            var pcb = new PercentBIndicator(_closePrice, 5, Decimal.Two);

            Assert.IsTrue(pcb.GetValue(0).NaN);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(1), 0.75);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(2), 0.8244);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(3), 0.6627);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(4), 0.8517);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(5), 0.90328);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(6), 0.83);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(7), 0.6552);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(8), 0.5737);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(9), 0.1047);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(10), 0.5);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(11), 0.0284);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(12), 0.0344);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(13), 0.2064);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(14), 0.1835);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(15), 0.2131);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(16), 0.3506);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(17), 0.5737);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(18), 0.5);
            TaTestsUtils.AssertDecimalEquals(pcb.GetValue(19), 0.7673);
        }
コード例 #8
0
        public void StandardDeviationShouldBeZeroWhenTimeFrameIs1()
        {
            var sdv = new StandardDeviationIndicator(new ClosePriceIndicator(_data), 1);

            TaTestsUtils.AssertDecimalEquals(sdv.GetValue(3), 0);
            TaTestsUtils.AssertDecimalEquals(sdv.GetValue(8), 0);
        }
コード例 #9
0
 public void ConstantIndicator()
 {
     TaTestsUtils.AssertDecimalEquals(_constantIndicator.GetValue(0), "30.33");
     TaTestsUtils.AssertDecimalEquals(_constantIndicator.GetValue(1), "30.33");
     TaTestsUtils.AssertDecimalEquals(_constantIndicator.GetValue(10), "30.33");
     TaTestsUtils.AssertDecimalEquals(_constantIndicator.GetValue(30), "30.33");
 }
コード例 #10
0
        public void BollingerBandsLowerUsingSmaAndStandardDeviation()
        {
            var bbmSma            = new BollingerBandsMiddleIndicator(_sma);
            var standardDeviation = new StandardDeviationIndicator(_closePrice, _timeFrame);
            var bblSma            = new BollingerBandsLowerIndicator(bbmSma, standardDeviation);

            TaTestsUtils.AssertDecimalEquals(bblSma.K, 2);

            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(1), 0.5);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(2), 0.367);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(3), 1.367);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(4), 2.3905);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(5), 2.7239);
            TaTestsUtils.AssertDecimalEquals(bblSma.GetValue(6), 2.367);

            var bblSmAwithK = new BollingerBandsLowerIndicator(bbmSma, standardDeviation, Decimal.ValueOf("1.5"));

            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.K, 1.5);

            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(1), 0.75);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(2), 0.7752);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(3), 1.7752);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(4), 2.6262);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(5), 2.9595);
            TaTestsUtils.AssertDecimalEquals(bblSmAwithK.GetValue(6), 2.7752);
        }
コード例 #11
0
        public void UlcerIndexUsingTimeFrame14UsingIbmData()
        {
            var ulcer = new UlcerIndexIndicator(new ClosePriceIndicator(_ibmData), 14);

            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(0), 0);

            // From: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ulcer_index
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(26), 1.3047);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(27), 1.3022);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(28), 1.2156);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(29), 0.9967);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(30), 0.7257);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(31), 0.453);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(32), 0.4284);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(33), 0.4284);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(34), 0.4284);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(35), 0.4287);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(36), 0.5089);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(37), 0.6673);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(38), 0.9914);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(39), 1.0921);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(40), 1.3161);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(41), 1.5632);
            TaTestsUtils.AssertDecimalEquals(ulcer.GetValue(42), 1.7609);
        }
コード例 #12
0
        public void BollingerBandsUpperUsingSmaAndStandardDeviation()
        {
            var bbmSma            = new BollingerBandsMiddleIndicator(_sma);
            var standardDeviation = new StandardDeviationIndicator(_closePrice, _timeFrame);
            var bbuSma            = new BollingerBandsUpperIndicator(bbmSma, standardDeviation);

            TaTestsUtils.AssertDecimalEquals(bbuSma.K, 2);

            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(1), 2.5);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(2), 3.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(3), 4.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(4), 4.2761);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(5), 4.6094);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(6), 5.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(7), 5.2761);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(8), 5.633);
            TaTestsUtils.AssertDecimalEquals(bbuSma.GetValue(9), 4.2761);

            var bbuSmAwithK = new BollingerBandsUpperIndicator(bbmSma, standardDeviation, Decimal.ValueOf("1.5"));

            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.K, 1.5);

            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(1), 2.25);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(2), 3.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(3), 4.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(4), 4.0404);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(5), 4.3737);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(6), 5.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(7), 5.0404);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(8), 5.2247);
            TaTestsUtils.AssertDecimalEquals(bbuSmAwithK.GetValue(9), 4.0404);
        }
コード例 #13
0
        public void GetValue()
        {
            IList <Tick> ticks = new List <Tick>();

            ticks.Add(GenerateTick.From(1355.69, 2739.55));
            ticks.Add(GenerateTick.From(1325.51, 3119.46));
            ticks.Add(GenerateTick.From(1335.02, 3466.88));
            ticks.Add(GenerateTick.From(1313.72, 2577.12));
            ticks.Add(GenerateTick.From(1319.99, 2480.45));
            ticks.Add(GenerateTick.From(1331.85, 2329.79));
            ticks.Add(GenerateTick.From(1329.04, 2793.07));
            ticks.Add(GenerateTick.From(1362.16, 3378.78));
            ticks.Add(GenerateTick.From(1365.51, 2417.59));
            ticks.Add(GenerateTick.From(1374.02, 1442.81));
            TimeSeries series = GenerateTimeSeries.From(ticks);

            var nvi = new NviIndicator(series);

            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(0), 1000);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(1), 1000);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(2), 1000);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(3), 984.0452);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(4), 988.7417);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(5), 997.6255);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(6), 997.6255);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(7), 997.6255);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(8), 1000.079);
            TaTestsUtils.AssertDecimalEquals(nvi.GetValue(9), 1006.3116);
        }
コード例 #14
0
        public void ShouldBeZeroWhenTimeFrameIs1()
        {
            var covar = new CovarianceIndicator(_close, _volume, 1);

            TaTestsUtils.AssertDecimalEquals(covar.GetValue(3), 0);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(8), 0);
        }
コード例 #15
0
        public void UsingTimeFrame5UsingClosePriceAndVolume()
        {
            var covar = new CovarianceIndicator(_close, _volume, 5);

            TaTestsUtils.AssertDecimalEquals(covar.GetValue(0), 0);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(1), 26.25);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(2), 63.3333);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(3), 143.75);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(4), 156);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(5), 60.8);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(6), 15.2);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(7), -17.6);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(8), 4);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(9), 11.6);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(10), -14.4);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(11), -100.2);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(12), -70.0);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(13), 24.6);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(14), 35.0);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(15), -19.0);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(16), -47.8);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(17), 11.4);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(18), 55.8);
            TaTestsUtils.AssertDecimalEquals(covar.GetValue(19), 33.4);
        }
コード例 #16
0
        public void AverageDirectionalMovement()
        {
            var tick1 = GenerateTick.From(0, 0, 13, 7);
            var tick2 = GenerateTick.From(0, 0, 11, 5);
            var tick3 = GenerateTick.From(0, 0, 15, 3);
            var tick4 = GenerateTick.From(0, 0, 14, 2);
            var tick5 = GenerateTick.From(0, 0, 13, 0.2);

            IList <Tick> ticks = new List <Tick>();

            ticks.Add(tick1);
            ticks.Add(tick2);
            ticks.Add(tick3);
            ticks.Add(tick4);
            ticks.Add(tick5);

            var series  = GenerateTimeSeries.From(ticks);
            var admdown = new AverageDirectionalMovementDownIndicator(series, 3);

            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(1), 4d / 3);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(2), 4d / 3 * 2d / 3);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(3), (4d / 3 * 2d / 3) * 2d / 3 + 1d / 3);
            TaTestsUtils.AssertDecimalEquals(admdown.GetValue(4), ((4d / 3 * 2d / 3) * 2d / 3 + 1d / 3) * 2d / 3 + 1.8 * 1d / 3);
        }
コード例 #17
0
        public void EmaUsingTimeFrame10UsingClosePrice()
        {
            var ema = new EmaIndicator(new ClosePriceIndicator(_data), 10);

            TaTestsUtils.AssertDecimalEquals(ema.GetValue(9), 63.6536);
            TaTestsUtils.AssertDecimalEquals(ema.GetValue(10), 63.2312);
            TaTestsUtils.AssertDecimalEquals(ema.GetValue(11), 62.9182);
        }
コード例 #18
0
        public void ZlemaUsingTimeFrame10UsingClosePrice()
        {
            var zlema = new ZlemaIndicator(new ClosePriceIndicator(_data), 10);

            TaTestsUtils.AssertDecimalEquals(zlema.GetValue(9), 11.9091);
            TaTestsUtils.AssertDecimalEquals(zlema.GetValue(10), 8.8347);
            TaTestsUtils.AssertDecimalEquals(zlema.GetValue(11), 5.7739);
        }
コード例 #19
0
        public void StochasticOscilatorKParam14()
        {
            var sof = new StochasticOscillatorKIndicator(_data, 14);

            TaTestsUtils.AssertDecimalEquals(sof.GetValue(0), 313 / 3.5);
            TaTestsUtils.AssertDecimalEquals(sof.GetValue(12), 1000 / 10.81);
            TaTestsUtils.AssertDecimalEquals(sof.GetValue(13), 57.8168);
        }
コード例 #20
0
ファイル: CashFlowTest.cs プロジェクト: jasonmnemonic/TA4N
        public void CashFlowValueWithNoTrades()
        {
            TimeSeries sampleTimeSeries = GenerateTimeSeries.From(3d, 2d, 5d, 4d, 7d, 6d, 7d, 8d, 5d, 6d);
            var        cashFlow         = new CashFlow(sampleTimeSeries, new TradingRecord());

            TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(4), 1);
            TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(7), 1);
            TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(9), 1);
        }
コード例 #21
0
        public void ValueLessThenTimeFrame()
        {
            var wr = new WilliamsRIndicator(new ClosePriceIndicator(_data), 100, new MaxPriceIndicator(_data), new MinPriceIndicator(_data));

            TaTestsUtils.AssertDecimalEquals(wr.GetValue(0), -100d * (0.12 / 0.21));
            TaTestsUtils.AssertDecimalEquals(wr.GetValue(1), -100d * (0.07 / 0.21));
            TaTestsUtils.AssertDecimalEquals(wr.GetValue(2), -100d * (0.13 / 0.36));
            TaTestsUtils.AssertDecimalEquals(wr.GetValue(3), -100d * (0.18 / 0.36));
        }
コード例 #22
0
        public void WilliamsRUsingTimeFrame10UsingClosePrice()
        {
            var wr = new WilliamsRIndicator(new ClosePriceIndicator(_data), 10, new MaxPriceIndicator(_data), new MinPriceIndicator(_data));

            TaTestsUtils.AssertDecimalEquals(wr.GetValue(9), -4.0816);
            TaTestsUtils.AssertDecimalEquals(wr.GetValue(10), -11.7647);
            TaTestsUtils.AssertDecimalEquals(wr.GetValue(11), -8.9286);
            TaTestsUtils.AssertDecimalEquals(wr.GetValue(12), -10.5263);
        }
コード例 #23
0
ファイル: CashFlowTest.cs プロジェクト: jasonmnemonic/TA4N
        public void ReallyLongCashFlow()
        {
            const int  size             = 1000000;
            TimeSeries sampleTimeSeries = GenerateTimeSeries.From(Enumerable.Repeat((Tick)GenerateTick.From(10), size).ToList());
            var        tradingRecord    = new TradingRecord(Order.BuyAt(0), Order.SellAt(size - 1));
            var        cashFlow         = new CashFlow(sampleTimeSeries, tradingRecord);

            TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(size - 1), 1);
        }
コード例 #24
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));
        }
コード例 #25
0
        public void GetValueWithCacheLengthIncrease()
        {
            var data = new double[200];

            TaTestsUtils.ArraysFill(data, 10);
            var sma = new SmaIndicator(new ClosePriceIndicator(GenerateTimeSeries.From(data)), 100);

            TaTestsUtils.AssertDecimalEquals(sma.GetValue(105), 10);
        }
コード例 #26
0
 public void IndicatorShouldRetrieveTickVariation()
 {
     TaTestsUtils.AssertDecimalEquals(_variationIndicator.GetValue(0), 1);
     for (var i = 1; i < 10; i++)
     {
         var previousTickClosePrice = _timeSeries.GetTick(i - 1).ClosePrice;
         var currentTickClosePrice  = _timeSeries.GetTick(i).ClosePrice;
         Assert.AreEqual(_variationIndicator.GetValue(i), currentTickClosePrice.DividedBy(previousTickClosePrice));
     }
 }
コード例 #27
0
ファイル: CashFlowTest.cs プロジェクト: jasonmnemonic/TA4N
        public void CashFlowBuyWithOnlyOneTrade()
        {
            TimeSeries sampleTimeSeries = GenerateTimeSeries.From(1d, 2d);
            var        tradingRecord    = new TradingRecord(Order.BuyAt(0), Order.SellAt(1));

            var cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);

            TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(0), 1);
            TaTestsUtils.AssertDecimalEquals(cashFlow.GetValue(1), 2);
        }
コード例 #28
0
 public void GetValue()
 {
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(0), "4");
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(1), "7");
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(2), "9");
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(3), "11.53");
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(4), "21.87");
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(5), "-30");
     TaTestsUtils.AssertDecimalEquals(_sumIndicator.GetValue(6), "-1321");
 }
コード例 #29
0
 public void GetValue()
 {
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(0), "8");
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(1), "6");
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(2), "5");
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(3), "3.47");
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(4), "0.13");
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(5), "0");
     TaTestsUtils.AssertDecimalEquals(_differenceIndicator.GetValue(6), "-4");
 }
コード例 #30
0
        public void MeanDeviationUsingTimeFrame5UsingClosePrice()
        {
            var meanDeviation = new MeanDeviationIndicator(new ClosePriceIndicator(_data), 5);

            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(2), 2.44444444444444);
            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(3), 2.5);
            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(7), 2.16);
            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(8), 2.32);
            TaTestsUtils.AssertDecimalEquals(meanDeviation.GetValue(9), 2.72);
        }