Ejemplo n.º 1
0
        public bool meetBuyChance(DataStoreHelper dsh, SelectMode selectMode)
        {
            IStrategy_LF stra     = (IStrategy_LF)this;
            float        buyLimit = stra.buyLimit();

            switch (selectMode)
            {
            case SelectMode.SM_Regress:
                return(dsh.Ref(Info.LF) < buyLimit);

            case SelectMode.SM_SelectOpen:
                return(true);

            default:
                return(dsh.Ref(Info.ZF) < buyLimit + 0.005f);
            }
        }
Ejemplo n.º 2
0
        Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo)
        {
            IStrategy_LF stra = (IStrategy_LF)this;

            if (!meetBuyChance(dsh, selectMode))
            {
                return(null);
            }

            if (dsh.Ref(Info.OF) > 0.04 || dsh.Ref(Info.OF) < -0.015 || dsh.Ref(Info.ZF, 1) < -0.02 || dsh.Ref(Info.OF, 1) < -0.03)
            {
                return(null);
            }
            if (dsh.Ref(Info.CO, 1) / dsh.Ref(Info.C, 1) < 0.01)
            {
                return(null);
            }
            int   iSigDateIndex         = -1;
            int   nUpCount              = 0;
            int   nUStopCount           = 0;
            int   nDStopCount           = 0;
            bool  bMeetTradeSigAllready = false;
            bool  bMeetRealUp           = false;
            float sigDateVol            = 0;
            float otherMaxVol           = 0;
            bool  bHasUpShadowTooHight  = false;
            bool  bHasDownShadowTooLow  = false;
            float otherMaxZF            = 0;
            float otherMaxC             = 0;
            float otherMaxH             = 0;
            float sumOfSigDateZF        = 0;

            for (int i = 1; i < 8; ++i)
            {
                var curOf    = dsh.Ref(Info.OF, i);
                var curHf    = dsh.Ref(Info.HF, i);
                var curZf    = dsh.Ref(Info.ZF, i);
                var curPreZf = dsh.Ref(Info.ZF, i + 1);
                var vol      = dsh.Ref(Info.V, i);
                if (curOf < 0.03 && curZf > 0.03 && curZf < 0.095 &&
                    dsh.Ref(Info.OF, i + 1) < 0.03 && dsh.Ref(Info.ZF, i + 1) > 0.03)
                {
                    for (int j = i + 2; j < i + 5; j++)
                    {
                        if (dsh.Ref(Info.ZF, j) < 0)
                        {
                            break;
                        }

                        if (dsh.Ref(Info.ZF, j) > 0.05)
                        {
                            return(null);
                        }
                    }
                    bool bHasDown = false;
                    for (int j = i + 2; j < i + 7; j++)
                    {
                        if (dsh.Ref(Info.ZF, j) < 0)
                        {
                            bHasDown = true;
                            break;
                        }
                    }
                    if (dsh.AccZF(8, i + 2) < -0.15)
                    {
                        return(null);
                    }
                    float preVol = dsh.Ref(Info.V, i + 1);
                    float chkVol = Math.Max(vol, preVol);
                    for (int j = i + 2; j < i + 6; ++j)
                    {
                        if (dsh.Ref(Info.V, j) > chkVol * 2)
                        {
                            return(null);
                        }
                    }
                    if (!bHasDown)
                    {
                        return(null);
                    }
                    sumOfSigDateZF = curZf + dsh.Ref(Info.ZF, i + 1);
                    if (sumOfSigDateZF > 0.1)
                    {
                        iSigDateIndex = i;
                        sigDateVol    = Math.Max(dsh.Ref(Info.V, i + 1), vol);
                        break;
                    }
                }
                otherMaxVol = Math.Max(vol, otherMaxVol);
                if (curZf > 0 && dsh.IsReal(i))
                {
                    nUpCount++;
                }
                if (curZf > 0.095)
                {
                    nUStopCount++;
                }
                else if (curZf < -0.095)
                {
                    nDStopCount++;
                }
                if (curZf < -0.03)
                {
                    bMeetTradeSigAllready = true;
                }
                else if (curZf > 0.012)
                {
                    bMeetRealUp = true;
                }

                if (dsh.UpShadow(i) > 0.03)
                {
                    bHasUpShadowTooHight = true;
                }

                if (dsh.DownShadow(i) < -0.03)
                {
                    bHasDownShadowTooLow = true;
                }
                otherMaxZF = Math.Max(otherMaxZF, curZf);
                otherMaxC  = Math.Max(dsh.Ref(Info.C, i), otherMaxC);
                otherMaxH  = Math.Max(dsh.Ref(Info.H, i), otherMaxH);
            }
            if (iSigDateIndex == -1)
            {
                return(null);
            }
            sigInfo = dsh.Date(iSigDateIndex).ToString();

            int iMaxCOIndex = dsh.HH(Info.CO, 30, 1);

            if (dsh.Ref(Info.ZF, iMaxCOIndex) < 0)
            {
                return(null);
            }
            if (nUpCount < 2)
            {
                return(null);
            }
            if (dsh.Ref(Info.C, 1) * (1 + stra.buyLimit() - 0.01) < dsh.Ref(Info.L, iSigDateIndex))
            {
                return(null);
            }
            if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp)
            {
                return(null);
            }
            if (sigDateVol > otherMaxVol * 2)
            {
                return(null);
            }
            float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex);

            if (maxUpF < 0.015 /* || maxUpF > 0.04*/)
            {
                return(null);
            }
            if (sigDateVol < otherMaxVol * 1.2)
            {
                return(null);
            }

            if (bHasUpShadowTooHight || bHasDownShadowTooLow)
            {
                return(null);
            }


            if (
                dsh.Ref(Info.ZF, 2) < 0.005 &&
                dsh.Ref(Info.ZF, 3) < 0.005)
            {
                return(null);
            }
            if (Math.Min(dsh.Ref(Info.ZF, iSigDateIndex), dsh.Ref(Info.ZF, iSigDateIndex + 1)) + dsh.Ref(Info.ZF, iSigDateIndex + 2) < -0.01)
            {
                return(null);
            }


            if (dsh.Ref(Info.C, iSigDateIndex) < dsh.Ref(Info.O, iSigDateIndex))
            {
                return(null);
            }
            if (dsh.Ref(Info.C, iSigDateIndex + 1) < dsh.Ref(Info.O, iSigDateIndex + 1))
            {
                return(null);
            }
            return(EmptyRateItemButSel);
