Ejemplo n.º 1
0
        private void SearchData()
        {
            //记录买入时间
            DateTime buytime  = DateTime.Now;
            int      progress = 0;

            int totalnum = StockApp.allstock.Count * pnl_buysell.GetSelectedCombGroup().Length;
            int rulenum  = 0;
            int lastdate = StockDapan.GetLastDate();

            foreach (combineRule combinerule in pnl_buysell.GetSelectedCombGroup())
            {
                Buy  buyitem  = combinerule.buy;
                Sell sellitem = combinerule.sell;
                rulenum++;
                progress = rulenum * StockApp.allstock.Count;
                int            buyvalue = chk_ml.Checked ? Rule.STATUS_BUY_ML : Rule.STATUS_BUY;
                StockOpeItem[] opeitems = StockAnalysisSQL.GetAnalysis2List(buyvalue, fromdate, todate, buyitem.ToString(), sellitem.ToString(),
                                                                            -0.99,  //SCORE
                                                                            false,  //NO DEFAULT apply
                                                                            false); // no restrict max sell date

                foreach (StockOpeItem item in opeitems)
                {
                    //sellprice > 0, 说明已卖出
                    if (chk_hidesold.Checked && item.selldate < Math.Min(lastdate, todate))
                    {
                        continue;
                    }

                    list.Add(item.ToRowInfo());
                }
            }
        }
