Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
            }
        }