Exemple #1
0
        static void Main(string[] args)
        {
            const int DAYS_TO_CHECK = 90;
            //DateTime day_to_check = Convert.ToDateTime("5/25/2015");
            SwolepointsRanker ranks = new SwolepointsRanker(DateTime.Today.AddDays(-DAYS_TO_CHECK - 1));
            //Swolepoints ranks = new Swolepoints(DateTime.Today.AddDays(-150), DateTime.Today.AddDays(-7));
            Dictionary<string, HLTVTeam> ranked_teams;
            ranked_teams = ranks.GenerateTrueSkill(DateTime.Today.AddDays(-DAYS_TO_CHECK - 1), DateTime.Today.AddDays(1));
            List<HLTVTeam> teams = new List<HLTVTeam>();
            foreach (HLTVTeam t in ranked_teams.Values)
                teams.Add(t);

            //ranked_teams.RemoveAll(o => o.rating.StandardDeviation > 2.8);
            //ranked_teams.Sort((a, b) => b.elo.CompareTo(a.elo));
            //teams.Sort((a, b) => a.name.CompareTo(b.name));
            teams.Sort((a, b) => b.rating.ConservativeRating.CompareTo(a.rating.ConservativeRating));
            //ranked_teams.Sort((a, b) => b.rating.ConservativeRating.CompareTo(a.rating.ConservativeRating));

            using (StreamWriter w = new StreamWriter("./teams.json"))
            {
                w.WriteLine("Using knowlege of games from " + DateTime.Today.AddDays(1).Date.ToShortDateString() + " at the latest");
                foreach (HLTVTeam t in teams)
                {
                    w.WriteLine(t.name + ": " + Math.Round(t.rating.ConservativeRating * 50) + " (dev: " + t.rating.StandardDeviation + ")");
                }
            }

            ranks.GenerateWinLossChart();
        }
Exemple #2
0
 private void update_rankings(DateTime start, DateTime end)
 {
     teams.Clear();
     SwolepointsRanker ranker = new SwolepointsRanker(start);
     teams = ranker.GenerateTrueSkill(start, end);
 }
