Beispiel #1
0
        SelectItem priCompete(List <SelectItem> selItems, out float maxRank)
        {
            SelectItem maxRankItem = null;

            maxRank = int.MinValue;
            float maxRankC = 0;

            foreach (var item in selItems)
            {
                int rank = Utils.ToType <int>(item.getColumnVal("prirank"));
                if (rank > maxRank)
                {
                    maxRank     = rank;
                    maxRankItem = item;
                    maxRankC    = Utils.ToType <float>(item.getColumnVal("close"));
                }
                else if (rank == maxRank)
                {
                    float curC = Utils.ToType <float>(item.getColumnVal("close"));
                    if (curC > maxRankC)
                    {
                        maxRank     = rank;
                        maxRankItem = item;
                        maxRankC    = curC;
                    }
                }
            }
            return(maxRankItem);
        }
Beispiel #2
0
        public List <SelectItem> buyMostBonusPerDay(RegressResult re)
        {
            App.host_.uiStartProcessBar();
            List <SelectItem> buyitems = new List <SelectItem>();
            List <int>        dateList = Utils.TraverTimeDay(re.dateRangeList_);

            dateList.Reverse();
            int nFinishCount = 0;
            int nTotalCount  = dateList.Count;
            int nMissCount   = 0;
            int nTradeCount  = 0;

            foreach (int date in dateList)
            {
                nFinishCount++;
                List <SelectItem> items = SelectResult.OfDate(date, re.selItems_);
                if (items.Count == 0)
                {
                    if (Utils.IsTradeDay(date))
                    {
                        ++nMissCount;
                    }
                    continue;
                }
                float      maxBonusValue = -11;
                SelectItem maxBonusItem  = null;
                foreach (var item in items)
                {
                    var bonus = item.getColumnVal("bonus");
                    if (bonus == "")
                    {
                        continue;
                    }
                    var bonusValue = Utils.GetBonusValue(bonus);
                    if (bonusValue > maxBonusValue)
                    {
                        maxBonusValue = bonusValue;
                        maxBonusItem  = item;
                    }
                }
                if (maxBonusItem == null)
                {
                    buyitems.Add(items[0]);
                }
                else
                {
                    buyitems.Add(maxBonusItem);
                }
                ++nTradeCount;
                App.host_.uiSetProcessBar(String.Format("{0}:正在回归{1}-{2},可能最佳购买阶段:完成{3}的购买, 选择总数:{4},当前MissBuy:{5},Buy:{6}",
                                                        re.solutionName_,
                                                        dateList.Last(), dateList.First(), date, re.selItems_.Count, nMissCount, nTradeCount),
                                          nFinishCount * 100 / nTotalCount);
            }
            App.host_.uiFinishProcessBar();
            return(buyitems);
        }
Beispiel #3
0
        public static float GetBackBonus(List <SelectItem> allItems)
        {
            allItems.Sort(delegate(SelectItem lhs, SelectItem rhs)
            {
                var lhsBonus = lhs.getColumnVal("bonus");
                var rhsBonus = rhs.getColumnVal("bonus");
                if (lhsBonus == "")
                {
                    return(1);
                }
                if (rhsBonus == "")
                {
                    return(-1);
                }
                float lhsBonusValue = Utils.GetBonusValue(lhsBonus);
                float rhsBonusValue = Utils.GetBonusValue(rhsBonus);
                return(lhsBonusValue.CompareTo(rhsBonusValue));
            });
            float allBackBonusValue = 0;
            Dictionary <int, int> backBonusDataDict = new Dictionary <int, int>();

            for (int i = 0; i < allItems.Count; ++i)
            {
                SelectItem item  = allItems[i];
                var        bonus = item.getColumnVal("bonus");
                if (bonus == "")
                {
                    continue;
                }
                float allbonusValue = Utils.GetBonusValue(bonus);
                if (allbonusValue >= 0)
                {
                    break;
                }
                if (backBonusDataDict.ContainsKey(item.date_))
                {
                    continue;
                }
                backBonusDataDict[item.date_] = 0;
                allBackBonusValue            += allbonusValue;
                if (backBonusDataDict.Count >= 10)
                {
                    break;
                }
            }
            if (backBonusDataDict.Count > 0)
            {
                return(allBackBonusValue / backBonusDataDict.Count);
            }
            else
            {
                return(0);
            }
        }
