def one_match_simulator(
    home_goalkeeper,
    home_defenders,
    home_midfielders,
    home_forwards,
    away_goalkeeper,
    away_defenders,
    away_midfielders,
    away_forwards,
    model_name='/Users/bgrantham/Documents/Personal/fifa-ratings-predictor/fifa_ratings_predictor'
    '/deep-models'
    '-all/deep'):
    home_defenders = home_defenders + [0] * (6 - len(home_defenders))
    away_defenders = away_defenders + [0] * (6 - len(away_defenders))
    home_midfielders = home_midfielders + [0] * (7 - len(home_midfielders))
    away_midfielders = away_midfielders + [0] * (7 - len(away_midfielders))
    home_forwards = home_forwards + [0] * (4 - len(home_forwards))
    away_forwards = away_forwards + [0] * (4 - len(away_forwards))

    home_feature_vector = home_goalkeeper + home_defenders + home_midfielders + home_forwards
    away_feature_vector = away_goalkeeper + away_defenders + away_midfielders + away_forwards

    feature_vector = normalise_features(
        np.array(home_feature_vector + away_feature_vector)).reshape(1, 36)

    net = NeuralNet()
    probability = net.predict(feature_vector, model_name)

    return probability[0]
    def simulate_monte_carlo(self,
                             number_of_simulations,
                             verbose=False,
                             normalise=True):

        for k, v in self.predicted_lineups.items():
            self.predicted_lineups[k] = normalise_features(v)

        probabilities = self.get_match_probabilities(self.fixtures,
                                                     verbose=verbose)

        results = self.get_match_results_from_probabilities(
            probabilities, number_of_simulations)

        for i in tqdm(range(number_of_simulations),
                      desc='running_simulations',
                      disable=not verbose):
            self.run_season(self.fixtures, [x[i] for x in results])

        if normalise:
            self.normalise_season_values(number_of_simulations)

        df = self.convert_to_pandas(write_to_csv=self.write_to_csv)

        return df
