def revise_history(PvA_df, web_df, weight_factor, date, HCA, stdev): yesterday = max(web_df['Date']) planned_picklehood = False while date < yesterday: planned_picklehood = True date += timedelta(days=1) # updata is an updated, temporary copy of the data trawled from the web. In addition to the trawled data it contains a weighting factor. It is temporary because we will be going back in time to make historical predictions, and we want the weights to be what they would actually have been back in the day updata = introduce_weighting(web_df, weight_factor, date) # add weights column PwrRt = PowerRater(updata[updata['Date']<date]).power_ratings todays_data = updata[updata['Date']==date] for i in xrange(todays_data.shape[0]): home = todays_data.iloc[i]['Home'] away = todays_data.iloc[i]['Away'] prob = predict(todays_data.iloc[i], PwrRt, HCA, stdev) outcome = [0,1][todays_data.iloc[i]['Home Score']>todays_data.iloc[i]['Away Score']] PvA_df.loc[PvA_df.shape[0]] = (date, away, home, prob, outcome) return PvA_df, planned_picklehood
coredump(website, csv_file) #load data from csv as a pandas DataFrame data = get_trawled_data(csv_file, ['Date', 'Away', 'Away Score', 'Home', 'Home Score']) # compile a list of historical predictions and actual outcomes history_file = 'Predictive_outcomes_2015' past_predictions = historical(data, weight_factor, history_file, HCA, sigma) # get the fit parameters needed to correct errors in the historical model beta_correct = model_the_model(past_predictions) print 'Checking on the model parameters: %s' % beta_correct # make predictions todays_schedule = pickle.load(open('Today', 'rb')) data = introduce_weighting(data, weight_factor,home_court_advantage=HCA) # add weights column PwrRt = PowerRater(data).power_ratings # generate latest ratings print PwrRt.sort_values(by='rating', ascending=False) prob = [] for i in xrange(todays_schedule.shape[0]): prob.append(predict(todays_schedule.iloc[i], PwrRt, HCA, sigma)) todays_schedule['Prob'] = prob # pull in odds odds = read_odds('Odds.csv', todays_schedule) # determine optimal betting strategy print wager(odds) # pull in 538 predictions