示例#1
0
文件: Test.old.cs 项目: slb7/backtest
        public IBar GetDayBar(int d)
        {
            IBar rv = bd.GetMinuteBar(0, 390, 0);

            return(rv);

            return(Container.dict[Container.screenDate][Container.screenSymbol]);

            if (Container.dbk == null)
            {
                Container.dbk = Container.dict.Keys.ToArray();
                Array.Sort(Container.dbk);
            }
            int ind = Array.BinarySearch(Container.dbk, Container.screenDate);

            if (ind >= d)
            {
                ind -= d;
            }
            else
            {
                Container.uf = true;
                return(GetZeroBar());
            }
            Dictionary <string, IBar> sb = Container.dict[Container.dbk[ind]];

            //File.AppendAllText(@"c:\src\diag.txt", $"open={sb["SPY"].Open} close={sb["SPY"].Close}");
            return(sb[Container.screenSymbol]);
        }
示例#2
0
        //        private void ProcessTradeExit(List<string> results, BarDay barday, ref bool inPosition, double exitLimitPrice, double enterExecPrice, ref double exitExecPrice, int stopTime)
        private void ProcessTradeExit(List <string> results, IBarDay barday) //, ref bool inPosition, double exitLimitPrice, double enterExecPrice, ref double exitExecPrice, int stopTime)
        {
            IBar b = bd.GetMinuteBar(i, 1, 0);

            //File.AppendAllText(@"c:\src\diag.txt", $"profitExit={profitExit} tif={tif} exitLimitPrice{exitLimitPrice}\r\n");
            if (b != null)
            {
                if (b.Open > exitLimitPrice)
                {
                    DateTime barTime = barday.Date.AddHours(9.5).AddMinutes(i);
                    exitExecPrice = exitLimitPrice;
                    double pandl = exitExecPrice - enterExecPrice;
                    Container.testResult.NumTrades++;
                    Container.testResult.PandL += pandl;
                    //testResults.Add(testResult);
                    string str = $"{bd.Symbol} exit:{barTime.ToString("MM-dd-yy HH:mm:ss")} {i} {b.ToString()} exitExecPrice={exitExecPrice} p&l={(exitExecPrice - enterExecPrice).ToString("0.00")}";
                    results.Add(str);
                    results.AddRange(Container.messages);
                    inPosition = false;
                }
                else if (i >= stopTime || (i >= CloseAll && inPositionDays >= maxOvernights))
                {
                    //File.AppendAllText(@"c:\src\diag.txt", $"profitExit={profitExit} tif={tif} exitLimitPrice{exitLimitPrice} \r\n");
                    DateTime barTime = barday.Date.AddHours(9.5).AddMinutes(i);
                    exitExecPrice = b.Open;
                    double pandl = exitExecPrice - enterExecPrice;
                    Container.testResult.NumTrades++;
                    Container.testResult.PandL += pandl;
                    //testResults.Add(testResult);
                    string str = $"{bd.Symbol} Stop Exit:{barTime.ToString("MM-dd-yy HH:mm:ss")} {i} {b.ToString()} exitExecPrice={exitExecPrice} p&l={(exitExecPrice - enterExecPrice).ToString("0.00")}";
                    results.Add(str);
                    results.AddRange(Container.messages);
                    inPosition = false;
                }
            }
        }