public void TestForwardCodeIndeier() { string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataPackage_Code dataPackage = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, endDate); ForwardReferedPeriods referedPeriods = new ForwardReferedPeriods(); referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Minute); referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_5Minute); referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_15Minute); referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Hour); referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Day); referedPeriods.UseTickData = true; referedPeriods.UseTimeLineData = true; printLine.Clear(); DataForForward_Code data1 = new DataForForward_Code(dataPackage, referedPeriods); DataForForward_CodeIndeier indeier = new DataForForward_CodeIndeier(data1); int len = data1.GetMainKLineData().Length; for (int i = 0; i < len; i++) { IKLineBar bar = data1.GetMainKLineData().GetBar(i); Print(bar, indeier.GetFinishedBarsRelativeToMainKLine(i), data1); } AssertUtils.AssertEqual_List("forwardcodeindeier", GetType(), printLine); }
private void AssertText(string code, int start, int end, string fileName) { List <string> list_OnBar = new List <string>(); IDataPackage_Code datapackage = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, end, 0, 0); IKLineData_Extend klineData = datapackage.GetKLineData(KLinePeriod.KLinePeriod_1Minute); ITickData tickData = datapackage.GetTickData(start); KLineToTickIndeier indeier = new KLineToTickIndeier(tickData, klineData); int lastBarPos; for (int i = 0; i < tickData.Length; i++) { list_OnBar.Add("tick:" + tickData.GetBar(i)); Console.WriteLine("tick:" + tickData.GetBar(i)); int pos = indeier.GetKLineBarPosIfFinished(i, out lastBarPos); if (pos >= 0) { list_OnBar.Add(klineData.Period + ":" + klineData.GetBar(pos)); Console.WriteLine(klineData.Period + ":" + klineData.GetBar(pos)); for (int m = pos + 1; m <= lastBarPos; m++) { list_OnBar.Add(klineData.Period + ":" + klineData.GetBar(m)); Console.WriteLine(klineData.Period + ":" + klineData.GetBar(m)); //lastBarPos = 1; } } } AssertUtils.AssertEqual_List(fileName, GetType(), list_OnBar); }
public void TestKLineDataForward_Tick() { printStrs_Forward_Tick.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar; klineDataForward.OnTick += KlineDataForward_OnTick; DateTime prevtime = DateTime.Now; while (klineDataForward.Forward()) { } DateTime time = DateTime.Now; TimeSpan span = time.Subtract(prevtime); Console.WriteLine(span.Minutes * 60 * 1000 + span.Seconds * 1000 + span.Milliseconds); //ITimeLineData timeLineData = klineDataForward.GetTimeLineData(); //for(int i = 0; i < timeLineData.Length; i++) //{ // ITimeLineBar timeLineBar = timeLineData.GetBar(i); // Console.WriteLine(timeLineBar); //} AssertUtils.AssertEqual_List("forward_tick", GetType(), printStrs_Forward_Tick); printStrs_Forward_Tick.Clear(); }
public void TestTrade() { string code = "RB1710"; int startDate = 20170601; int endDate = 20170603; StrategyReferedPeriods referedPeriods = new StrategyReferedPeriods(); referedPeriods.UseTickData = false; referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_1Minute); referedPeriods.UsedKLinePeriods.Add(KLinePeriod.KLinePeriod_5Minute); StrategyForwardPeriod forwardPeriod = new StrategyForwardPeriod(false, KLinePeriod.KLinePeriod_1Minute); StrategyArguments_CodePeriod strategyCodePeriod = new StrategyArguments_CodePeriod(code, startDate, endDate, referedPeriods, forwardPeriod); IStrategyExecutor_Single executor = StrategyCenter.Default.GetStrategyExecutorFactory().CreateExecutor_History(strategyCodePeriod); StrategyAbstract strategy = (StrategyAbstract)StrategyGetter.GetStrategy(typeof(MockStrategy_Trade)); executor.Strategy = strategy; executor.Run(); StrategyTrader_History trader = ((StrategyTrader_History)strategy.StrategyHelper.Trader); IList <TradeInfo> tradeInfos = trader.Account.CurrentTradeInfo; AssertUtils.PrintLineList((IList)tradeInfos); AssertUtils.AssertEqual_List("StrategyTrade", GetType(), tradeInfos); Assert.AreEqual(96250, trader.Account.Asset); //Assert.AreEqual(98870, trader.Account.Asset); //IList<OrderInfo> orderInfos = strategy.StrategyOperator.Trader.CurrentOrderInfo; //for (int i = 0; i < tradeInfos.Count; i++) //{ // Console.WriteLine(tradeInfos[i]); //} //Console.WriteLine(strategy.StrategyOperator.Trader.OwnerTrader.Account.Asset); }
public void TestReadMainContract() { IDataReader dataReader = TestDataCenter.Instance.DataReader; IList <MainContractInfo> contracts = dataReader.MainContractReader.GetMainContractInfos("RB", 20160101, 20170101); //AssertUtils.PrintLineList((IList)contracts); AssertUtils.AssertEqual_List("MainContract", GetType(), contracts); }
public void TestGetAllCodes() { List <CodeInfo> codes = CsvUtils_Code.Load(TestCaseManager.GetTestCasePath(GetType(), "Codes")); CacheUtils_CodeInfo cache = new CacheUtils_CodeInfo(codes); List <CodeInfo> newcodes = cache.GetAllCodes(); AssertUtils.AssertEqual_List("Codes", GetType(), newcodes); }
public void TestGetDataCenter() { string filePath = TestCaseManager.GetTestCasePath(GetType(), "datacenter.config"); DataCenter dataCenter = DataCenterManager.Create(filePath).GetDataCenterByUri("file:/E:/FUTURES/MOCKDATACENTER/"); List <CodeInfo> instruments = dataCenter.DataReader.CodeReader.GetAllCodes(); AssertUtils.PrintLineList(instruments); AssertUtils.AssertEqual_List("instruments", GetType(), instruments); }
public void TestIndeier() { List <string> list_OnBar = new List <string>(); string code = "RB1710"; int start = 20170601; int end = 20170603; AssertForwardData(code, start, end, list_OnBar); AssertUtils.AssertEqual_List("ForwardDataIndeier", GetType(), list_OnBar); }
public void TestGetAllCodesByVariety() { List <CodeInfo> codes = CsvUtils_Code.Load(TestCaseManager.GetTestCasePath(GetType(), "Codes")); CacheUtils_CodeInfo cache = new CacheUtils_CodeInfo(codes); List <CodeInfo> newcodes = cache.GetCodesByCatelog("m", 20160101); //AssertUtils.PrintLineList(newcodes); AssertUtils.AssertEqual_List("Codes_M_20160101", GetType(), newcodes); }
public void TestKLineToKLine() { list_OnBar.Clear(); string code = "RB1710"; int start = 20170601; int end = 20170603; AssertKLineToKLine(code, start, end, list_OnBar); AssertUtils.AssertEqual_List("forward_kline", GetType(), list_OnBar); }
private void AssertDaySplitter(string code, int start, int end, KLinePeriod period, string fileName) { CacheUtils_TradingTime cache = GetTradingSessionCache(code); IKLineData klineData = MockDataLoader.GetKLineData(code, start, end, period); List <SplitterResult> results = DaySplitter.Split(klineData, cache); AssertUtils.AssertEqual_List <SplitterResult>(fileName, GetType(), results); //AssertUtils.PrintKLineData(klineData); //AssertUtils.PrintLineList(results); }
public void TestGetAllInstruments() { IDataReader dataReader = DataReaderFactory.CreateDataReader(DataCenterUri.URI); List <CodeInfo> instruments = dataReader.CodeReader.GetAllCodes(); AssertUtils.PrintLineList(instruments); AssertUtils.AssertEqual_List("instruments", GetType(), instruments); CodeInfo instrument = dataReader.CodeReader.GetCodeInfo("m05"); Assert.AreEqual("M05", instrument.Code); Assert.AreEqual("豆粕05", instrument.Name); Assert.AreEqual("M", instrument.Catelog); }
public void TestRunStrategy() { string code = "rb1710"; int start = 20170601; int end = 20170603; IStrategyExecutor_Single executor = StrategyTestUtils.CreateExecutor_CodePeriod(code, start, end); MockStrategy strategy = new MockStrategy(); executor.Strategy = strategy; //executor.Execute(); executor.Run(); //AssertUtils.PrintLineList(strategy.PrintData); AssertUtils.AssertEqual_List("executorhistory", GetType(), strategy.PrintData); }
public void TestTradingDaySaveLoad() { string path = TestCaseManager.GetTestCasePath(GetType(), "output_TradingDay"); List <int> tradingDays = MockDataLoader.GetAllTradingDays(); TradingDayStore_File store = new TradingDayStore_File(path); store.Save(tradingDays); TradingDayStore_File newstore = new TradingDayStore_File(path); List <int> tradingDays2 = newstore.Load(); AssertUtils.AssertEqual_List(tradingDays, tradingDays2); File.Delete(path); }
public void TestInstrumentsSaveLoad() { string path = TestCaseManager.GetTestCasePath(GetType(), "CsvUtils_Instruments"); List <CodeInfo> instruments = CsvUtils_Code.Load(path); string outputPath = TestCaseManager.GetTestCasePath(GetType(), "Instruments_Output.csv"); CsvUtils_Code.Save(outputPath, instruments); List <CodeInfo> newInstruments = CsvUtils_Code.Load(outputPath); AssertUtils.AssertEqual_List(instruments, newInstruments); //TestCaseManager.SaveTestCaseFile(GetType(),) //List<InstrumentInfo> instruments = MockDataLoader.GetAllInstruments(); //AssertUtils.AssertEqual_List("CsvUtils_Instruments", GetType(), instruments); }
public void TestGetTradingSessionDetail() { string pluginPath = ScConfig.Instance.ScPath; DataLoader_Variety dataLoader_Instrument = new DataLoader_Variety(pluginPath); DataLoader_TradingSessionDetail dataLoader = new DataLoader_TradingSessionDetail(pluginPath, dataLoader_Instrument); List <double[]> tradingSessionDetail = dataLoader.GetTradingTime("m1005", 20100104); AssertUtils.AssertEqual_List <double[]>("tradingsessiondetail_normal", GetType(), tradingSessionDetail); tradingSessionDetail = dataLoader.GetTradingTime("rb1005", 20100106); AssertUtils.AssertEqual_List <double[]>("tradingsessiondetail_sqearly", GetType(), tradingSessionDetail); tradingSessionDetail = dataLoader.GetTradingTime(20100104); AssertUtils.PrintLineList(tradingSessionDetail); }
public void TestKLineDataForward_OnBar() { list_OnBar.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; KLineDataForward_BigPeriod klineDataForward = GetDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar; AddToList(list_OnBar, klineDataForward); while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_bigperiod", GetType(), list_OnBar); }
public void TestKLineDataForward_OnBar() { list_OnBar.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = GetDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar; list_OnBar.Add(KLinePeriod.KLinePeriod_1Minute + ":" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute)); Console.WriteLine(KLinePeriod.KLinePeriod_1Minute + ":" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute)); while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_kline", GetType(), list_OnBar); }
public void TestBiaoPuYongHua() { IDataProvider dataProvider = new DataProvider_BiaoPuYongHua(DataUpdateConst.SRCDATAPATH_BIAOPUYONGHUA, DataUpdateConst.PLUGINPATH); List <int> tradingDays = dataProvider.GetNewTradingDays(); AssertUtils.AssertEqual_List("tradingdays", GetType(), tradingDays); //AssertUtils.PrintLineList(tradingDays); List <CodeInfo> codes = dataProvider.GetNewCodes(); AssertUtils.PrintLineList(codes); AssertUtils.AssertEqual_List("codes", GetType(), codes); ITickData tickData = dataProvider.LoadTickData("A1005", 20100105); //AssertUtils.PrintTickData(tickData); AssertUtils.AssertEqual_TickData("TickData_A1005_20100105", GetType(), tickData); }
public void TestForward_TimeLineData() { printStrs_Forward_TimeLine.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, start, endDate, true, true, new KLinePeriod[] { KLinePeriod.KLinePeriod_1Minute }); klineDataForward.OnTick += KlineDataForward_OnTick; DateTime prevtime = DateTime.Now; while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_tick_timeline", GetType(), printStrs_Forward_TimeLine); printStrs_Forward_TimeLine.Clear(); }
public void TestKLineDataForward_Tick_OnBar() { string code = "RB1710"; int start = 20170601; int endDate = 20170603; printStrs_Forward_TimeInfo_OnBar.Clear(); IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar2; while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_tick_onbar", GetType(), printStrs_Forward_TimeInfo_OnBar); printStrs_Forward_TimeInfo_OnBar.Clear(); }
public void TestForwardTimeInfo_OnTick() { string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); //klineDataForward.OnBar += KlineDataForward_OnBar1; ; //klineDataForward.OnTick += KlineDataForward_OnTick; klineDataForward.OnTick += KlineDataForward_OnTick1; printStrs_Forward_TimeInfo_OnTick.Clear(); while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_tick_timeinfo", GetType(), printStrs_Forward_TimeInfo_OnTick); printStrs_Forward_TimeInfo_OnTick.Clear(); }
public void TestKLineDataForward_Minute() { string code = "RB1710"; int start = 20170601; int endDate = 20170603; KLineDataForward_BigPeriod klineDataForward = GetDataForward(code, start, endDate); List <string> list = new List <string>(); //Print(klineDataForward); AddToList(list, klineDataForward); while (klineDataForward.Forward()) { //Print(klineDataForward); AddToList(list, klineDataForward); } AssertUtils.AssertEqual_List("forward_bigperiod", GetType(), list); }
public void TestExecuteStrategy_MA() { string code = "rb1710"; int start = 20170601; int end = 20170603; IStrategyExecutor_Single executor = StrategyTestUtils.CreateExecutor_CodePeriod(code, start, end); MockStrategy_Ma strategy = new MockStrategy_Ma(); executor.Strategy = strategy; executor.Run(); List <float> floats = strategy.MAList; IDataPackage_Code dataPackage = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, end); IKLineData_Extend klineData = dataPackage.GetKLineData(KLinePeriod.KLinePeriod_1Minute); List <float> floats2 = KLineDataUtils.MaList(klineData, klineData.BarPos, klineData.Length - 1, 5); for (int i = 0; i < floats.Count; i++) { Console.WriteLine(floats[i] + "," + floats2[i]); } AssertUtils.AssertEqual_List(floats2, floats); }
public void TestLoadDaily() { //string srcDataPath = @"E:\FUTURES\CSV\TICK_DAILY\"; //string pluginPath = @"D:\SCWORK\DEV\SC2\bin\Debug\plugin\cnfutures\"; IDataProvider dataProvider = new DataProvider_Daily(DataUpdateConst.SRCDATAPATH_DAILY, DataUpdateConst.PLUGINPATH); List <int> tradingDays = dataProvider.GetNewTradingDays(); tradingDays.RemoveRange(40, tradingDays.Count - 40); AssertUtils.AssertEqual_List("tradingdays", GetType(), tradingDays); List <CodeInfo> codes = dataProvider.GetNewCodes(); codes.Sort(new CodeInfoComparer()); //AssertUtils.PrintLineList(codes); //AssertUtils.AssertEqual_List("codes", GetType(), codes); ITickData tickData = dataProvider.LoadTickData("A1705", 20170405); //AssertUtils.PrintTickData(tickData); AssertUtils.AssertEqual_TickData("TickData_A1705_20170405", GetType(), tickData); }
public void TestTickAttachKLine() { int start = 20170601; int endDate = 20170602; //string code = "A0401"; //int start = 20040106; //int endDate = 20040106; printStrs_Forward_KLine.Clear(); IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, start, endDate, false); historyDataForward.AttachOtherData(code2); historyDataForward.OnBar += HistoryDataForward_OnBar; historyDataForward.OnTick += HistoryDataForward_OnTick; //historyDataForward.OnTick += KlineDataForward_OnTick; while (historyDataForward.Forward()) { } AssertUtils.AssertEqual_List("attachcode_kline", GetType(), printStrs_Forward_KLine); }
public void TestLoadJinShuYuan() { //string srcDataPath = @"E:\FUTURES\CSV\TICK_JSY\"; //string pluginPath = @"D:\SCWORK\DEV\SC2\bin\Debug\plugin\cnfutures\"; DataProvider_JinShuYuan dataProvider = new DataProvider_JinShuYuan(DataUpdateConst.SRCDATAPATH_JINSHUYUAN, DataUpdateConst.PLUGINPATH); List <CodeInfo> codes = dataProvider.GetNewCodes(); //AssertUtils.PrintLineList(codes); AssertUtils.AssertEqual_List("codes", GetType(), codes); List <int> tradingDays = dataProvider.GetNewTradingDays(); AssertUtils.AssertEqual_List("tradingdays", GetType(), tradingDays); ITickData tickData = dataProvider.LoadTickData("a1607", 20160503); AssertUtils.AssertEqual_TickData("TickData_A1607_20160503", GetType(), tickData); tickData = dataProvider.LoadTickData("CF1607", 20160503); AssertUtils.AssertEqual_TickData("TickData_CF1607_20160503", GetType(), tickData); //AssertUtils.PrintTickData(tickData); }
private void Executor_OnFinished(object sender, StrategyFinishedArguments arguments) { AssertUtils.AssertEqual_List("executorhistory", GetType(), ((MockStrategy)arguments.Strategy).PrintData); }