Example #1
0
        public void TestAccAggregatorProfits()
        {
            var acc    = new TestAccAgregator();
            var candle = new Candle()
            {
                Close = 1
            };

            acc.Buy(5, candle);
            candle.Close = 10;
            acc.Close(candle);
            Assert.AreEqual(45, acc.Profits[0]);
            candle.Close = 5;
            acc.Sell(1, candle);
            candle.Close = 3;
            acc.Pass(candle);
            candle.Close = 2;
            acc.Sell(2, candle);
            Assert.AreEqual(3, acc.Profits[1]);
            candle.Close = 3;
            acc.Buy(3, candle);
            Assert.AreEqual(-3, acc.Profits[2]);
            Assert.AreEqual(15, acc.MeanProfit);
            Assert.AreEqual((float)2 / 3, acc.SuccessRatio);
            Assert.AreEqual(-3, acc.MeanNegativeProfit);
            Assert.AreEqual(24, acc.MeanPositiveProfit);
        }
Example #2
0
 public TestAccAgregator Calculate(float[] parameters, out IAlgorithm alg)
 {
     using (var mc = new MemoryCache <T>(_cache))
     {
         alg = (IAlgorithm)Activator.CreateInstance(typeof(T1));
         var acc = new TestAccAgregator();
         alg.Initialize(parameters);
         Candle curr = mc.Current;
         while (mc.MoveNext())
         {
             var answer = alg.Check(mc.Current);
             if (answer == AlgResult.Buy)
             {
                 acc.Buy(1 - acc.Assets, mc.Current);
             }
             if (answer == AlgResult.Sell)
             {
                 acc.Sell(1 + acc.Assets, mc.Current);
             }
             if (answer == AlgResult.Exit)
             {
                 acc.Close(mc.Current);
             }
             curr = mc.Current;
         }
         acc.Close(curr);
         return(acc);
     }
 }
Example #3
0
        public void TestAccAggregatorSharpIndex()
        {
            var acc    = new TestAccAgregator();
            var candle = new Candle()
            {
                TimeStamp = new DateTime(2017, 1, 2, 15, 0, 0),
                Close     = 1
            };

            acc.Pass(candle);
            Assert.AreEqual(0, acc.Balance);
            Assert.AreEqual(0, acc.SharpIndex);
            candle.TimeStamp = new DateTime(2017, 2, 1, 15, 0, 0);
            acc.Buy(1, candle);
            Assert.AreEqual(0, acc.SharpIndex);
            candle.TimeStamp = new DateTime(2017, 2, 2, 15, 0, 0);
            candle.Close     = 10;
            acc.Sell(2, candle);
            candle.TimeStamp = new DateTime(2017, 3, 2, 15, 0, 0);
            candle.Close     = 12;
            acc.Buy(1, candle);
            candle.TimeStamp = new DateTime(2017, 4, 1, 14, 0, 0);
            candle.Close     = 15;
            acc.Close(candle);
            Assert.AreEqual(0.5, acc.SuccessRatio);
            Assert.IsTrue(Math.Abs(3.5 / (float)Math.Sqrt((3.5 - 9) * (3.5 - 9) + (3.5 + 2) * (3.5 + 2)) - acc.SharpIndex) < 10e-3);
        }
 public void TestBasicAlgProfit()
 {
     using (var provider = new TextCandleProvider())
     {
         provider.SetTextParams("data/si-9-17.dat", ';');
         var alg = new BasicAlgorithm(5, 5);
         var acc = new TestAccAgregator();
         while (provider.MoveNext())
         {
             var answer = alg.Check(provider.Current);
             if (answer == FortsRobotLib.AlgResult.Buy)
             {
                 acc.Buy(1 - acc.Assets, provider.Current);
             }
             if (answer == FortsRobotLib.AlgResult.Sell)
             {
                 acc.Sell(1 + acc.Assets, provider.Current);
             }
             if (answer == FortsRobotLib.AlgResult.Exit)
             {
                 acc.Close(provider.Current);
             }
         }
         acc.Close(provider.Current);
         Assert.IsTrue(acc.Balance > 0);
     }
 }
 public void TestGuppiAlgData()
 {
     using (var provider = new TextCandleProvider())
     {
         provider.SetTextParams(@"data\si-9-17.dat", ';');
         var alg = new GuppiAlgorithm(4, 6, 9, 13, 31, 36, 41, 46, 51, 61);
         var acc = new TestAccAgregator();
         for (var i = 0; i < 61; i++)
         {
             provider.MoveNext();
             var res = alg.Check(provider.Current);
             Assert.IsTrue(res == AlgResult.Exit && !alg.Data.Last().Any());
         }
         while (provider.MoveNext())
         {
             var answer = alg.Check(provider.Current);
             if (answer == FortsRobotLib.AlgResult.Buy)
             {
                 acc.Buy(1 - acc.Assets, provider.Current);
             }
             if (answer == FortsRobotLib.AlgResult.Sell)
             {
                 acc.Sell(1 + acc.Assets, provider.Current);
             }
             if (answer == FortsRobotLib.AlgResult.Exit)
             {
                 acc.Close(provider.Current);
             }
             Assert.IsTrue(alg.Data.Last().Length == 10 + 10 + 8 + 1);
         }
     }
 }
Example #6
0
        public void TestAccAggregatorBuySell()
        {
            var acc    = new TestAccAgregator();
            var candle = new Candle()
            {
                Close = 1
            };

            acc.Buy(1, candle);
            candle.Close = 0;
            acc.Sell(1, candle);
            Assert.AreEqual(acc.Balance, -1);
            Assert.AreEqual(acc.Assets, 0);
        }
Example #7
0
        public void TestAccAggregatorReset()
        {
            var acc    = new TestAccAgregator();
            var candle = new Candle()
            {
                Close = 1
            };

            acc.Buy(1, candle);
            Assert.AreEqual(acc.Assets, 1);
            acc.Reset();
            Assert.AreEqual(acc.Balance, 0);
            Assert.AreEqual(acc.Data.Length, 0);
            Assert.AreEqual(acc.Assets, 0);
        }
Example #8
0
        public void TestAccAggregatorBuySellClose()
        {
            var acc    = new TestAccAgregator();
            var candle = new Candle()
            {
                Close = 1
            };

            acc.Buy(5, candle);
            candle.Close = 10;
            acc.Pass(candle);
            candle.Close = 7;
            acc.Sell(3, candle);
            candle.Close = 5;
            acc.Pass(candle);
            candle.Close = 1;
            acc.Sell(10, candle);
            acc.Close(candle);
            Assert.AreEqual(acc.Balance, 18);
            Assert.AreEqual(acc.Data.Length, 6);
            Assert.AreEqual(acc.Assets, 0);
        }
Example #9
0
        public void TestAccAggregatorBuyAndHold()
        {
            var acc    = new TestAccAgregator();
            var candle = new Candle()
            {
                Close = 1
            };

            acc.Pass(candle);
            Assert.AreEqual(acc.Balance, 0);
            acc.Buy(1, candle);
            Assert.AreEqual(acc.Balance, 0);
            candle.Close = 2;
            acc.Pass(candle);
            Assert.AreEqual(acc.Balance, 1);
            candle.Close = 0;
            acc.Pass(candle);
            Assert.AreEqual(acc.Balance, -1);
            candle.Close = 1;
            acc.Close(candle);
            Assert.AreEqual(acc.Balance, 0);
            Assert.AreEqual(acc.Data.Length, 5);
        }