Beispiel #4
0
        public SelectItem makeDeside(List <SelectItem> selectItems, int date, IBuyDesider desider, bool bIsSelect)
        {
            if (selectItems.Count == 0)
            {
                return(null);
            }
            if (bIsSelect)
            {
                DateTime curTime = DateTime.Now;
                var      dt      = DB.Global().Select(
                    String.Format("Select code, buyNormlizePrice From minute_select Where date = '{0}'", Utils.Date(curTime)));

                Dictionary <String, int> codeBuyNormlizePriceDict = new Dictionary <String, int>();
                foreach (DataRow row in dt.Rows)
                {
                    codeBuyNormlizePriceDict.Add(row["code"].ToString(), Utils.ToType <int>(row["buyNormlizePrice"].ToString()));
                }

                foreach (var item in selectItems)
                {
                    bool bMinuteStrategy = item.strategyName_.StartsWith("LF_");
                    if (!bMinuteStrategy)
                    {
                        continue;
                    }
                    if (codeBuyNormlizePriceDict.TryGetValue(item.code_, out item.buyNormlizePrice_))
                    {
                        item.sigInfo_ = Utils.ToPrice(item.buyNormlizePrice_).ToString();
                        continue;
                    }
                    var   close = item.getColumnVal("close");
                    float fclose;
                    if (!float.TryParse(close, out fclose))
                    {
                        continue;
                    }
                    item.buyNormlizePrice_ = (int)(fclose * Setting.NormalizeRate);
                    item.sigInfo_          = Utils.ToPrice(item.buyNormlizePrice_).ToString();
                    Dictionary <String, Object> selectItem = new Dictionary <String, Object>();
                    selectItem["code"]             = item.code_;
                    selectItem["date"]             = item.date_;
                    selectItem["name"]             = item.getColumnVal("name");
                    selectItem["zf"]               = item.getColumnVal("zf");
                    selectItem["bonus"]            = item.getColumnVal("bonus");
                    selectItem["close"]            = item.getColumnVal("close");
                    selectItem["straname"]         = item.strategyName_;
                    selectItem["buyNormlizePrice"] = item.buyNormlizePrice_;
                    selectItem["selecttime"]       = Utils.ToTimeDesc(curTime);

                    DB.Global().Insert("minute_select", selectItem);
                }
                foreach (var item in selectItems)
                {
                    bool bMinuteStrategy = item.strategyName_.StartsWith("LF_");
                    if (!bMinuteStrategy)
                    {
                        continue;
                    }
                    if (!codeBuyNormlizePriceDict.ContainsKey(item.code_))
                    {
                        continue;
                    }
                    var close = item.getColumnVal("close");
                    DB.Global().Execute(String.Format("Update minute_select Set close = '{0}' Where code = '{1}'", close, item.code_));
                }
            }
            SelectItem buyItem = desider.makeDeside(selectItems);

            return(buyItem);
        }