Exemple #3
0
        private SimResults SimulateAllParsedMatches(DateTime sim_start, DateTime sim_end,
            double start_bank, string path, bool limit_max, double max_pct, bool make_file)
        {
            SimResults results = new SimResults();
            Dictionary<DateTime, List<Match>> date_map = new Dictionary<DateTime, List<Match>>();
            double daily_bankroll = 0.0f;
            results.start_amt = start_bank;
            results.end_amt = start_bank;
            results.max_gain = -1.0f;
            results.max_loss = -1.0f;
            results.lowest_bankroll = start_bank;
            results.peak_bankroll = start_bank;
            results.wins = 0;
            results.losses = 0;

            foreach (Match m in all_time_matches)
            {
                if (!date_map.ContainsKey(m.match_time.Date))
                    date_map.Add(m.match_time.Date, new List<Match>());

                date_map[m.match_time.Date].Add(m);
            }

            System.IO.StreamWriter file = null;
            if (make_file)
            {
                file = new System.IO.StreamWriter(path, false);
                file.WriteLine(
                    "MatchID" + "\t"
                    + "Date" + "\t"
                    + "Winner" + "\t"
                    + "WnrSwlPts" + "\t"
                    + "WOdds" + "\t"
                    + "Loser" + "\t"
                    + "LsrSwlPts" + "\t"
                    + "LOdds" + "\t"
                    + "Pre-BR" + "\t"
                    + "BetAmt" + "\t"
                    + "NetChg" + "\t"
                    + "%Chg" + "\t"
                    + "Post-BR");
                file.WriteLine(
                    "0000" + "\t" // match id
                    + "00/00/0000" + "\t" // date
                    + "" + "\t" // winner
                    + "0000" + "\t" // winner swolepoints
                    + "0.00" + "\t" // winner odds
                    + "" + "\t" // loser
                    + "0000" + "\t" // loser swolepoints
                    + "0.00" + "\t" // loser odds
                    + results.start_amt + "\t" // pre-br
                    + "0.00" + "\t" // bet amt
                    + "0.00" + "\t" // netchg
                    + "0.00%" + "\t" // %chg
                    + results.end_amt
                ); // post-br
            }
            int skip_games = 0;
            DateTime old_date = DateTime.MinValue;
            DateTime cur_date = DateTime.MinValue;
            SwolepointsRanker ranker = new SwolepointsRanker(sim_start.AddDays(-RANK_DAYS_BACK));
            Dictionary<string, HLTVTeam> rank_teams = null;
            foreach (DateTime day in date_map.Keys)
            {
                if (day < sim_start || day > sim_end.AddMinutes(1440)) continue;
                //daily_bankroll = Math.Truncate(results.end_amt / date_map[day].Count * 100) / 100;
                daily_bankroll = Math.Truncate(results.end_amt / 10 * 100) / 100;

                foreach (Match match in date_map[day])
                {
                    if (match.winner == Winner.NoWinner) continue;

                    if (rank_teams != null && !fits_criteria(match, rank_teams[match.team_a.name], rank_teams[match.team_b.name]))
                    {
                        skip_games++;
                        continue;
                    }

                    cur_date = match.match_time.Date;
                    if (old_date == DateTime.MinValue || cur_date > old_date)
                    {
                        rank_teams = ranker.GenerateTrueSkill(cur_date.AddDays(-RANK_DAYS_BACK), cur_date.AddDays(-1));
                        old_date = cur_date;
                    }

                    if (rank_teams != null && !fits_criteria(match, rank_teams[match.team_a.name], rank_teams[match.team_b.name]))
                    {
                        skip_games++;
                        continue;
                    }

                    bool team_a_favored;
                    double smart_win_chance;
                    bool team_a_smart;
                    double win_probability = get_win_probability(
                        rank_teams[match.team_a.name].rating,
                        rank_teams[match.team_b.name].rating,
                        match.format,
                        out team_a_favored);
                    double rec_bet_pct;

                    if (team_a_favored)
                        rec_bet_pct = get_recommended_bet_pct(win_probability, match.team_a_odds);
                    else
                        rec_bet_pct = get_recommended_bet_pct(win_probability, match.team_b_odds);

                    if (team_a_favored && rec_bet_pct < 0)
                    {
                        // team A has a higher chance of winning, but less of a chance than Lounge says;
                        // therefore, team B is the smarter bet
                        smart_win_chance = (1 - win_probability);
                        team_a_smart = false;
                        rec_bet_pct = get_recommended_bet_pct(smart_win_chance, match.team_b_odds);
                    }
                    else if (team_a_favored && rec_bet_pct >= 0)
                    {
                        // team A has a higher chance of winning by an amount greater than Lounge says;
                        // therefore, team A is still the smarter bet
                        smart_win_chance = win_probability;
                        team_a_smart = true;
                        rec_bet_pct = get_recommended_bet_pct(smart_win_chance, match.team_a_odds);
                    }
                    else if (!team_a_favored && rec_bet_pct < 0)
                    {
                        // team B has a higher chance of winning, but less of a chance than Lounge says;
                        // therefore, team A is the smarter bet
                        smart_win_chance = (1 - win_probability);
                        team_a_smart = true;
                        rec_bet_pct = get_recommended_bet_pct(smart_win_chance, match.team_a_odds);
                    }
                    else
                    {
                        // team B has a higher chance of winning by an amount greater than Lounge says;
                        // therefore, team B is still the smarter bet
                        smart_win_chance = win_probability;
                        team_a_smart = false;
                        rec_bet_pct = get_recommended_bet_pct(smart_win_chance, match.team_b_odds);
                    }

                    double match_change = 0.0f;
                    double bet_amt = 0.0f;
                    if (results.end_amt > 0.03)
                    {
                        if (team_a_smart && match.winner == Winner.TeamA)
                        {
                            // team A won and we bet on it
                            results.wins++;
                            bet_amt = rec_bet_pct * daily_bankroll;
                            if (limit_max)
                                bet_amt = Math.Min(CSGL_MAX_BET, bet_amt);
                            bet_amt = Math.Min(bet_amt, daily_bankroll / max_pct);
                            bet_amt = Math.Truncate(bet_amt * 100) / 100;
                            match_change = Math.Truncate(bet_amt * match.team_a_odds * 100) / 100;
                            if (results.max_gain == -1.0f || results.max_gain < match_change)
                            {
                                results.max_gain = match_change;
                                results.max_gain_match = match;
                            }
                            if (make_file)
                                file.WriteLine(
                                    match.match_id + "\t"
                                    + match.match_time.ToShortDateString() + "\t"
                                    + match.team_a.name + "\t"
                                    + Math.Round(teams[match.team_a.name].rating.ConservativeRating * 50) + "\t"
                                    + match.team_b_pct + "\t"
                                    + match.team_b.name + "\t"
                                    + Math.Round(teams[match.team_b.name].rating.ConservativeRating * 50) + "\t"
                                    + match.team_a_pct + "\t"
                                    + results.end_amt + "\t"
                                    + bet_amt + "\t"
                                    + match_change + "\t"
                                    + Math.Truncate((match_change / results.end_amt) * 100) / 100 + "\t"
                                    + (results.end_amt + match_change));
                            results.end_amt += match_change;
                            if (results.end_amt > results.peak_bankroll) results.peak_bankroll = results.end_amt;
                        }
                        else if (!team_a_smart && match.winner == Winner.TeamB)
                        {
                            // team B won and we bet on it
                            results.wins++;
                            bet_amt = rec_bet_pct * daily_bankroll;
                            if (limit_max)
                                bet_amt = Math.Min(CSGL_MAX_BET, bet_amt);
                            bet_amt = Math.Min(bet_amt, daily_bankroll / max_pct);
                            bet_amt = Math.Truncate(bet_amt * 100) / 100;
                            match_change = Math.Truncate(bet_amt * match.team_b_odds * 100) / 100;
                            if (results.max_gain == -1.0f || results.max_gain < match_change)
                            {
                                results.max_gain = match_change;
                                results.max_gain_match = match;
                            }
                            if (make_file)
                                file.WriteLine(
                                    match.match_id + "\t"
                                    + match.match_time.ToShortDateString() + "\t"
                                    + match.team_b.name + "\t"
                                    + Math.Round(rank_teams[match.team_b.name].rating.ConservativeRating * 50) + "\t"
                                    + match.team_b_pct + "\t"
                                    + match.team_a.name + "\t"
                                    + Math.Round(rank_teams[match.team_a.name].rating.ConservativeRating * 50) + "\t"
                                    + match.team_a_pct + "\t"
                                    + results.end_amt + "\t"
                                    + bet_amt + "\t"
                                    + match_change + "\t"
                                    + Math.Truncate((match_change / results.end_amt) * 100) / 100 + "\t"
                                    + (results.end_amt + match_change)
                            );
                            results.end_amt += match_change;
                            if (results.end_amt > results.peak_bankroll) results.peak_bankroll = results.end_amt;
                        }
                        else if (team_a_smart && match.winner == Winner.TeamB || !team_a_smart && match.winner == Winner.TeamA)
                        {
                            // we lost
                            results.losses++;
                            bet_amt = rec_bet_pct * daily_bankroll;
                            if (limit_max)
                                bet_amt = Math.Min(CSGL_MAX_BET, bet_amt);
                            bet_amt = Math.Min(bet_amt, daily_bankroll / max_pct);
                            bet_amt = Math.Truncate(bet_amt * 100) / 100;
                            match_change = Math.Truncate(bet_amt * 100) / 100;
                            if (results.max_loss == -1.0f || results.max_loss < match_change)
                            {
                                results.max_loss = match_change;
                                results.max_loss_match = match;
                            }
                            if (make_file)
                                file.WriteLine(
                                    match.match_id + "\t"
                                    + match.match_time.ToShortDateString() + "\t"
                                    + (match.rec_bet_a ? match.team_b.name : match.team_a.name) + "\t"
                                    + (match.rec_bet_a ?
                                    Math.Round(rank_teams[match.team_b.name].rating.ConservativeRating * 50)
                                    : Math.Round(rank_teams[match.team_a.name].rating.ConservativeRating * 50)) + "\t"
                                    + (match.rec_bet_a ? match.team_b_pct : match.team_a_pct) + "\t"
                                    + (match.rec_bet_a ? match.team_a.name : match.team_b.name) + "\t"
                                    + (match.rec_bet_a ?
                                    Math.Round(rank_teams[match.team_a.name].rating.ConservativeRating * 50)
                                    : Math.Round(rank_teams[match.team_b.name].rating.ConservativeRating * 50)) + "\t"
                                    + (match.rec_bet_a ? match.team_a_pct : match.team_b_pct) + "\t"
                                    + results.end_amt + "\t"
                                    + bet_amt + "\t"
                                    + -match_change + "\t"
                                    + Math.Truncate((-match_change / results.end_amt) * 100) / 100 + "\t"
                                    + (results.end_amt - match_change)
                                    );
                            results.end_amt -= match_change;
                            if (results.end_amt < results.lowest_bankroll) results.lowest_bankroll = results.end_amt;
                        }
                        results.end_amt = Math.Truncate(results.end_amt * 100) / 100;
                    }
                    else
                        break;
                }
            }
            if (make_file)
                file.Dispose();

            results.net_pct_chg = results.end_amt / results.start_amt - 1;

            return results;
        }