Пример #1
0
        public static List <DateSelectItem> ToDaySelectItemList(List <SelectItem> selItems, List <DateRange> dateRangeList)
        {
            List <DateSelectItem> retList  = new List <DateSelectItem>();
            List <int>            dateList = Utils.TraverTimeDay(dateRangeList);

            dateList.Reverse();
            foreach (int date in dateList)
            {
                if (!Utils.IsTradeDay(date))
                {
                    continue;
                }
                DateSelectItem item = new DateSelectItem();
                item.date_ = date;
                var rawitems = SelectResult.OfDate(date, selItems, true);
                Dictionary <String, int> uniqueItemDict = new Dictionary <String, int>();
                item.selItems_ = new List <SelectItem>();
                foreach (var ritem in rawitems)
                {
                    if (!uniqueItemDict.ContainsKey(ritem.code_))
                    {
                        item.selItems_.Add(ritem);
                        uniqueItemDict[ritem.code_] = 0;
                    }
                }

                item.goodSampleSelItems_ = GetGoodSampleSelectItems(item.selItems_);
                retList.Add(item);
            }
            return(retList);
        }
Пример #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);
        }
Пример #3
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);
            }
        }
Пример #4
0
        public List <SelectItem> desideToBuy(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;
                }
                else
                {
                    var buyItem = makeDeside(items, date, RankBuyDesider.buyer_, false);
                    if (buyItem != null)
                    {
                        buyItem.iamBuyItem_ = true;
                        ++nTradeCount;
                    }
                    buyitems.Add(buyItem);
                }
                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(re.buyItems_ = buyitems);
        }
Пример #5
0
        public SelectResult selectNow()
        {
            DataStoreHelper dsh = new DataStoreHelper();
//             List<IStrategy> strategyList = new List<IStrategy>();
//             strategyList.Add(App.grp_.strategy("LStopUp"));

            List <IStrategy> strategyList;
            SelectMode       selectMode = SelectMode.SM_SelectInDay;
            DateTime         curTime    = DateTime.Now;

            if (Utils.IsOpenTime(curTime.Hour, curTime.Minute))
            {
                strategyList = App.Solution("lf_good").straList_;
                selectMode   = SelectMode.SM_SelectOpen;
            }
            else if (Utils.IsCloseTime(curTime.Hour, curTime.Minute))
            {
                strategyList = App.Solution("close_good").straList_;
                selectMode   = SelectMode.SM_SelectClose;
            }
            else if (Utils.IsTradeTime(curTime.Hour, curTime.Minute))
            {
                strategyList = App.Solution("lf_good").straList_;
                selectMode   = SelectMode.SM_SelectInDay;
            }
            else
            {
                strategyList = App.Solution("close_good").straList_;
                selectMode   = SelectMode.SM_SelectClose;
            }
            if (strategyList.Count == 0)
            {
                throw new Exception("No strategy provide!");
            }
            SelectResult re = select(dsh, selectMode, Utils.NowDate(), strategyList);

            foreach (var item in re.selItems_)
            {
                item.allSelectItems_ = re.selItems_;
            }
            var buyItem = App.grp_.makeDeside(re.selItems_, Utils.NowDate(), RankBuyDesider.buyer_, true);

            if (buyItem != null)
            {
                buyItem.iamBuyItem_ = true;
            }
            re.selItems_.Sort(delegate(SelectItem lhs, SelectItem rhs)
            {
                if (lhs.iamBuyItem_)
                {
                    return(-1);
                }
                if (rhs.iamBuyItem_)
                {
                    return(1);
                }
                return(Utils.ToType <int>(lhs.getColumnVal("prirank")).CompareTo(Utils.ToType <int>(rhs.getColumnVal("prirank"))));
            });


            return(re);
        }
Пример #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);
        }