Beispiel #5
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_);
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public static HistoryData GetHistoryData(List <DateSelectItem> dateItems,
                                                 int iStartIndex, int nCount, RunMode runMode)
        {
            List <SelectItem> allItems = new List <SelectItem>();

            for (int i = 0; i < nCount; i++)
            {
                if (iStartIndex + i >= dateItems.Count)
                {
                    break;
                }
                DateSelectItem dayData = dateItems[iStartIndex + i];
                allItems.AddRange(dayData.selItems_);
            }
            HistoryData data = new HistoryData();

            data.backBonusValue_ = GetBackBonus(allItems);
            for (int i = 0; i < allItems.Count; ++i)
            {
                SelectItem item  = allItems[i];
                var        bonus = item.getColumnVal("bonus");
                if (bonus == "")
                {
                    continue;
                }
                data.nHoldStockDays_ += Utils.ToType <int>(item.getColumnVal("tradespan"));
                float bonusValue = Utils.GetBonusValue(bonus);
                data.allBonusValue_ += bonusValue;
            }

            allItems.Clear();
            for (int i = 0; i < nCount; i++)
            {
                if (iStartIndex + i >= dateItems.Count)
                {
                    break;
                }
                DateSelectItem dayData = dateItems[iStartIndex + i];
                allItems.AddRange(dayData.goodSampleSelItems_);
            }
            data.gbackBonusValue_ = GetBackBonus(allItems);
            for (int i = 0; i < allItems.Count; ++i)
            {
                SelectItem item   = allItems[i];
                var        bonus  = item.getColumnVal("bonus");
                var        strNsh = item.getColumnVal("nsh");
                if (bonus == "" || strNsh == "")
                {
                    continue;
                }
                data.nGoodSampleHoldStockDays_ += Utils.ToType <int>(item.getColumnVal("tradespan"));
                float bonusValue = Utils.GetBonusValue(bonus);
                data.allGoodSampleBonusValue_ += bonusValue;
                float nsh = Utils.GetBonusValue(strNsh);
                if (nsh > 0.5)
                {
                    data.nPlusCount_++;
                }
                else if (nsh < -1.5)
                {
                    data.nMinusCount_++;
                    if (nsh < -0.095)
                    {
                        data.nDeadCount_++;
                    }
                }
                else if (bonusValue < 0.2)
                {
                    data.nPartialMinusCount_++;
                }
            }


            data.nDayCount_ = iStartIndex + nCount - 1 >= dateItems.Count ?
                              dateItems.Count - iStartIndex : nCount;
            int date0 = dateItems[iStartIndex].date_;
            int date1 = dateItems[iStartIndex + data.nDayCount_ - 1].date_;

            data.startDate_ = Math.Min(date0, date1);
            data.endDate_   = Math.Max(date0, date1);
            for (int i = 0; i < nCount; i++)
            {
                if (iStartIndex + i >= dateItems.Count)
                {
                    break;
                }
                DateSelectItem dayData = dateItems[iStartIndex + i];
                foreach (var selItem in dayData.selItems_)
                {
                    var bonus = selItem.getColumnVal("bonus");
                    if (bonus == "")
                    {
                        continue;
                    }
                    float bounusValue = Utils.GetBonusValue(bonus);
                    var   envBonus    = selItem.getColumnVal("envbonus");
                    if (envBonus != "")
                    {
                        float envBonusValue = Utils.GetBonusValue(envBonus);
                        if (envBonusValue < 0)
                        {
                            ++data.nAntiEnvCheckCount_;
                            if (bounusValue > 0)
                            {
                                ++data.nAntiEnvCount_;
                            }
                        }
                    }
                }
                data.nGoodSampleSelectCount_ += dayData.goodSampleSelItems_.Count;
                data.nAllSampleSelectCount_  += dayData.selItems_.Count;
                data.nDayMaxSelectCount_      = Math.Max(data.nDayMaxSelectCount_, dayData.selItems_.Count);
                foreach (var selItem in dayData.goodSampleSelItems_)
                {
                    var bonus = selItem.getColumnVal("bonus");
                    if (bonus == "")
                    {
                        continue;
                    }
                    float bounusValue = Utils.GetBonusValue(bonus);
                    if (bounusValue > 0)
                    {
                        ++data.nSelectSucCount_;
                    }
                }
                if (runMode == RunMode.RM_Asset)
                {
                    var buyItem = dayData.getBuyItem();
                    if (buyItem != null)
                    {
                        var bonus = buyItem.getColumnVal("bonus");
                        if (bonus != "")
                        {
                            float bounusValue = Utils.GetBonusValue(bonus);
                            if (bounusValue > 0)
                            {
                                data.nTradeSucCount_++;
                            }
                            data.tradeBonusValue_ += bounusValue;
                        }
                        ++data.nTradeCount_;
                    }

                    float dayAllBonusValue = 0;
                    foreach (var item in dayData.selItems_)
                    {
                        var bonus = item.getColumnVal("bonus");
                        if (bonus != "")
                        {
                            float bonusValue = Utils.GetBonusValue(bonus);
                            dayAllBonusValue += bonusValue;
                        }
                    }
                    if (dayAllBonusValue > 0)
                    {
                        data.nTradeAllSucCount_++;
                    }
                }
                else
                {
                    if (dayData.selItems_.Count > 0)
                    {
                        float dayAllBonusValue = 0;
                        foreach (var item in dayData.goodSampleSelItems_)
                        {
                            var bonus = item.getColumnVal("bonus");
                            if (bonus != "")
                            {
                                float bonusValue = Utils.GetBonusValue(bonus);
                                dayAllBonusValue += bonusValue;
                            }
                        }
                        if (dayAllBonusValue > 0)
                        {
                            data.nTradeSucCount_++;
                            data.nTradeAllSucCount_++;
                        }
                        data.tradeBonusValue_ += dayAllBonusValue / dayData.goodSampleSelItems_.Count;
                        if (dayData.goodSampleSelItems_.Count > 0)
                        {
                            data.nTradeCount_++;
                        }
                    }
                }
            }
            data.refrestStatistics();
            return(data);
        }