//             var delta = (dsh.Ref(Info.C) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1);
//             if (delta > -0.01)
//             {
//                 return null;
//             }
//             var ret = new Dictionary<String, String>();
//             ret[String.Format("sumSig/{0}", sumOfSigDateZF>0.12 ? "1": "0")] = "";
//             ret[String.Format("delta/{0}", delta < -0.02 ? "1" : "0")] = "";
//             ret[String.Format("maxUp/{0}", maxUpF > 0.02 ? "1" : "0")] = "";
//             ret[String.Format("diffzf/{0}", otherMaxZF + zf > -0.02 ? "1" : "0")] = "";
//             return ret;
        }
Ejemplo n.º 3
0
        public String computeBonus(SelectItem item, Stock stock, int buyDate, out BuySellInfo info)
        {
            IStrategy_LF    stra           = (IStrategy_LF)this;
            float           firstDayBonusL = firstDayBonusLimit();
            float           bonusL         = bonusLimit();
            float           buyLimit       = stra.buyLimit();
            DataStoreHelper dsh            = new DataStoreHelper();

            dsh.setStock(stock);
            dsh.iIndex_ = App.ds_.index(stock, buyDate);
            float buyC = dsh.Ref(Info.C, 1) * (1 + buyLimit);

            --dsh.iIndex_;
            info = new BuySellInfo();
            if (dsh.iIndex_ == -1)
            {
                return("");// 还未遇到交易日,不知道盈亏
            }
            int   nBuySpan      = 0;
            int   nBuySpanLimit = buySpan();
            float sellC         = 0;

            for (; dsh.iIndex_ >= 0; --dsh.iIndex_, ++nBuySpan)
            {
                float o = dsh.Ref(Info.O);
                float h = dsh.Ref(Info.H);
                float c = dsh.Ref(Info.C);

                float of = dsh.Ref(Info.OF);
                float hf = dsh.Ref(Info.HF);
                float lf = dsh.Ref(Info.LF);
                float zf = dsh.Ref(Info.ZF);

                var   limit      = nBuySpan == 0 ? firstDayBonusL : bonusL;
                float wantedC    = buyC * (1 + limit);
                float wantedMinC = buyC * (1 + bonusL);
                //
                //                 if (lf < -0.111 || hf > 0.111)
                //                 {//除权了
                //                     return "";
                //                 }
                if (Utils.IsDownStop(hf))//一直跌停
                {
                    info.bSellWhenMeetMyBounusLimit_ = false;
                    continue;
                }
                //今天没一直跌停,大概率能卖出
                if (info.bSellWhenMeetMyBounusLimit_)
                {
                    if (o > wantedC)//开盘超出盈利顶额
                    {
                        sellC = o;
                        ++nBuySpan;
                        break;
                    }
                    if (h > wantedC)//达到盈利顶额
                    {
                        sellC = wantedC;
                        ++nBuySpan;
                        break;
                    }
                    if (Utils.IsDownStop(zf))//尾盘跌停,卖不了
                    {
                        info.bSellWhenMeetMyBounusLimit_ = false;
                        continue;
                    }
                    sellC = c;
                    if (zf >= 0.01 || h >= wantedMinC || nBuySpan >= nBuySpanLimit - 1)
                    {
                        ++nBuySpan;
                        break;
                    }
                }
                else
                {                              //逃命模式
                    if (!Utils.IsDownStop(of)) //开盘没跌停
                    {                          //跑了
                        sellC = o;
                        ++nBuySpan;
                        break;
                    }
                    //开盘跌停但因为没一直跌停,所以肯定可以以跌停价卖出
                    sellC = dsh.Ref(Info.C, 1) * (1 - 0.095f);
                    ++nBuySpan;
                    break;
                }
            }
            if (dsh.iIndex_ == -1)
            {
                return("");
            }
            info.sellDate_  = dsh.Date();
            info.tradeSpan_ = nBuySpan;
            float bonus = (sellC - buyC) / buyC;

            info.allBonus_ = Utils.ToBonus(bonus - 0.002f);
            return(info.allBonus_);
        }
