Exemple #1
0
        private void btnStrategy7_Click(object sender, EventArgs e)
        {
            //在策略3的基础上,增加模式识别功能
            //回测策略5,获取sp整数部分为15的比赛,然后每天随机选取一场比赛作为投注


            //1.获取比赛
            DataTable dtStrategy = StrategyDAL.GetStrategy5Data();
            List<MatchShouyi> matches = new List<MatchShouyi>();

            string preriqi = "";
            string curriqi = "";
            double basepeilv = Convert.ToDouble(txtBasePeilv.Text);
            double thresholdPeilv = Convert.ToDouble(txtThresholdPeilv.Text);
            double originalMoney = 1000.0;
            double currentMoney = 1000.0;
            double maxHuiche = 0.0;
            double totalshouyi = 0.0;
            double staticshouyi = 100.0;
            double bestPeilv = 0.0;
            string bestLucky = "";
            preriqi = dtStrategy.Rows[0]["riqi"].ToString();
            int maxFailed = 0;
            int continuedFailed = 0;
            int maxSuccess = 0;
            int continuedSuccess = 3;

            string bestriqi = "";
            string bestbianhao = "";

            double addPercent = Convert.ToDouble(txtAddedPercent.Text);
            List<FootMatch> dayMatches = new List<FootMatch>();

            int maxWaitWin = 2;

            foreach (DataRow row in dtStrategy.Rows)
            {
                string riqi = row["riqi"].ToString();
                double shengsp = Convert.ToDouble(row["shengsp"]);
                string lucky = "2";
                string spfresult = row["spfresult"].ToString();
                if (spfresult == "3")
                {
                    lucky = "1";
                }
                string bianhao = row["bianhao"].ToString();

                FootMatch curMatch = new FootMatch();
                curMatch.Riqi = riqi;
                curMatch.Bianhao = bianhao;
                curMatch.RealPeilv = shengsp;
                curMatch.Lucky = lucky;

                curriqi = riqi;

                if (curriqi == preriqi)
                {
                    dayMatches.Add(curMatch);
                }
                else
                {
                    
                    //选出代表这一天的比赛
                    //这个策略使用随机算法
                    Random rnd = new Random();
                    int matchCount = dayMatches.Count;

                    //a 第一种取随机
                    //int matchIndex = rnd.Next(matchCount);
                    //b 第二种取第一个
                    //int matchIndex = 0;
                    //c 第三种取最后一个
                    //int matchIndex = matchCount - 1;
                    //d 第四种取中间一个
                    int matchIndex = matchCount / 2;

                    FootMatch selMatch = dayMatches[matchIndex];
                    bestPeilv = selMatch.RealPeilv;
                    bestriqi = selMatch.Riqi;
                    bestbianhao = selMatch.Bianhao;
                    bestLucky = selMatch.Lucky;

                    double touru = 0.0;
                    double yuqiShouyi = 100;
                    totalshouyi = totalshouyi + yuqiShouyi;

                    if (bestLucky == "1")
                    {
                        continuedSuccess++;
                        if (continuedSuccess > maxWaitWin)
                        {   
                            //totalshouyi = yuqiShouyi;
                            touru = totalshouyi / (bestPeilv - 1);

                            if (currentMoney - touru > 0)
                            {
                                touru += (currentMoney - touru) * addPercent;

                            }

                            currentMoney -= touru;

                            if (currentMoney < maxHuiche)
                            {
                                maxHuiche = currentMoney;
                            }
                            if (bestLucky == "1")
                            {

                                currentMoney = touru * bestPeilv + currentMoney;
                                totalshouyi = 0.0;
                                continuedFailed = 0;
                                //continuedSuccess++;
                                if (continuedSuccess > maxSuccess)
                                {
                                    maxSuccess = continuedSuccess;
                                }
                            }
                            else
                            {
                                totalshouyi += touru;
                                continuedFailed++;
                                if (continuedFailed > maxFailed)
                                {
                                    maxFailed = continuedFailed;
                                }
                                continuedSuccess = 0;
                            }

                            
                            MatchShouyi match = new MatchShouyi();
                            match.riqi = bestriqi;
                            match.bianhao = bestbianhao;
                            match.lucky = bestLucky;
                            match.shouyi = currentMoney;
                            match.totaltouru = touru;
                            match.totalprize = bestPeilv;
                            match.IsSkip = 0; //设置跳过符号

                            //match.huiche = match.shouyi - match.totaltouru;
                            matches.Add(match);
                        }
                        else 
                        {
                            //如果没有过3,则需要等等,跳过该场比赛
                            MatchShouyi match = new MatchShouyi();
                            match.riqi = bestriqi;
                            match.bianhao = bestbianhao;
                            match.lucky = bestLucky;
                            match.shouyi = currentMoney;
                            match.totaltouru = touru;
                            match.totalprize = bestPeilv;
                            match.IsSkip = 1; //设置跳过符号

                            //match.huiche = match.shouyi - match.totaltouru;
                            matches.Add(match);
                        }
                       

                        
                    }
                    else //if bestlucky = 1
                    {
                        if (continuedSuccess > maxWaitWin - 1)
                        {
                            
                            totalshouyi = totalshouyi + yuqiShouyi;


                            //totalshouyi = yuqiShouyi;
                            touru = totalshouyi / (bestPeilv - 1);

                            if (currentMoney - touru > 0)
                            {
                                touru += (currentMoney - touru) * addPercent;

                            }

                            currentMoney -= touru;

                            if (currentMoney < maxHuiche)
                            {
                                maxHuiche = currentMoney;
                            }
                            MatchShouyi match = new MatchShouyi();
                            match.riqi = bestriqi;
                            match.bianhao = bestbianhao;
                            match.lucky = bestLucky;
                            match.shouyi = currentMoney;
                            match.totaltouru = touru;
                            match.totalprize = bestPeilv;
                            //match.huiche = match.shouyi - match.totaltouru;
                            matches.Add(match);

                            totalshouyi = totalshouyi + touru;
                        }
                        else
                        {
                            MatchShouyi match = new MatchShouyi();
                            match.riqi = bestriqi;
                            match.bianhao = bestbianhao;
                            match.lucky = bestLucky;
                            match.shouyi = currentMoney;
                            match.totaltouru = touru;
                            match.totalprize = bestPeilv;
                            match.IsSkip = 1;
                            //match.huiche = match.shouyi - match.totaltouru;
                            matches.Add(match);
                        }
                        continuedSuccess = 0;
                        //continuedFailed++;
                        //if (continuedFailed > maxFailed)
                        //{
                        //    maxFailed = continuedFailed;
                        //}
                    }
                   
                    dayMatches = new List<FootMatch>();
                    dayMatches.Add(curMatch);
                }

                preriqi = riqi;

            }
            //计算一下回撤
            for (int i = 1; i < matches.Count; i++)
            {
                MatchShouyi match = matches[i];
                MatchShouyi preMatch = matches[i - 1];
                match.huiche = preMatch.shouyi - match.totaltouru;
            }
            dataGridView1.DataSource = matches;
            PrintPicture(matches);
            lblResult.Text = "最终的收益为" + currentMoney + "最大回撤为" + maxHuiche + "最大连续失败次数" + maxFailed + "最大连续成功次数" + maxSuccess;


        }
