Esempio n. 1
0
        public void regress(RegressResult regressRe)
        {
            DataStoreHelper dsh        = new DataStoreHelper();
            SelectManager   selManager = new SelectManager();
            List <int>      dateList   = Utils.TraverTimeDay(regressRe.dateRangeList_);

            dateList.Reverse();
            App.host_.uiStartProcessBar();
            int nFinishCount = 0;
            int nTotalCount  = dateList.Count;

            SelectHint hint = new SelectHint();

            foreach (Stock sk in App.ds_.stockList_)
            {
                hint.nextWantedIndexHintDict_[sk] = -1;
            }
            foreach (int date in dateList)
            {
                SelectResult re = selManager.select(dsh, SelectMode.SM_Regress, date, regressRe.strategyList_, hint);
                regressRe.selItems_.AddRange(re.selItems_);
                App.host_.uiSetProcessBar(String.Format("{0}:正在回归{1}-{2},选择阶段:完成{3}的选择,当前选中记录数:{4}",
                                                        regressRe.solutionName_,
                                                        dateList.Last(), dateList.First(), date, regressRe.selItems_.Count),
                                          nFinishCount * 100 / nTotalCount);
                ++nFinishCount;
            }
            regressRe.selItems_.Sort(delegate(SelectItem lhs, SelectItem rhs)
            {
                var lhsBonus = lhs.getColumnVal("nsl");
                var rhsBonus = rhs.getColumnVal("nsl");
                if (lhsBonus == "")
                {
                    return(1);
                }
                if (rhsBonus == "")
                {
                    return(-1);
                }
                float lhsBonusValue = Utils.GetBonusValue(lhsBonus);
                float rhsBonusValue = Utils.GetBonusValue(rhsBonus);
                return(lhsBonusValue.CompareTo(rhsBonusValue));
            });
            foreach (var item in regressRe.selItems_)
            {
                item.allSelectItems_ = regressRe.selItems_;
            }
            App.host_.uiFinishProcessBar();
            if (regressRe.runMode_ == RunMode.RM_Asset)
            {
                regressRe.buyItems_ = App.grp_.desideToBuy(regressRe);
            }
            else
            {
                regressRe.buyItems_ = App.grp_.buyMostBonusPerDay(regressRe);
            }
        }
Esempio n. 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);
        }