Пример #1
0
        public String computeBonus(SelectItem item, Stock stock, int buyDate, out BuySellInfo info)
        {
            info = new BuySellInfo();
            if (item.buyNormlizePrice_ == 0)
            {
                return("");
            }
            IStrategy_LF_M  stra = (IStrategy_LF_M)this;
            DataStoreHelper dsh  = new DataStoreHelper();

            dsh.setStock(stock);
            dsh.iIndex_ = App.ds_.index(stock, buyDate);
            float buyC = item.buyNormlizePrice_;

            float firstDayBonusL = firstDayBonusLimit();
            float bonusL         = bonusLimit();
            float bL             = dsh.iIndex_ > 1 ? bonusL : firstDayBonusL;

            if (dsh.iIndex_ == 0)
            {
                var bonus = Utils.DeltaF(dsh.Ref(Info.C) - buyC, dsh.Ref(Info.C));
                info.sellDate_  = buyDate;
                info.tradeSpan_ = 0;
                info.allBonus_  = Utils.ToBonus(bonus - 0.002f);
                return(info.allBonus_);
            }
            else
            {
                --dsh.iIndex_;
                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;
                var bonus = (sellC - buyC) / buyC;
                info.allBonus_ = Utils.ToBonus(bonus - 0.002f);
                return(info.allBonus_);
            }
        }
Пример #2
0
        public SelectResult select(DataStoreHelper dsh, SelectMode selectMode, int date, List <IStrategy> strategyList, SelectHint hint = null)
        {
            bool bShowProgress = date == Utils.NowDate();

            if (bShowProgress)
            {
                App.host_.uiStartProcessBar();
            }
            SelectResult re = new SelectResult();

            dsh.iSZIndex_ = App.ds_.index(App.ds_.szListData_, date);
            for (int isk = 0; isk < App.ds_.stockList_.Count; ++isk)
            {
                Stock sk = App.ds_.stockList_[isk];
                if (bShowProgress)
                {
                    App.host_.uiSetProcessBar(String.Format("正在检测是否选择{0}", sk.code_), isk * 100 / App.ds_.stockList_.Count);
                }
                int iDateIndexHint = -1;
                if (hint != null)
                {
                    iDateIndexHint = hint.nextWantedIndexHintDict_[sk];
                }
                dsh.setStock(sk);
                for (int i = 0; i < strategyList.Count; ++i)
                {
                    IStrategy stra = strategyList[i];
                    Dictionary <String, String> rateItemDict = null;
                    String sigInfo = "";
                    try {
                        int iIndex = App.ds_.index(sk, date, iDateIndexHint);
                        if (iIndex == -1)
                        {
                            continue;
                        }
                        if (hint != null)
                        {
                            hint.nextWantedIndexHintDict_[sk] = iIndex + 1;
                        }
                        dsh.iIndex_ = iIndex;

                        if (dsh.dataList_[iIndex] == Data.NowInvalidData)
                        {
                            continue;
                        }

                        FocusOn fon            = stra.focusOn();
                        int     beforDateCount = sk.dataList_.Count - iIndex;
                        bool    isNewStock     = beforDateCount < Setting.MyNewStockLimit;
                        switch (fon)
                        {
                        case FocusOn.FO_Old:
                            if (isNewStock)
                            {
                                continue;
                            }
                            break;

                        case FocusOn.FO_All:
                            break;

                        case FocusOn.FO_New:
                            if (!isNewStock)
                            {
                                continue;
                            }
                            break;

                        default:
                            throw new ArgumentException("Unknown focusOn");
                        }
                        if (!isNewStock && dsh.MA(Info.A, 5, 1) < 20000)
                        {
                            continue;
                        }

                        rateItemDict = stra.select(dsh, selectMode, ref sigInfo);
                        if (rateItemDict == null)
                        {
                            continue;
                        }
                    } catch (DataException /*ex*/) {
                        continue;
                    }
                    SelectItem selItem = new SelectItem();
                    selItem.code_         = sk.code_;
                    selItem.date_         = date;
                    selItem.sigInfo_      = sigInfo;
                    selItem.strategyName_ = stra.name();
                    selItem.rateItemDict_ = rateItemDict;
                    re.selItems_.Add(selItem);
                }
            }
            Dictionary <String, int> strategySelCountDict = new Dictionary <String, int>();

            foreach (var item in re.selItems_)
            {
                if (strategySelCountDict.ContainsKey(item.strategyName_))
                {
                    ++strategySelCountDict[item.strategyName_];
                }
                else
                {
                    strategySelCountDict.Add(item.strategyName_, 1);
                }
            }
            foreach (var item in re.selItems_)
            {
                item.sameDayStrategySelCount_ = strategySelCountDict[item.strategyName_];
                item.sameDaySelCount_         = re.selItems_.Count;
            }
            if (bShowProgress)
            {
                App.host_.uiFinishProcessBar();
            }
            return(re);
        }