Ejemplo n.º 2
0
        //如果stockitem kpi被filter
        private bool isfilter(string rulename, StockRuleItem item)
        {
            if (dapanlist == null)
            {
                //初始化 得到该买卖法则filter的规则
                dapanlist = StockRuleSQL.GetDapanFilter(rulename);
            }
            string dapanstatus = StockDapan.GetDaPanScore(item.date);

            if (dapanlist.Contains(dapanstatus))
            {
                return(false);
            }

            if (filterlist == null)
            {
                //初始化 得到该买卖法则filter的规则
                filterlist = StockRuleSQL.GetRuleFilter(rulename);
            }
            int size = filterlist.Count;

            for (int i = 0; i < size; i++)
            {
                string[] s    = (string[])filterlist[i]; //s包含kpivalue, kpivalue
                string[] kpis = item.kpis.Split(StockApp.seperator);
                //判断当前是否符合filter规则
                //{"kpiname","kpiindex","kpivalue"}
                if (!kpis[Convert.ToInt16(s[1])].ToString().Equals(s[2]))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        private void RefreshDaPan()
        {
            if (!(lst_buy.SelectedItems.Count > 0))
            {
                return;
            }
            if (!(lst_buy.SelectedItems.Count < 2))
            {
                return;
            }
            string rulename = lst_buy.SelectedItems[0].ToString();

            //先所有不选中
            for (int i = 0; i < chkl_status.Items.Count; i++)
            {
                this.chkl_status.SetItemChecked(i, false);
            }

            string    sql = "select * from Rule_filter_dapan where rulename = '" + rulename + "';";
            DataTable dt  = db.GetTable(sql);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                this.chkl_status.SetItemChecked(StockDapan.GetGradeIndex((string)dr["kpiname"]), true);
            }
        }
Ejemplo n.º 4
0
        //计算买卖数据
        private void CalBuy(StockData stock)
        {
            //由设定时间开始分析
            int analyse_startindex = StockApp.START_ANALYSIS;

            int           id       = db.GetMaxTableId(StockSQL.TABLE_RULE_BUY0);
            SQLMassImport rulefile = new SQLMassImport("RuleBuy");

            foreach (Buy rule in GetAllBuy())
            {
                int stock_length = stock.items.Length;

                for (int i = analyse_startindex; i < stock_length; i++)
                {
                    StockItem item = stock.items[i];
                    if (rule.isBuy(stock, i))
                    {
                        id++;
                        string[] attristrs = new string[21];
                        attristrs[0]  = Rule.STATUS_BUY.ToString();
                        attristrs[1]  = id.ToString();
                        attristrs[2]  = rule.ToString();
                        attristrs[3]  = stock.code;
                        attristrs[4]  = item.date.ToString();
                        attristrs[5]  = item.index.ToString();
                        attristrs[6]  = (i < stock_length - 1) ? Math.Min(item.end, stock.items[i + 1].start).ToString() : item.end.ToString();
                        attristrs[7]  = "0"; //pregrade
                        attristrs[8]  = rule.GetScore(stock, item.index).ToString();
                        attristrs[9]  = stock.getKPIs(i);
                        attristrs[10] = stock.getNumKPIs(i);
                        attristrs[11] = StockDapan.GetDaPanScore(item.date).ToString();                           //dapan
                        attristrs[12] = item.kpi[StockApp.DEFAULT_SELLs[0] + StockKPI.default_price].ToString();  //short
                        attristrs[13] = item.kpi[StockApp.DEFAULT_SELLs[1] + StockKPI.default_price].ToString();; //medium
                        attristrs[14] = item.kpi[StockApp.DEFAULT_SELLs[2] + StockKPI.default_price].ToString();; //long
                        attristrs[15] = item.kpi[StockApp.DEFAULT_SELLs[3] + StockKPI.default_price].ToString();  //end

                        int    nextday   = Convert.ToInt32(item.kpi[StockApp.DEFAULT_SELLs[2] + StockKPI.default_date].ToString());
                        double nextprice = Convert.ToDouble(item.kpi[StockApp.DEFAULT_SELLs[2] + StockKPI.default_price].ToString());
                        //去除outline
                        //if (nextprice - item.end * 2 > StockApp.MIN_ZERO
                        //    || nextday - 3000 - item.date > StockApp.MIN_ZERO) continue;
                        //发出买入信号后1~5天的表现,纯参考,未在任何地方使用
                        attristrs[16] = item.attributes[StockAttribute.POST1].ToString();
                        attristrs[17] = item.attributes[StockAttribute.POST2].ToString();;
                        attristrs[18] = item.attributes[StockAttribute.POST3].ToString();;
                        attristrs[19] = item.attributes[StockAttribute.POST4].ToString();;
                        attristrs[20] = item.attributes[StockAttribute.POST5].ToString();;
                        rulefile.AddRow(attristrs);
                    }
                }//foreach

                //UtilLog.AddInfo(TAG, rule.ToString() + " calculation finished. ");
            }
            //导入买入卖出数据
            rulefile.ImportClose(db, StockSQL.TABLE_RULE_BUY0);
            UtilLog.AddInfo(TAG, stock.code + " RuleBuy calculation finished. ");
        }
Ejemplo n.º 5
0
        //同步股票数据
        //2018-03-14 Reviewed
        private void SyncData()
        {
            //更新进度
            int statusNum = 0;

            //删除已有股票
            StockSQL.DeleteStock();
            this.btn_syncData.Enabled = false;

            foreach (object obj in filelist)
            {
                statusNum++;
                string filename = (string)obj;

                StockData stock = new StockData();
                stock.Init(filename);
                UtilLog.AddInfo(TAG, "Start to analyse " + stock.code + ";");
                StockAttribute attri = new StockAttribute(stock);
                StockKPI       kpi   = new StockKPI(stock);

                if (!stock.IsValid())
                {
                    UtilLog.AddInfo(TAG, statusNum + "/" + filelist.Count + "  " + stock.code + " skipped");
                }
                else
                {
                    attri.InitAttribute();
                    kpi.InitKPI();

                    StockSQL.InsertStockWithItem(stock);
                    UtilLog.AddInfo(TAG, statusNum + "/" + filelist.Count + "  " + stock.code + " initialization finished");
                }
                int status = statusNum * 100 / filelist.Count;
                if (statusNum % 100 == 0)
                {
                    GC.Collect();
                }
                prog.SetProgress(status);
            }
            StockData.SetStockFull();
            StockDapan.InsertStockDaPan();
            this.btn_syncData.Enabled = true;
        }