コード例 #1
0
ファイル: Program.cs プロジェクト: slb7/backtest
        static void setup(int year, int month)
        {
            string filter = $@"{year.ToString("0000")}{month.ToString("00")}*.bin";

            string[] files = Directory.GetFiles($@"{minuteData}", filter);
            files = (from f in files where f.EndsWith(".bin") select f).ToArray();
            foreach (string file in files)
            {
                var ymd = getymd(file);
                BarDay.LoadDay(ymd.Item1, ymd.Item2, ymd.Item3);
                float[] tarr = BarDay.arr;
                BarDay.LoadDay(ymd.Item1, ymd.Item2, ymd.Item3, true);
                string date = $"{ymd.Item2.ToString("00")}/{ymd.Item3.ToString("00")}/{ymd.Item1.ToString("0000")}";

                List <IBarDay> bdlist = new List <IBarDay>();
                for (int i = 0; i < BarDay.symbols.Count(); i++)
                {
                    BarDay.dates = new string[] { date };
                    for (int j = 0; j < BarDay.dates.Count(); j++)
                    {
                        bdlist.Add(new BarDay(j, i));
                    }
                }
                string prev = Utility.GetTradingDay(date, -1);
                string nxt  = Utility.GetTradingDay(date, 1);
                Dictionary <string, IDayCandle> prevDay = Utility.LoadDayCandles(prev, BarDay.symbols);
                Dictionary <string, IDayCandle> nxtDay  = Utility.LoadDayCandles(nxt, BarDay.symbols);
                Dictionary <string, IDayCandle> today   = Utility.LoadDayCandles(date, BarDay.symbols);
                dictionary[date] = new TestDay()
                {
                    arr = tarr, symbols = BarDay.symbols, bdlist = bdlist, ndArr = BarDay.arr, nextDay = nxtDay, prevDay = prevDay, toDay = today
                };
            }

            //arrs[0] = BarDay.arr;
            //arrs[1] = BarDay.arr5;
            //arrs[2] = BarDay.arr15;
            //arrs[3] = BarDay.arr390;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: slb7/backtest
        static void Main(string[] args)
        {
            HttpListener list = new HttpListener();
            string       url  = $"http://*****:*****@"c:\src\MyTest\Mytest\bin\debug\mytest.dll");
                Type ty = null;
                try
                {
                    a  = GetAssembly();
                    ty = a.GetType("MyTest.MyTest");
                } catch (Exception e)
                {
                    continue;
                }
                StreamWriter sw = new StreamWriter(ctx.Response.OutputStream);
                Test.messages.Clear();
                Test.testResults.Clear();
                Test.results.Clear();
                foreach (string date in dictionary.Keys)
                {
                    TestDay td = dictionary[date];
                    BarDay.symbols = td.symbols;
                    arrs[0]        = td.arr;
                    string testdate = date;
                    Test   t        = (Test)Activator.CreateInstance(ty);// null;  //new MyTest();
                    BarDay.arr = td.arr;
                    if (t.testNextDay)
                    {
                        testdate   = Utility.GetTradingDay(date, 1);
                        BarDay.arr = td.ndArr;
                    }
                    BarDay.dates = new string[] { testdate };
                    //ILookup<DateTime, IBarDay> bdl = bdlist.ToLookup(k => DateTime.Parse("01/02/1998"));
                    //t.Container = new TestContainer();
                    //Test.type = typeof(MyTest);
                    //Test.type = typeof(Test);
                    Test.type = ty;
                    //System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
                    Console.WriteLine($"running {date} {i}");
                    sw.WriteLine($"Testing version {t.GetVerion()}");
                    BarDay.bdinit();
                    Dictionary <string, Dictionary <string, IDayCandle> > prev = new Dictionary <string, Dictionary <string, IDayCandle> >();
                    prev[testdate] = td.prevDay;
                    Dictionary <string, Dictionary <string, IDayCandle> > today = new Dictionary <string, Dictionary <string, IDayCandle> >();
                    today[testdate] = td.toDay;
                    t.run(td.bdlist.ToArray(), BarDay.symbols, BarDay.dates, arrs, prev, today);
                    //Test.results.Clear();
                }
                string d = "nodate";
                foreach (string s in Test.messages)
                {
                    //Console.WriteLine(s);
                    sw.WriteLine($"Message^{d}^{s}");
                }
                foreach (string s in Test.results)
                {
                    //Console.WriteLine(s);
                    sw.WriteLine($"results^{d}^{s}");
                }
                foreach (TestResult s in Test.testResults)
                {
                    //Console.WriteLine(s.ToString());
                    sw.WriteLine($"testResults^{d}^{s}");
                }
                string dir = ctx.Request.Url.AbsolutePath;

                //StreamWriter sw = new StreamWriter(ctx.Response.OutputStream);
                sw.Write(dir);
                sw.Flush();
                ctx.Response.Close();
            }
        }