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 TestProviderMemoryCache() { var candles = new List <Candle>(); using (var p1 = new TextCandleProvider()) { p1.SetTextParams(@"data\si-9-17.dat"); Assert.IsTrue(p1.Initialize()); candles.Add(p1.Current); while (p1.MoveNext()) { candles.Add(p1.Current); } } var p = new TextCandleProvider(); p.SetTextParams(@"data\si-9-17.dat"); // p gets automatically disposed using (var mc = new MemoryCache <TextCandleProvider>(p)) { var num = 0; while (mc.MoveNext()) { Assert.AreEqual(candles[num], mc.Current); num++; } mc.Reset(); mc.MoveNext(); Assert.AreEqual(candles[0], mc.Current); } }
public void TestBasicAlgMatrix() { using (var provider = new TextCandleProvider()) { var alg = new BasicAlgorithm(13, 12, 11, 10, 9, 8, 7, 6, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13); provider.SetTextParams("data/si-9-17.dat", ';'); while (provider.MoveNext() && provider.Current.TimeStamp != new DateTime(2017, 6, 1, 15, 0, 0)) { } Assert.IsTrue(provider.Current.Close == 58054); while (provider.MoveNext() && provider.Current.TimeStamp != new DateTime(2017, 6, 8, 11, 0, 0)) { alg.Check(provider.Current); } alg.Check(provider.Current); Assert.IsTrue(provider.Current.Close == 58204); using (var reader = new StreamReader("../../data/basic_data.dat")) { while (provider.MoveNext() && provider.Current.TimeStamp != new DateTime(2017, 6, 10, 0, 0, 0)) { var answer = alg.Check(provider.Current); var data = alg.Data.Last(); var values = reader.ReadLine().Split(';').ToArray(); for (var i = 3; i < 12; i++) { Assert.AreEqual(Math.Truncate((data[i - 2])), Math.Truncate(float.Parse(values[i], NumberStyles.Any, CultureInfo.InvariantCulture))); } Assert.AreEqual(Math.Truncate(float.Parse(values[2], NumberStyles.Any, CultureInfo.InvariantCulture)), Math.Truncate(data[0])); System.Diagnostics.Trace.WriteLine(answer); } } Assert.IsTrue(provider.Current.Close == 58220); } }
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); } } }
public void TestWaitForGeneticsSelection() { using (var provider = new TextCandleProvider()) { provider.SetTextParams(@"data\si-9-17.dat"); var gen = new GeneticsSelector <TextCandleProvider, BasicAlgorithm>(new MemoryCache <TextCandleProvider>(provider), 5, 30, 4); gen.Select(2); gen.Wait(); var bestResults = gen.GetBestResults(); Assert.AreEqual(2, gen.PopulationIndex); } }
public void TestSingleCalculation() { var p = new TextCandleProvider(); p.SetTextParams(@"data\si-9-17.dat"); var calc = new Calculator <TextCandleProvider, BasicAlgorithm>(p, 2); IAlgorithm alg; var result = calc.Calculate(new float[] { 13, 12, 11, 10, 9, 8, 7, 6, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, out alg); Assert.AreEqual(result.Balance, 2379); Assert.AreEqual(result.Assets, 0); Assert.IsTrue(alg.Data.Length > 0); }
public void TestCopyMemoryCache() { var p = new TextCandleProvider(); p.SetTextParams(@"data\si-9-17.dat"); using (var mc = new MemoryCache <TextCandleProvider>(p)) { mc.MoveNext(); using (var mc1 = new MemoryCache <TextCandleProvider>(mc)) { Assert.IsTrue(mc1.Current == default(Candle)); mc1.MoveNext(); Assert.AreEqual(mc.Current, mc1.Current); mc1.MoveNext(); Assert.AreNotEqual(mc.Current, mc1.Current); mc.MoveNext(); Assert.AreEqual(mc.Current, mc1.Current); } } }
public void TestRandomPopulation() { using (var provider = new TextCandleProvider()) { provider.SetTextParams("data/si-9-17.dat"); var gen = new GeneticsSelector <TextCandleProvider, BasicAlgorithm>(provider, 5, 30, 50, generationSize: 100); var randomPopulation = gen.GenerateRandomPopulation(); Assert.IsTrue(randomPopulation.Length == 100); Assert.IsTrue(randomPopulation.All(o => o.Length == 50)); foreach (var ind in randomPopulation) { foreach (var p in ind) { Assert.IsTrue(p >= 5 && p <= 30); } } Assert.IsFalse(randomPopulation.First() .SequenceEqual(randomPopulation.Last())); } }
public void TestParallelCalculations() { var p = new TextCandleProvider(); p.SetTextParams(@"data\si-9-17.dat"); var calc = new Calculator <TextCandleProvider, BasicAlgorithm>(p, 4); calc.AddParamsForCalculation(new float[] { 13, 12, 11, 10, 9, 8, 7, 6, 5 }); calc.AddParamsForCalculation(new float[] { 5, 5 }); // just pass calc.Wait(); calc.CalculateAsync(); calc.Wait(); Assert.AreEqual(2, calc.Results.Length); Assert.AreNotEqual(calc.Results.First().Balance, calc.Results.Last().Balance); calc.Reset(); calc.AddParamsForCalculation(new float[] { 10, 20, 30 }); calc.AddParamsForCalculation(new float[] { 5, 5 }); calc.CalculateAsync(); calc.Wait(); Assert.AreEqual(2, calc.Results.Length); }
public void TestBasicAlgDataIntegrity() { using (var provider = new TextCandleProvider()) { provider.SetTextParams("data/si-9-17.dat", ';'); while (provider.MoveNext()) { var curr = provider.Current; if (curr.TimeStamp == new DateTime(2017, 7, 13, 13, 0, 0)) { Assert.IsTrue(curr.Open == 61036 && curr.Close == 60804 && curr.High == 61049 && curr.Low == 60785); } if (curr.TimeStamp == new DateTime(2017, 6, 14, 17, 0, 0)) { Assert.IsTrue(curr.Open == 58120 && curr.Close == 58115 && curr.High == 58126 && curr.Low == 58016); } if (curr.TimeStamp == new DateTime(2017, 7, 14, 19, 0, 0)) { Assert.IsTrue(curr.Open == 60076 && curr.Close == 59940 && curr.High == 60109 && curr.Low == 59940); } } Assert.IsTrue(provider.Current.TimeStamp > new DateTime(2017, 8, 2)); } }