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 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 TestTextCandleProviderInitialization() { using (var provider = new TextCandleProvider()) { Assert.IsTrue(provider.Initialize()); } }
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 TestMutations() { using (var provider = new TextCandleProvider()) { var gen = new GeneticsSelector <TextCandleProvider, BasicAlgorithm>(provider, 5, 30, 50); var mutatedInd = new float[] { 1, 2, 3, 4 }; gen.Mutate(mutatedInd); Assert.IsFalse(mutatedInd.SequenceEqual(new float[] { 1, 2, 3, 4 })); } }
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 TestParentsCross() { using (var provider = new TextCandleProvider()) { var gen = new GeneticsSelector <TextCandleProvider, BasicAlgorithm>(provider, 5, 30, 50); float[] child1; float[] child2; gen.Cross(new float[] { 1, 2, 3 }, new float[] { 4, 5, 6 }, out child1, out child2); Assert.IsTrue(child1.SequenceEqual(new float[] { 4, 2, 6 })); Assert.IsTrue(child2.SequenceEqual(new float[] { 1, 5, 3 })); gen.Cross(new float[] { 1 }, new float[] { 4, 1 }, out child1, out child2); Assert.IsNull(child1); Assert.IsNull(child2); } }
public void TestTextCandleProviderReadToEOF() { using (var provider = new TextCandleProvider()) { int num = 0; Candle lastCurrent = new Candle(); while (provider.MoveNext()) { Assert.IsTrue(provider.Current != lastCurrent); lastCurrent = provider.Current; num++; } Assert.IsTrue(num > 1); } }
public void TestReadCandleForBaseTextCandleProvider() { using (var provider = new TextCandleProvider()) { // <DATE>;<TIME>;<OPEN>;<HIGH>;<LOW>;<CLOSE>;<VOL> string exStr = "01.01.2017;7:7:7;1;2;3;4;5"; var candle = provider.GetCandle(exStr); Assert.AreEqual(candle, new Candle() { TimeStamp = new DateTime(2017, 1, 1, 7, 7, 7), Open = 1, High = 2, Low = 3, Close = 4, Volume = 5 }); } }
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)); } }