Example #1
0
def getAllOdds(year):
    df = getDataSet('DataForModel_' + year + '.xlsx')
    dates = df.GAME_DATE_EST_x_x.unique()
    dfall = getDataSet('Historical_Odds_' + year + '.xlsx')
    done = dfall.GAME_DATE_EST_x.unique()
    for i in dates:
        if i > done[-1]:
            x = i
            i = i[:10]
            i = i.replace("-", "")
            print(i)
            df = main(i)
            # df = getDataSet('Todays_Odds.xlsx')
            df['AwayTeam'] = df.apply(getTeams, axis=1)
            df['HomeTeam'] = df.apply(getOppTeams, axis=1)
            df['key'] = df['key'].astype(str)
            df['GAMECODE_x'] = df.apply(getGameCodeODDS, axis=1)
            df['VegasLines'] = df.apply(filterOdds, axis=1)
            df['TEAM_ABBREVIATION_x_x'] = df['AwayTeam']
            df = pd.DataFrame({
                'GAMECODE_x':
                df['GAMECODE_x'],
                'TEAM_ABBREVIATION_x_x':
                df['TEAM_ABBREVIATION_x_x'],
                'VegasLines':
                df['VegasLines'],
                'GAME_DATE_EST_x':
                x
            })
            # saveToExcel(df,'Todays_Odds.xlsx','Master')
            # dfh = getDataSet('Historical_Odds.xlsx')
            dfall = dfall.append(df)
        saveToExcel(dfall, 'Historical_Odds_' + year + '.xlsx', 'Master')
Example #2
0
def backtest():
    # ----Add in ability so select certain models--------------
    odds = GetOdds()
    df = getDataSet('DataForModel_' + year + '.xlsx')
    startDate = '2017-10-31T00:00:00'
    df = df.loc[df['GAME_DATE_EST_x'] >= startDate]
    actual = getDataSet('AllStats_' + year + '.xlsx')
    proj = RunModels(df, odds)
    getResults(actual, proj, 'ALL')
Example #3
0
def backtest(year, both):
    odds = getDataSet('Historical_Odds_' + year + '.xlsx')
    if both:
        odds1 = getDataSet('Historical_Odds_' + '2015' + '.xlsx')
        odds2 = getDataSet('Historical_Odds_' + '2016' + '.xlsx')
        frames = [odds1, odds2]
        odds = pd.concat(frames)
    df = getDataSet('DataForModel_' + year + '.xlsx')
    if both:
        df1 = getDataSet('DataForModel_' + '2015' + '.xlsx')
        df2 = getDataSet('DataForModel_' + '2016' + '.xlsx')
        frames = [df1, df2]
        df = pd.concat(frames)
    actual = getDataSet('AllStats_' + year + '.xlsx')
    if both:
        actual1 = getDataSet('AllStats_' + '2015' + '.xlsx')
        actual2 = getDataSet('AllStats_' + '2016' + '.xlsx')
        frames = [actual1, actual2]
        actual = pd.concat(frames)
    Regression(df)
    proj = RunModels(df, odds)
    results = getResults(actual, proj, 'Backtest')
    # dfr = pd.merge(dfd, results, on=['GAMECODE_x','TEAM_ABBREVIATION_x'],how='left')
    # saveToExcel(dfr,'BackTest_Data.xlsx','Master')
    dfb = getResultSummary(results)
    if both:
        saveToExcel(dfb, 'BackTest_Summary.xlsx', 'Both')
    if not both:
        saveToExcel(dfb, 'BackTest_Summary.xlsx', year)
Example #4
0
def GetYesterdaysData():
    yesterdaysGames = getGames(yesterday)
    df = getADVStats(yesterdaysGames)
    saveToExcel(df, 'yesterdaysGames.xlsx', 'Master')
    df1 = getDataSet('AllStats_' + year + '.xlsx')
    df2 = getDataSet('yesterdaysGames.xlsx')
    df4 = df1.tail(1)
    x = df4['GAMECODE'].str[:9].values
    df5 = df2.head(1)
    y = df5['GAMECODE'].str[:9].values
    df3 = df1.append(df2)
    if x != y:
        saveToExcel(df3, 'AllStats_' + year + '.xlsx', 'Master')
    return df3