Example #3
0
def one_match_simulator(home_goalkeeper, home_defenders, home_midfielders, home_forwards, away_goalkeeper,
                        away_defenders, away_midfielders, away_forwards,
                        model_name='/Users/offera/Desktop/Personal Projects/betPredictor/pl-predictions-using-fifa/fifa_ratings_predictor'
                                   '/models/E0'
                                   '/deep'):
    home_defenders = home_defenders + [0] * (6 - len(home_defenders))
    away_defenders = away_defenders + [0] * (6 - len(away_defenders))
    home_midfielders = home_midfielders + [0] * (7 - len(home_midfielders))
    away_midfielders = away_midfielders + [0] * (7 - len(away_midfielders))
    home_forwards = home_forwards + [0] * (4 - len(home_forwards))
    away_forwards = away_forwards + [0] * (4 - len(away_forwards))

    home_feature_vector = home_goalkeeper + home_defenders + home_midfielders + home_forwards
    away_feature_vector = away_goalkeeper + away_defenders + away_midfielders + away_forwards

    feature_vector = normalise_features(np.array(home_feature_vector + away_feature_vector)).reshape(1, 36)

    net = NeuralNet()
    probability = net.predict(feature_vector, model_name)

    return probability[0]
    tf.set_random_seed(8)
    np.random.seed(8)

    league = 'F1'

    inputs = np.vstack(
        (np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/feature-vectors-13-14.npy'),
         np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/feature-vectors-14-15.npy'),
         np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/feature-vectors-15-16.npy'),
         np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/feature-vectors-16-17.npy')))
    inputs = normalise_features(inputs)
    outputs = np.vstack(
        (np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/targets-13-14.npy'),
         np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/targets-14-15.npy'),
         np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/targets-15-16.npy'),
         np.load('./data/lineup-data/' + league +
                 '/processed-numpy-arrays/targets-16-17.npy'))).reshape(-1, 3)

    nan_rows = np.where(outputs != outputs)[0]

    inputs = np.delete(inputs, nan_rows, axis=0)
    outputs = np.delete(outputs, nan_rows, axis=0)
Example #5
0
def main():
    bet_tracker = BetTracker()

    league = 'E0'

    match_data = read_match_data(season='2016-2017', league=league)

    match_data = assign_odds_to_match(match_data, read_all_football_data(league=league))

    player_data = read_player_data(season='2016-2017')

    net = NeuralNet()

    bank = [100]

    all_odds = []

    errors = []

    cached_players = {}

    feature_vectors = []

    for match in match_data:

        try:

            home_players_matched, cached_players = match_lineups_to_fifa_players(match['info']['home lineup names'],
                                                                                 match['info']['home lineup raw names'],
                                                                                 match['info']['home lineup numbers'],
                                                                                 match['info'][
                                                                                     'home lineup nationalities'],
                                                                                 constants.LINEUP_TO_PLAYER_TEAM_MAPPINGS[
                                                                                     'ALL'][
                                                                                     match['info']['home team']],
                                                                                 match['info']['season'],
                                                                                 player_data, cached_players)

            away_players_matched, cached_players = match_lineups_to_fifa_players(match['info']['away lineup names'],
                                                                                 match['info']['away lineup raw names'],
                                                                                 match['info']['away lineup numbers'],
                                                                                 match['info'][
                                                                                     'away lineup nationalities'],
                                                                                 constants.LINEUP_TO_PLAYER_TEAM_MAPPINGS[
                                                                                     'ALL'][
                                                                                     match['info']['away team']],
                                                                                 match['info']['season'],
                                                                                 player_data, cached_players)

            home_feature_vector = create_feature_vector_from_players(home_players_matched)
            away_feature_vector = create_feature_vector_from_players(away_players_matched)

            feature_vector = np.array(home_feature_vector + away_feature_vector).reshape(-1, 36)

            feature_vectors.append(normalise_features(feature_vector))

        except Exception as exception:
            print(match['info']['date'], match['info']['home team'], match['info']['away team'])
            print(exception)
            errors.append(match['match number'])

    feature_vectors = np.vstack((x for x in feature_vectors))

    probabilities = net.predict(feature_vectors, model_name='./models/' + league + '/deep')

    match_data = [match for match in match_data if match['match number'] not in errors]

    for match, probability in zip(match_data, probabilities):

        # print(match['info']['date'], match['info']['home team'], match['info']['away team'])

        pred_home_odds, pred_draw_odds, pred_away_odds = [1 / x for x in probability]

        home_odds, draw_odds, away_odds = match['info']['home odds'], match['info']['draw odds'], match['info'][
            'away odds']

        all_odds.append((pred_home_odds, home_odds))
        all_odds.append((pred_away_odds, away_odds))

        if pred_home_odds < home_odds < 3.2 and 0.02 <= probability[0] - 1 / home_odds:
            stake = calculate_stake(home_odds, probability=1 / pred_home_odds, method='kelly',
                                    constant_profit=20) * bet_tracker.bankroll
            profit = stake * home_odds - stake
            bet = Bet(true_odds=home_odds, predicted_odds=pred_home_odds, stake=stake, profit=profit, match=match,
                      type='home')
            bet_tracker.make_bet(bet)
            if match['info']['home goals'] > match['info']['away goals']:
                bet_tracker.bet_won()
            else:
                bet_tracker.bet_lost()
            bank.append(bet_tracker.bankroll)
        elif pred_away_odds < away_odds < 3.2 and 0.02 <= probability[2] - 1 / away_odds:
            stake = calculate_stake(away_odds, probability=1 / pred_away_odds, method='kelly',
                                    constant_profit=20) * bet_tracker.bankroll
            profit = stake * away_odds - stake
            bet = Bet(true_odds=away_odds, predicted_odds=pred_away_odds, stake=stake, profit=profit, match=match,
                      type='away')
            bet_tracker.make_bet(bet)
            if match['info']['home goals'] < match['info']['away goals']:
                bet_tracker.bet_won()
            else:
                bet_tracker.bet_lost()
            bank.append(bet_tracker.bankroll)

    return bet_tracker, bank, all_odds