Ejemplo n.º 4
0
        Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo)
        {
            IStrategy_LF stra = (IStrategy_LF)this;

            if (!meetBuyChance(dsh, selectMode))
            {
                return(null);
            }

            if (dsh.Ref(Info.OF) > 0.04 || dsh.Ref(Info.OF) < -0.015 || dsh.Ref(Info.ZF, 1) < -0.02 || dsh.Ref(Info.OF, 1) < -0.03)
            {
                return(null);
            }
            if (dsh.Ref(Info.CO, 1) / dsh.Ref(Info.C, 1) < 0.01)
            {
                return(null);
            }

            int   iSigDateIndex         = -1;
            int   nUpCount              = 0;
            int   nDownCount            = 0;
            int   nUStopCount           = 0;
            int   nDStopCount           = 0;
            bool  bMeetTradeSigAllready = false;
            bool  bMeetRealUp           = false;
            bool  bHasUpShadowTooHight  = false;
            bool  bHasDownShadowTooLow  = false;
            float otherMaxVol           = float.MinValue;
            float otherMaxC             = float.MinValue;
            float otherMaxH             = float.MinValue;
            float otherMaxZF            = float.MinValue;
            float sigDateVol            = 0;
            float sigZF         = 0;
            float minDownShadow = float.MaxValue;
            float maxUpShadow   = float.MinValue;
            float otherMinZF    = float.MaxValue;
            float totalUp       = 0;
            float totalDown     = 0;

            for (int i = 1; i < 8; ++i)
            {
                var curOf    = dsh.Ref(Info.OF, i);
                var curHf    = dsh.Ref(Info.HF, i);
                var curZf    = dsh.Ref(Info.ZF, i);
                var curPreZf = dsh.Ref(Info.ZF, i + 1);
                var vol      = dsh.Ref(Info.V, i);
                if (curZf > 0.095)
                {
                    return(null);
                }
                if (curOf < 0.04 && curHf > 0.095 && curZf < 0.095 && curZf > 0)
                {
                    iSigDateIndex = i;
                    sigDateVol    = vol;
                    sigZF         = curZf;
                    for (int j = i + 1; j < i + 5; ++j)
                    {
                        if (dsh.Ref(Info.V, j) > vol * 2)
                        {
                            return(null);
                        }
                    }
                    if (dsh.AccZF(8, i + 1) < -0.15)
                    {
                        return(null);
                    }
                    if (dsh.AccZF(3, i + 1) > 0.095)
                    {
                        return(null);
                    }
                    break;
                }
                if (curOf < -0.04)
                {
                    return(null);
                }

                if (curZf > 0 && dsh.IsReal(i))
                {
                    nUpCount++;
                }
                if (curZf < 0 && dsh.IsReal(i))
                {
                    nDownCount++;
                }
                if (curZf > 0.095)
                {
                    nUStopCount++;
                }
                else if (curZf < -0.095)
                {
                    nDStopCount++;
                }
                if (curZf < -0.03)
                {
                    bMeetTradeSigAllready = true;
                }
                else if (curZf > 0.012)
                {
                    bMeetRealUp = true;
                }
                float upShadow   = dsh.UpShadow(i);
                float downShadow = dsh.DownShadow(i);
                if (upShadow > maxUpShadow)
                {
                    maxUpShadow = upShadow;
                }
                if (downShadow < minDownShadow)
                {
                    minDownShadow = downShadow;
                }
                if (curZf > 0)
                {
                    totalUp += curZf;
                }
                else
                {
                    totalDown += curZf;
                }
                otherMaxVol = Math.Max(vol, otherMaxVol);
                otherMaxC   = Math.Max(dsh.Ref(Info.C, i), otherMaxC);
                otherMaxH   = Math.Max(dsh.Ref(Info.H, i), otherMaxH);
                otherMaxZF  = Math.Max(otherMaxZF, curZf);
                otherMinZF  = Math.Min(otherMinZF, curZf);
            }
            if (iSigDateIndex == -1)
            {
                return(null);
            }
            sigInfo = dsh.Date(iSigDateIndex).ToString();

            if (dsh.Ref(Info.ZF, iSigDateIndex) + dsh.Ref(Info.ZF, iSigDateIndex + 1) < -0.01)
            {
                return(null);
            }
            if (sigDateVol > otherMaxVol * 2)
            {
                return(null);
            }
            if (otherMinZF > 0.03)
            {
                return(null);
            }
            if (totalDown + totalUp < -0.01)
            {
                return(null);
            }
            if (otherMaxH < dsh.Ref(Info.H, iSigDateIndex))
            {
                return(null);
            }
            if (dsh.Ref(Info.C, 1) * (1 + stra.buyLimit() - 0.01) < dsh.Ref(Info.L, iSigDateIndex))
            {
                return(null);
            }
            if (maxUpShadow > 0.03)
            {
                bHasUpShadowTooHight = true;
            }

            if (minDownShadow < -0.03)
            {
                bHasDownShadowTooLow = true;
            }
            if (nUpCount < 2)
            {
                return(null);
            }
            if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp)
            {
                return(null);
            }
            float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex);

            if (maxUpF < 0.02 /* || maxUpF > 0.04*/)
            {
                return(null);
            }