Example #5
0
def liveResults():
    todaysGames = getGames(today)
    df = getADVStats(todaysGames)
    df['GAMECODE_x'] = df['GAMECODE']
    df['TEAM_ABBREVIATION_x'] = df['TEAM_ABBREVIATION']
    actual = df[['GAMECODE_x', 'TEAM_ABBREVIATION_x', 'PTS']]
    projected = getDataSet('Projections.xlsx')
    getResults(actual, projected, 'Todays')
Example #6
0
def CalcStats(year):
    # ---------------- Split data out by team and calculate stats ------------------------
    dataset = getDataSet('AllStats_'+ year + '.xlsx')
    SplitTeams(dataset,year)
    # ---------------- Consume team data from tabs to make one dataset and combine both teams onto one line------------------------
    d1 = getFirstSplit(year)
    # #---------------- Cosolidate split team data, remove first 6 rows without Last 5 calcs, Filter only needed columns------------------------
    teamdata4 = trimDF(d1)
    print('Stat Calculation Complete')
Example #7
0
def GetOdds():
    df1 = getDataSet('Historical_Odds_' + '2017' + '.xlsx')
    if fetchOdds:
        scrapeOdds()
        df = getDataSet('Todays_Odds.xlsx')
        df['AwayTeam'] = df.apply(getTeams, axis=1)
        df['HomeTeam'] = df.apply(getOppTeams, axis=1)
        df['key'] = df['key'].astype(str)
        df['GAMECODE_x'] = df.apply(getGameCodeODDS, axis=1)
        df['VegasLines'] = df.apply(filterOdds, axis=1)
        df['TEAM_ABBREVIATION_x_x'] = df['AwayTeam']
        df = df[['GAMECODE_x', 'TEAM_ABBREVIATION_x_x', 'VegasLines']]
        saveToExcel(df, 'Todays_Odds.xlsx', 'Master')
        df1 = df1.append(df)
        saveToExcel(df1, 'Season_Odds.xlsx', 'Master')

    # df3 = df1.tail(1)
    # x = df3['GAMECODE_x'].str[:9].values
    # df4 =df.head(1)
    # y = df4['GAMECODE_x'].str[:9].values
    # if x != y:
    #     df2 = df1.append(df)
    #     saveToExcel(df2,'Season_Odds.xlsx','Master')
    return df1
