Beispiel #1
0
        private void btnCalcYdnAndBifa_Click(object sender, EventArgs e)
        {
            DataSet yuce = new AppYuceDAL().GetAllYuce();
            DataSet kaijiang = new KaijiangDAL().GetAllKaijiang();
            DataSet bifa = new SuperBifaDAL().GetAllBifa();

            double minShouyi = double.MaxValue;
            double maxShouyi = double.MinValue;
            string mindate = "";
            string maxdate = "";
           

            double totalshouyi = 0.0;
            double defaultTouru = 200;
            foreach (DataRow yuceRow in yuce.Tables[0].Rows)
            {
                string yuceriqi = yuceRow["riqi"].ToString();
                string yucebianhao = yuceRow["bianhao"].ToString();
                string yucerangqiushu = yuceRow["rangqiushu"].ToString();
                string yucespfresult = yuceRow["spfresult"].ToString();

                //如果让球数不为0,则不考虑进来
                if(yucerangqiushu != "0")
                {
                    continue;
                }


                DataRow matchedRow = null;
                foreach (DataRow kaijiangrow in kaijiang.Tables[0].Rows)
                {
                    if (kaijiangrow["riqi"].ToString() == yuceriqi && kaijiangrow["bianhao"].ToString() == yucebianhao)
                    {
                        matchedRow = kaijiangrow;
                        break;
                    }
                }

                DataRow matchRowBifa = null;
                foreach (DataRow bifarow in bifa.Tables[0].Rows)
                {
                    if (bifarow["riqi"].ToString() == yuceriqi && bifarow["bianhao"].ToString() == yucebianhao)
                    {
                        matchRowBifa = bifarow;
                        break;
                    }
                }
                //如果找不到记录
                if (matchedRow == null || matchRowBifa == null)
                {
                    continue;
                }
                double dae_sheng = Convert.ToDouble(matchRowBifa["dae_sheng"]);
                double dae_ping = Convert.ToDouble(matchRowBifa["dae_ping"]);
                double dae_fu = Convert.ToDouble(matchRowBifa["dae_fu"]);


                bool flag = IsSameResult(yucespfresult, dae_sheng,dae_ping,dae_fu);
                if (flag)
                {
                    totalshouyi = totalshouyi - defaultTouru;
                    double shengsp = 0.0;
                    double pingsp = 0.0;
                    double fusp = 0.0;
                    int spfresult = 0;
                    double spfresultsp = 0.0;
                    if (yucerangqiushu == "0")
                    {
                        shengsp = Convert.ToDouble(matchedRow["shengsp"]);
                        pingsp = Convert.ToDouble(matchedRow["pingsp"]);
                        fusp = Convert.ToDouble(matchedRow["fusp"]);
                        spfresult = Convert.ToInt32(matchedRow["spfresult"]);
                        spfresultsp = Convert.ToDouble(matchedRow["spfsp"]);

                    }
                    else
                    {
                        shengsp = Convert.ToDouble(matchedRow["rqshengsp"]);
                        pingsp = Convert.ToDouble(matchedRow["rqpingsp"]);
                        fusp = Convert.ToDouble(matchedRow["rqfusp"]);
                        spfresult = Convert.ToInt32(matchedRow["rqspfresult"]);
                        spfresultsp = Convert.ToDouble(matchedRow["rqspfsp"]);
                    }
                    //首先要判断是否中奖
                    if (yucespfresult.Trim().IndexOf(spfresult.ToString()) != -1)
                    {
                        if (yucespfresult.Trim().Length == 1)
                        {
                            if (yucespfresult == spfresult.ToString())
                            {

                                totalshouyi = totalshouyi + defaultTouru * spfresultsp;
                            }
                        }
                        else
                        {
                            //第一个预测结果中奖的情况
                            string firstString = yucespfresult.Substring(0, 1);
                            double firstsp = GetMatchedSp(firstString, shengsp, pingsp, fusp);

                            string secondString = yucespfresult.Substring(1, 1);
                            double secondsp = GetMatchedSp(secondString, shengsp, pingsp, fusp);
                            if (secondsp == 0)
                            {
                                MessageBox.Show("数据不完整");
                            }
                            if (firstString == spfresult.ToString())
                            {
                                totalshouyi = totalshouyi + firstsp * (defaultTouru - defaultTouru / secondsp);

                            }
                            else
                            {
                                totalshouyi = totalshouyi + 200;
                            }


                        }
                    }
                    if (totalshouyi > maxShouyi)
                    {
                        maxShouyi = totalshouyi;
                        maxdate = yuceriqi;
                    }
                    if (totalshouyi < minShouyi)
                    {
                        minShouyi = totalshouyi;
                        mindate = yuceriqi;
                    }
                }                

            }

            MessageBox.Show("总收益为" + totalshouyi + ",过程最大收益为" + maxShouyi + "日期为" + maxdate + ",过程最小收益为" + minShouyi + "日期为" + mindate);

        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //计算收益和最大回撤

            //1.获取需要计算的数据
            DataSet ds = new SuperBifaDAL().GetBifaAndKaijiang();

            int singletouzhu = 200;
            double totalShouyi = 0.0;
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                double dae_sheng = Convert.ToDouble(row["dae_sheng"]);
                double dae_ping = Convert.ToDouble(row["dae_ping"]);
                double dae_fu = Convert.ToDouble(row["dae_fu"]);
                double shengsp = Convert.ToDouble(row["shengsp"]);
                double pingsp = Convert.ToDouble(row["pingsp"]);
                double fusp = Convert.ToDouble(row["fusp"]);
                if (dae_sheng == 0 && dae_ping == 0 && dae_fu == 0)
                {
                    continue;
                }
                if (shengsp == 0 && pingsp == 0 && fusp == 0)
                {
                    continue;
                }
                totalShouyi = totalShouyi - singletouzhu;

                double dae_prize_rank = Convert.ToDouble(row["dae_prize_rank"]);
                //先用最基本策略计算,1概率来赚钱,2概率来保本
                double p2 = GetZhuanqianSp(shengsp, pingsp, fusp, dae_sheng, dae_ping, dae_fu);
                double p1 = GetBaobenSp(shengsp, pingsp, fusp, dae_sheng, dae_ping, dae_fu);

                if (dae_prize_rank == 1)
                {
                    totalShouyi = totalShouyi + 200 * p1 * p2 / (p1 + p2);
                }
                else if (dae_prize_rank == 2)
                {
                    totalShouyi = totalShouyi + 200 * p1 * p2 / (p1 + p2);
                }


            }

            MessageBox.Show("最后收益为" + totalShouyi);
        }
        private void btnLoadData_Click(object sender, EventArgs e)
        {
            GraphPane myPane = zedGraphControl1.GraphPane;
            // get a reference to the GraphPane  

            // Set the Titles  
            myPane.Title.Text = "彩票收益曲线";
            myPane.XAxis.Title.Text = "时间";
            myPane.YAxis.Title.Text = "收益";

            // Make up some data arrays based on the Sine function  

            double x, y1, y2;


            PointPairList list1 = new PointPairList();

            DataSet bifa = new SuperBifaDAL().GetAllBifa();

            DateTime startDate = dateTimePicker1.Value;

            double threshold = Convert.ToDouble(textBox1.Text);

            double totalTouru = 0.0;

            double totalShouyi = 0.0;

            double totalPrize = 0.0;

            DateTime markedStartDate = new DateTime(1900, 1, 1);

            foreach (DataRow row in bifa.Tables[0].Rows)
            {
                
                //按照一天来算更有意义
                DateTime date = Convert.ToDateTime(row["riqi"].ToString());
                if (startDate > date)
                {
                    continue;
                }
                double first_sp = Convert.ToDouble(row["first_sp"].ToString());
                if (first_sp == 0 || first_sp >= threshold)
                {
                    continue;
                }
                int dae_prize_rank = Convert.ToInt32(row["dae_prize_rank"].ToString());
                double second_sp = Convert.ToDouble(row["second_sp"].ToString());

                totalTouru += 1;
                if (dae_prize_rank == 2)
                {
                    totalPrize += 1 * second_sp;

                }
                
                totalShouyi = totalPrize - totalTouru;
                if (markedStartDate != date)
                {
                    if (markedStartDate.ToString("yyyy-MM-dd") == "1900-01-01")
                    {
                        list1.Add(-1, 0);
                    }else
                    {
                        TimeSpan ts = date - startDate;
                        list1.Add(ts.Days, totalShouyi);
                    }
                    markedStartDate = date;
                   
                }
                

            }

            //PointPairList list2 = new PointPairList();
            
            
            
            
            
            //for (int i = 0; i < 36; i++)
            //{
            //    x = (double)i + 5;
            //    y1 = 1.5 + Math.Sin((double)i * 0.2);
            //    y2 = 3.0 * (1.5 + Math.Sin((double)i * 0.2));
            //    list1.Add(x, y1);
               
            //}

            // Generate a red curve with diamond  

            // symbols, and "Porsche" in the legend  

            LineItem myCurve = myPane.AddCurve("收益曲线", list1, Color.Red, SymbolType.Diamond);

            // Generate a blue curve with circle  

            // symbols, and "Piper" in the legend  

            //LineItem myCurve2 = myPane.AddCurve("Piper", list2, Color.Blue, SymbolType.None);

            // Tell ZedGraph to refigure the  

            // axes since the data have changed  

            // zedGraphControl1.GraphPane.AddCurve(" ", b, d, Color.Green, SymbolType.Triangle);  
            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();  
        }