Ejemplo n.º 1
0
        public bool collectRateItemHistory(RegressResult re,
                                           out Dictionary <String, HistoryData> strategyRateItemHistoryData,
                                           out List <HistoryData> dataList,
                                           out List <String> rateItemList
                                           )
        {
            Dictionary <String, List <SelectItem> > rateItemDict = RegressResult.ToRateItemDict(re.selItems_);
            var sortDict = from objDic in rateItemDict orderby objDic.Key select objDic;

            dataList     = new List <HistoryData>();
            rateItemList = new List <string>();
            strategyRateItemHistoryData = new Dictionary <string, HistoryData>();
            foreach (var kv in sortDict)
            {
                if (kv.Value.Count < 20)
                {
                    continue;
                }
                rateItemList.Add(kv.Key);
                List <DateSelectItem> items = RegressResult.ToDaySelectItemList(kv.Value, re.dateRangeList_);
                HistoryData           data  = StrategyAsset.GetHistoryData(items, 0, items.Count, RunMode.RM_Raw);
                dataList.Add(data);
            }
            if (dataList.Count == 0)
            {
                return(false);
            }
            for (int i = 0; i < rateItemList.Count; ++i)
            {
                strategyRateItemHistoryData[rateItemList[i]] = dataList[i];
            }
            return(true);
        }
Ejemplo 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
        public bool writeAssetForAllSingleStrategy(String dateRangeName)
        {
            DB.Global().Execute(String.Format("Delete From stra_his"));
            DB.Global().Execute(String.Format("Delete From stra_opt"));
            foreach (var item in App.autoSolutionSettingList_)
            {
                if (item.name_ == "$All" || item.name_ == "$Tmp")
                {
                    continue;
                }
                RegressResult re = new RegressResult();
                re.runMode_       = RunMode.RM_Raw;
                re.name_          = item.name_ + "-" + dateRangeName;
                re.solutionName_  = item.name_;
                re.dateRangeName_ = dateRangeName;
                re.dateRangeList_ = App.DateRange(dateRangeName).rangeList_;
                re.strategyList_  = App.Solution(item.name_).straList_;

                if (re.EndDate >= Utils.LastTradeDay())
                {
                    if (!App.ds_.prepareForSelect())
                    {
                        MessageBox.Show("准备数据工作失败,无法继续执行!");
                        return(false);
                    }
                }
                RegressManager regressManager = new RegressManager();
                regressManager.regress(re);

                List <DateSelectItem> items = RegressResult.ToDaySelectItemList(re.selItems_, re.dateRangeList_);
                re.reHistory_ = StrategyAsset.GetHistoryData(items, 0, items.Count, re.runMode_);

                Dictionary <String, HistoryData> strategyRateItemHistoryData;
                List <HistoryData> dataList;
                List <String>      rateItemList;
                App.asset_.collectRateItemHistory(re, out strategyRateItemHistoryData, out dataList, out rateItemList);
                StrategyAsset.WriteStrategyAsset(re.strategyList_[0], re.reHistory_, strategyRateItemHistoryData);

                Dictionary <String, Object> straDataDict = re.reHistory_.toDictionary("");
                straDataDict["straname"] = re.solutionName_;
                DB.Global().Insert("stra_opt", straDataDict);
            }
            App.asset_.readAssetFromDB();
            App.host_.uiSetMsg("Write asset completed.");
            return(true);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 public static void RemoveRegress(RegressResult re)
 {
     App.regressList_.Remove(re);
 }