Example #8
0
def GetTodaysData():
    todaysGames = getTodaysGames(today)
    game = []
    df = getDataSet('DataForModel_' + year + '.xlsx')
    # df = df.dropna()
    for i in todaysGames:
        hometeam = i[12:]
        awayteam = i[9:12]
        game.append([hometeam, awayteam])
    print(game)

    dfb = pd.DataFrame(columns=[
        'Match', 'GAMECODE_x', 'GAME_DATE_x', 'TEAM_ABBREVIATION_x_x',
        'HomeIndex_x_x', 'DaysRest_x', 'AvgPace_x_x', 'AvgORTG_x_x',
        'AvgDRTG_x_x', 'AvgORTG_L5_x_x', 'AvgDRTG_L5_x_x', 'std_AvgORTG_x_x',
        'std_AvgDRTG_x_x', 'std_AvgORTG_L5_x_x', 'std_AvgDRTG_L5_x_x',
        'HomeORTG_x_x', 'HomeDRTG_x_x', 'AwayORTG_x_x', 'AwayDRTG_x_x',
        'Location_Avg_ORTG_x_x', 'DaysRest_y', 'AvgPace_x_y', 'AvgORTG_x_y',
        'AvgDRTG_x_y', 'AvgORTG_L5_x_y', 'AvgDRTG_L5_x_y', 'std_AvgORTG_x_y',
        'std_AvgDRTG_x_y', 'std_AvgORTG_L5_x_y', 'std_AvgDRTG_L5_x_y',
        'HomeORTG_x_y', 'HomeDRTG_x_y', 'AwayORTG_x_y', 'AwayDRTG_x_y',
        'Location_Avg_ORTG_x_y'
    ])
    for x in game:
        match = x[1] + x[0]

        df1 = df.loc[df['TEAM_ABBREVIATION_x'] == x[0]]
        df2 = df.loc[df['TEAM_ABBREVIATION_x'] == x[1]]
        df1 = df1.tail(1)
        df2 = df2.tail(1)
        df1['Match'] = match
        df2['Match'] = match
        df1['GAME_DATE'] = pd.to_datetime(df1['GAMECODE'].str[:9])
        df2['GAME_DATE'] = pd.to_datetime(df2['GAMECODE'].str[:9])
        df1['today'] = pd.to_datetime(today)
        df2['today'] = pd.to_datetime(today)
        df1['DaysRest'] = (df1['today'] -
                           df1['GAME_DATE']).astype('timedelta64[D]')
        df2['DaysRest'] = (df2['today'] -
                           df2['GAME_DATE']).astype('timedelta64[D]')
        df3 = pd.merge(df1, df2, on='Match', how='outer')
        df4 = pd.merge(df2, df1, on='Match', how='outer')
        date = today.replace("-", "")
        df3['date'] = date
        df4['date'] = date
        df3['GAMECODE_x'] = df3.apply(getGameCodeToday, axis=1)
        df4['GAMECODE_x'] = df4.apply(getGameCodeToday, axis=1)
        # print(df4.head())
        df3 = df3[[
            'Match', 'GAMECODE_x', 'GAME_DATE_x', 'TEAM_ABBREVIATION_x_x',
            'HomeIndex_x_x', 'DaysRest_x', 'AvgPace_x_x', 'AvgORTG_x_x',
            'AvgDRTG_x_x', 'AvgORTG_L5_x_x', 'AvgDRTG_L5_x_x',
            'std_AvgORTG_x_x', 'std_AvgDRTG_x_x', 'std_AvgORTG_L5_x_x',
            'std_AvgDRTG_L5_x_x', 'HomeORTG_x_x', 'HomeDRTG_x_x',
            'AwayORTG_x_x', 'AwayDRTG_x_x', 'Location_Avg_ORTG_x_x',
            'DaysRest_y', 'AvgPace_x_y', 'AvgORTG_x_y', 'AvgDRTG_x_y',
            'AvgORTG_L5_x_y', 'AvgDRTG_L5_x_y', 'std_AvgORTG_x_y',
            'std_AvgDRTG_x_y', 'std_AvgORTG_L5_x_y', 'std_AvgDRTG_L5_x_y',
            'HomeORTG_x_y', 'HomeDRTG_x_y', 'AwayORTG_x_y', 'AwayDRTG_x_y',
            'Location_Avg_ORTG_x_y'
        ]]
        df4 = df4[[
            'Match', 'GAMECODE_x', 'GAME_DATE_x', 'TEAM_ABBREVIATION_x_x',
            'HomeIndex_x_x', 'DaysRest_x', 'AvgPace_x_x', 'AvgORTG_x_x',
            'AvgDRTG_x_x', 'AvgORTG_L5_x_x', 'AvgDRTG_L5_x_x',
            'std_AvgORTG_x_x', 'std_AvgDRTG_x_x', 'std_AvgORTG_L5_x_x',
            'std_AvgDRTG_L5_x_x', 'HomeORTG_x_x', 'HomeDRTG_x_x',
            'AwayORTG_x_x', 'AwayDRTG_x_x', 'Location_Avg_ORTG_x_x',
            'DaysRest_y', 'AvgPace_x_y', 'AvgORTG_x_y', 'AvgDRTG_x_y',
            'AvgORTG_L5_x_y', 'AvgDRTG_L5_x_y', 'std_AvgORTG_x_y',
            'std_AvgDRTG_x_y', 'std_AvgORTG_L5_x_y', 'std_AvgDRTG_L5_x_y',
            'HomeORTG_x_y', 'HomeDRTG_x_y', 'AwayORTG_x_y', 'AwayDRTG_x_y',
            'Location_Avg_ORTG_x_y'
        ]]
        dfb = dfb.append(df3)
        dfb = dfb.append(df4)

    dfb = dfb.dropna()

    # dfb = dfb[['TEAM_ABBREVIATION_x_x','HomeIndex_x_x','ProjectedPace','DaysRest_x','DaysRest_y','std_AvgORTG_x_x','HomeORTG_x_x','AwayORTG_x_x','std_AvgORTG_L5_x_x','AvgDRTG_x_y','HomeDRTG_x_y','AwayDRTG_x_y','std_AvgDRTG_x_y']]
    return dfb