Пример #7
0
        public String getColumnVal(String colName, Stock stock, HistoryData straData, bool bSearchCache = true)
        {
            if (bSearchCache)
            {
                String cacheVal;
                if (colValCacheDict_.TryGetValue(colName, out cacheVal))
                {
                    return(cacheVal);
                }
            }
            IStrategy stra = App.grp_.strategy(strategyName_);

            if (colName == "date")
            {
                return(date_.ToString());
            }
            else if (colName == "strategy")
            {
                return(strategyName_);
            }
            if (stock == null)
            {
                return("");
            }
            if (colName == "code")
            {
                return(code_);
            }
            else if (colName == "name")
            {
                return(stock == null ? "" : stock.name_);
            }
            else if (colName == "zf")
            {
                String zf = stock.zfSee(date_);
                colValCacheDict_[colName] = zf;
                return(zf);
            }
            else if (colName == "bonus")
            {
                BuySellInfo info;
                String      bonus = stra.computeBonus(this, stock, date_, out info);
                colValCacheDict_[colName] = bonus;
                return(bonus);
            }
            else if (colName == "nsh")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                if (info.sellDate_ == -1)
                {
                    colValCacheDict_[colName] = "";
                    return("");
                }
                String bonus = Utils.ToBonus(stock.hf(info.sellDate_));
                colValCacheDict_[colName] = bonus;
                return(bonus);
            }
            else if (colName == "nsl")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                if (info.sellDate_ == -1)
                {
                    colValCacheDict_[colName] = "";
                    return("");
                }
                String bonus = Utils.ToBonus(stock.lf(info.sellDate_));
                colValCacheDict_[colName] = bonus;
                return(bonus);
            }

            else if (colName == "nso")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                if (info.sellDate_ == -1)
                {
                    colValCacheDict_[colName] = "";
                    return("");
                }
                String bonus = Utils.ToBonus(stock.of(info.sellDate_));
                colValCacheDict_[colName] = bonus;
                return(bonus);
            }
            else if (colName == "nsc")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                if (info.sellDate_ == -1 || !info.bSellWhenMeetMyBounusLimit_)
                {
                    colValCacheDict_[colName] = "";
                    return("");
                }
                String bonus = Utils.ToBonus(stock.zf(info.sellDate_));
                colValCacheDict_[colName] = bonus;
                return(bonus);
            }
            else if (colName == "hrate")
            {
                List <SelectItem> daySelectItems = SelectResult.OfDate(date_, allSelectItems_);
                int nPlusCount = 0;
                int nAllCount  = 0;
                foreach (var item in daySelectItems)
                {
                    var bonus = item.getColumnVal("bonus");
                    if (bonus == "")
                    {
                        continue;
                    }
                    if (Utils.GetBonusValue(bonus) > 0)
                    {
                        ++nPlusCount;
                    }
                    ++nAllCount;
                }
                String ret;
                if (nAllCount == 0)
                {
                    ret = "";
                }
                else
                {
                    ret = (nPlusCount * 1.0f / nAllCount).ToString("F2");
                }
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "envbonus")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                String ret = info.sellDate_ == -1 ? "" : App.ds_.envBonus(info.sellDate_);
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "sellspan")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                String ret;
                if (info.sellDate_ == -1)
                {
                    ret = "not yet";
                }
                else
                {
                    ret = Utils.DateSpan(date_, info.sellDate_);
                }
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "tradespan")
            {
                BuySellInfo info;
                stra.computeBonus(this, stock, date_, out info);
                String ret;
                if (info.tradeSpan_ == -1)
                {
                    ret = "not yet";
                }
                else
                {
                    ret = info.tradeSpan_.ToString();
                }
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "close")
            {
                String ret = App.ds_.realVal(Info.C, code_, date_).ToString("F3");
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "lastClose")
            {
                String ret = App.ds_.realVal(Info.C, code_, stock.prevTradeDate(date_)).ToString("F3");
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "pubrank")
            {
                if (straData == null)
                {
                    return("-1");
                }
//                 float priRank = Utils.ToType<float>(getColumnVal("prirank"));
//                 float priPercent = priRank / straData.rank_;
//                 return (priPercent * 55.0f + 45.0f * straData.rank_ / 100.0f).ToString("F0");
                return(straData.rank_.ToString());
            }
            else if (colName == "prirank")
            {
                String ret;
                if (straData == null)
                {
                    ret = "-1";
                }
                else
                {
                    ret = RateComputer.ComputerRank(strategyName_, rateItemDict_).ToString();
                }
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else if (colName == "trcount")
            {
                return(straData == null ? "0" : straData.nTradeCount_.ToString());
            }
            else if (colName == "selcount")
            {
                return(straData == null ? "0" : straData.nGoodSampleSelectCount_.ToString());
            }
            else if (colName == "siginfo")
            {
                return(sigInfo_);
            }
            else if (colName == "a")
            {
                String ret = App.ds_.Ref(Info.A, stock.dataList_, App.ds_.index(stock, date_), 0).ToString("F0");
                colValCacheDict_[colName] = ret;
                return(ret);
            }
            else
            {
                throw new ArgumentException("想要显示无效的列值: " + colName);
            }
        }