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 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 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 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)); } }