Exemplo n.º 1
0
 public override void OnInit()
 {
     //读取日线,计算持仓周期
     if (HasPosition)
     {
         DateTime     curDate   = Clock.Now.Date;
         List <Daily> dailyBars = BarUtils.GetLastNDailys(this.instrument, curDate.AddDays(-1), 40);
         BarUtils.AdjustDailys(dailyBars);            //向前复权
         int n = dailyBars.Count;
         if (n > 0)
         {
             int i;
             for (i = n - 1; i >= 0; i--)
             {
                 if (dailyBars[i].DateTime <= Position.EntryDate.Date)
                 {
                     break;
                 }
             }
             if (dailyBars[i].DateTime < Position.EntryDate.Date)
             {
                 i++;
             }
             if (i < 0)
             {
                 i = 0;
             }
             this.holdingPeriod = n - i + 1;
         }
         this.stopLossPrice = Position.EntryPrice * (1 - stopLossRate);
     }
     Console.WriteLine("投资组合中的证券 {0} 的持仓周期是 {1} ", this.instrument.Symbol, this.holdingPeriod);
 }
Exemplo n.º 2
0
    private static void ReviseDailys(List <Daily> dailys, string symbol, Trade lastTrade)
    {
        GMTrade gmTrade = (GMTrade)lastTrade;
        //去掉当天日线后
        int m = dailys.Count;

        if (dailys[m - 1].DateTime == dealDate)
        {
            BarUtils.CoverDailyFormTrade(dailys[m - 1], gmTrade);
        }
        else
        {
            dailys.RemoveAt(0);
            GMDaily newDaily = new GMDaily(dailys[m - 2] as GMDaily);
            BarUtils.CoverDailyFormTrade(newDaily, gmTrade);
            dailys.Add(newDaily);
        }
        //向前复权
        BarUtils.AdjustDailys(dailys);
    }