Exemple #2
0
        private void btnStrategy11_Click(object sender, EventArgs e)
        {
            //策略9的取值逻辑发生变化,使用赢赔率是15,双选压注31,这样的总概率是82.03,
            //投注比例使用低概率保本,高概率盈利模型


            DataTable dtStrategy = StrategyDAL.GetStrategy9Data();
            List<MatchShouyi> matches = new List<MatchShouyi>();

            List<FootMatch> dayMatches = new List<FootMatch>();

            string preriqi = dtStrategy.Rows[0]["riqi"].ToString();
            string curriqi = "";
            double maxHuiche = 0.0;
            double totalshouyi = 0.0;
            double staticshouyi = 100.0;
            double currentMoney = 0.0;

            int maxFailed = 0;
            int continuedFailed = 0;
            int maxSuccess = 0;
            int continuedSuccess = 0;

            int shengcount = 0;
            int pingcount = 0;
            int fucount = 0;
            double shengspsum = 0.0;
            double pingspsum = 0.0;
            double fuspsum = 0.0;


            foreach (DataRow row in dtStrategy.Rows)
            {
                string riqi = row["riqi"].ToString();
                double shengsp = Convert.ToDouble(row["shengsp"]);
                double pingsp = Convert.ToDouble(row["pingsp"]);
                double fusp = Convert.ToDouble(row["fusp"]);
                string lucky = "2";
                string spfresult = row["spfresult"].ToString();
                
                if (spfresult == "3" || spfresult == "1")
                {
                    lucky = "1";
                }
                string bianhao = row["bianhao"].ToString();

                double realsp = pingsp - pingsp/shengsp;                 
                    



                FootMatch curMatch = new FootMatch();
                curMatch.Riqi = riqi;
                curMatch.Bianhao = bianhao;
                curMatch.RealPeilv = realsp;
                curMatch.Lucky = spfresult;
                curMatch.PingPeilv = shengsp;
                curMatch.ShengPeilv = shengsp;
                curMatch.FuPeilv = fusp;

                curriqi = riqi;

                if (curriqi == preriqi)
                {
                    dayMatches.Add(curMatch);
                }
                else
                {
                    //选出代表这一天的比赛
                    //这个策略使用随机算法
                    Random rnd = new Random();
                    int matchCount = dayMatches.Count;

                    //a 第一种取随机
                    int matchIndex = rnd.Next(matchCount);
                    //b 第二种取第一个
                    //int matchIndex = 0;
                    //c 第三种取最后一个
                    //int matchIndex = matchCount - 1;
                    //d 第四种取中间一个
                    //int matchIndex = matchCount / 2;

                    FootMatch selMatch = dayMatches[matchIndex];


                    double yuqiShouyi = 300;
                    //totalshouyi = totalshouyi + yuqiShouyi;
                    totalshouyi = yuqiShouyi;
                    double touru = 300;

                    //totalshouyi = yuqiShouyi;
                    double tourudi = totalshouyi / selMatch.PingPeilv;
                    double tourugao = touru - tourudi;

                    //if (currentMoney - touru > 0)
                    //{
                    //    touru += (currentMoney - touru) * addPercent;

                    //}

                    currentMoney -= touru;

                    if (currentMoney < maxHuiche)
                    {
                        maxHuiche = currentMoney;
                    }
                    if (selMatch.Lucky == "3")
                    {
                        currentMoney = tourudi * selMatch.PingPeilv + currentMoney;
                        totalshouyi = 0.0;
                        continuedFailed = 0;
                        continuedSuccess++;
                        if (continuedSuccess > maxSuccess)
                        {
                            maxSuccess = continuedSuccess;
                        }
                        shengcount++;
                        shengspsum += selMatch.ShengPeilv;
                    }
                    else if (selMatch.Lucky == "1")
                    {
                        currentMoney = touru * selMatch.RealPeilv + currentMoney;
                        totalshouyi = 0.0;
                        continuedFailed = 0;
                        continuedSuccess++;
                        if (continuedSuccess > maxSuccess)
                        {
                            maxSuccess = continuedSuccess;
                        }
                        pingcount++;
                        pingspsum += selMatch.PingPeilv;
                    }
                    else
                    {
                        totalshouyi += touru;
                        continuedFailed++;
                        if (continuedFailed > maxFailed)
                        {
                            maxFailed = continuedFailed;
                        }
                        continuedSuccess = 0;

                        fucount++;
                        fuspsum += selMatch.FuPeilv;
                    }

                    MatchShouyi match = new MatchShouyi();
                    match.riqi = selMatch.Riqi;
                    match.bianhao = selMatch.Bianhao;
                    match.lucky = selMatch.Lucky;
                    match.shouyi = currentMoney;
                    match.totaltouru = touru;
                    match.totalprize = selMatch.RealPeilv;
                    //match.huiche = match.shouyi - match.totaltouru;
                    matches.Add(match);



                    dayMatches = new List<FootMatch>();
                    dayMatches.Add(curMatch);
                }
                preriqi = riqi;
            }
            //计算回撤
            for (int i = 1; i < matches.Count; i++)
            {
                MatchShouyi match = matches[i];
                MatchShouyi preMatch = matches[i - 1];
                match.huiche = preMatch.shouyi - match.totaltouru;
            }
            dataGridView1.DataSource = matches;
            PrintPicture(matches);
            lblResult.Text = "最终的收益为" + currentMoney + "最大回撤为" + maxHuiche + "最大连续失败次数" + maxFailed + "最大连续成功次数" + maxSuccess ;
            lblAdditionInfo.Text = "总的比赛数为:" + matches.Count + "次数" + shengcount + "," +pingcount+ "," +fucount+ "," + "胜sp和" + shengspsum + "," +pingspsum+ "," + fuspsum;

        }