//             if (sigDateVol < otherMaxVol * 1.2)
//             {
//                 return null;
//             }

//             if (dsh.Ref(Info.LF) < -0.06)
//             {
//                 return null;
//             }
            if (bHasUpShadowTooHight || bHasDownShadowTooLow)
            {
                return(null);
            }
//             if (dsh.Ref(Info.OF) < -0.02)
//             {
//                 return null;
//             }
            if (
                dsh.Ref(Info.ZF, 2) < 0.005 &&
                dsh.Ref(Info.ZF, 3) < 0.005)
            {
                return(null);
            }
            if (dsh.Ref(Info.ZF, iSigDateIndex - 1) < 0 && dsh.IsReal(iSigDateIndex - 1) &&
                dsh.Ref(Info.H, iSigDateIndex - 1) > dsh.Ref(Info.H, iSigDateIndex))
            {
                return(null);
            }
//              if (dsh.Ref(Info.ZF, iSigDateIndex-1) < 0 &&
//                   dsh.Ref(Info.ZF, iSigDateIndex - 2) < 0)
//              {
//                  return null;
//              }
            if (dsh.Ref(Info.C, iSigDateIndex) < dsh.Ref(Info.O, iSigDateIndex))
            {
                return(null);
            }

            var delta = (dsh.Ref(Info.C, 1) * (1 + stra.buyLimit() + 0.01) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1);

            if (delta > -0.01)
            {
                return(null);
            }
            var ret = new Dictionary <String, String>();

            ret[String.Format("vol/{0}", sigDateVol < otherMaxVol * 1.5 ? "1" : "0")] = "";
            //          ret[String.Format("maxUp/{0}", maxUpF > 0.03 ? "1" : "0")] = "";
            return(ret);
        }