content: # coding: utf-8
  
  #read in libraries
  import cPickle as pickle
  from webcrawler import coredump
  from dataloader import get_trawled_data, introduce_weighting
  from ratings import PowerRater
  from history import historical, model_the_model
  from predict import predict
  from oddsmaker import read_odds
  from betting import wager
  
  csv_file = 'NBA_data_2015' # whence the data come
  weight_factor = 60 # number of days over which to decrease the weight by 40%
  # weight factor needs justification
  HCA = 1.8
  sigma = 13.5
  
  # ask user for guidence on reading in data from web and write to csv file
  user_input = raw_input("Do you want to trawl the web for the latest data? ")
  if user_input in ['y', 'Y', 'yes', 'Yes', 'YES']:
      website = 'http://www.basketball-reference.com/leagues/NBA_2016_games.html'
      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
  # model the 538 model
  