import%20marimo%0A%0A__generated_with%20%3D%20%220.18.4%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20pd.set_option(%22display.max_rows%22%2C%20None)%0A%20%20%20%20pd.set_option(%22display.max_columns%22%2C%20None)%0A%20%20%20%20pd.set_option(%22display.width%22%2C%20None)%0A%20%20%20%20pd.set_option(%22display.max_colwidth%22%2C%20None)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20pyrf%20demo%20(*payoffs.py*)%0A%0A%20%20%20%20This%20notebook%20demonstrates%20the%20functionality%20of%20*pyrf%2Fpayoffs.py*%0A%0A%20%20%20%20The%20payoffs%20module%20provides%3A%0A%0A%20%20%20%20-%20**GoalGrid**%3A%20Generate%20matrices%20of%20goal%20scores%20for%20football%20matches%20with%20proper%20home%2Faway%20labeling%0A%20%20%20%20-%20**AsianHandicap**%3A%20Calculate%20Asian%20handicap%20betting%20payoffs%20with%20quarter%20line%20support%0A%20%20%20%20-%20**TotalGoals**%3A%20Calculate%20over%2Funder%20betting%20payoffs%20based%20on%20total%20goals%0A%20%20%20%20-%20**PayoffSurface**%3A%20Abstract%20base%20class%20for%20inheritance-based%20payoff%20calculations%0A%0A%20%20%20%20For%20betting%20lines%2C%20odds%2C%20and%20market%20functionality%2C%20see%20the%20companion%20notebook%3A%20%60demo_market_marimo.py%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Import%20Required%20Libraries%0A%0A%20%20%20%20Let's%20start%20by%20importing%20the%20library%20and%20setting%20up%20our%20environment%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20pyrf%20as%20rf%0A%20%20%20%20return%20(rf%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Understanding%20Goal%20Grids%0A%0A%20%20%20%20Goal%20grids%20are%20the%20foundation%20of%20payoff%20calculations.%20Let's%20explore%20how%20they%20work%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(rf)%3A%0A%20%20%20%20grid%20%3D%20rf.GoalGrid()%0A%20%20%20%20return%20(grid%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid)%3A%0A%20%20%20%20%23%20View%20the%20home%20and%20away%20goal%20matrices%0A%20%20%20%20print(%22Home%20goals%20matrix%3A%5Cn%22)%0A%20%20%20%20print(grid.home)%0A%20%20%20%20print(%22%5CnAway%20goals%20matrix%3A%22)%0A%20%20%20%20print(grid.away)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid)%3A%0A%20%20%20%20%23%20Calculate%20goal%20differences%20and%20totals%0A%20%20%20%20goal_diff%20%3D%20grid.home%20-%20grid.away%20%20%23%20Home%20advantage%0A%20%20%20%20goal_total%20%3D%20grid.home%20%2B%20grid.away%20%20%23%20Total%20goals%0A%20%20%20%20print(%22Goal%20difference%20(home%20-%20away)%3A%22)%0A%20%20%20%20print(goal_diff)%0A%20%20%20%20print(%22%5CnTotal%20goals%20(home%20%2B%20away)%3A%22)%0A%20%20%20%20print(goal_total)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Goal%20Diff%20Betting%0A%0A%20%20%20%20Asian%20handicap%20betting%20adjusts%20the%20score%20by%20a%20handicap%20line%20before%20determining%20the%20winner%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid%2C%20rf)%3A%0A%20%20%20%20%23%20Asian%20handicap%20with%20-0.75%20line%20(quarter%20line)%0A%20%20%20%20handicap%20%3D%20rf.AsianHandicap(line%3D-0.75)%0A%20%20%20%20payoff_matrix%20%3D%20handicap.grid_payoff(grid%3Dgrid)%0A%20%20%20%20print(f%22Asian%20handicap%20line%3A%20%7Bhandicap.line.value%7D%22)%0A%20%20%20%20print(f%22Line%20type%3A%20%7B'Quarter'%20if%20handicap.line.is_quarter_line()%20else%20'Other'%7D%22)%0A%20%20%20%20print(%22Payoff%20matrix%3A%22)%0A%20%20%20%20print(payoff_matrix)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Goal%20Total%20Betting%0A%0A%20%20%20%20Over%2Funder%20betting%20is%20based%20on%20whether%20the%20total%20goals%20exceed%20a%20certain%20threshold%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid%2C%20rf)%3A%0A%20%20%20%20%23%20Over%2Funder%20with%202.5%20line%20(half%20line)%0A%20%20%20%20over_under%20%3D%20rf.TotalGoals(line%3D2.5)%0A%20%20%20%20payoff_matrix_ou%20%3D%20over_under.grid_payoff(grid)%0A%20%20%20%20print(f%22Over%2Funder%20line%3A%20%7Bover_under.line.value%7D%22)%0A%20%20%20%20print(f%22Line%20type%3A%20%7B'Half'%20if%20over_under.line.is_half_line()%20else%20'Other'%7D%22)%0A%20%20%20%20print(%22%5CnPayoff%20matrix%3A%22)%0A%20%20%20%20print(payoff_matrix_ou)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Inheritance-Based%20Architecture%0A%0A%20%20%20%20The%20library%20uses%20a%20clean%20inheritance%20structure%20for%20different%20bet%20types%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid%2C%20rf)%3A%0A%20%20%20%20%23%20Demonstrate%20polymorphic%20usage%0A%20%20%20%20payoff_surfaces%20%3D%20%5B%0A%20%20%20%20%20%20%20%20rf.AsianHandicap(line%3D1.5)%2C%0A%20%20%20%20%20%20%20%20rf.TotalGoals(line%3D2.5)%2C%0A%20%20%20%20%20%20%20%20rf.AsianHandicap(line%3D-0.25)%2C%0A%20%20%20%20%20%20%20%20rf.TotalGoals(line%3D3.25)%2C%0A%20%20%20%20%5D%0A%0A%20%20%20%20print(%22Polymorphic%20Payoff%20Surface%20Usage%3A%22)%0A%20%20%20%20print(%22Type%20%20%20%20%20%20%20%20%20%20%20%20%7C%20Line%20%20%7C%20Line%20Type%20%7C%20Shape%22)%0A%20%20%20%20print(%22-%22%20*%2050)%0A%0A%20%20%20%20for%20surface%20in%20payoff_surfaces%3A%0A%20%20%20%20%20%20%20%20%23%20All%20are%20PayoffSurface%20instances%0A%20%20%20%20%20%20%20%20assert%20isinstance(surface%2C%20rf.PayoffSurface)%0A%0A%20%20%20%20%20%20%20%20%23%20Get%20payoff%20matrix%0A%20%20%20%20%20%20%20%20result%20%3D%20surface.grid_payoff(grid)%0A%20%20%20%20%20%20%20%20line_type%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20if%20surface.line.is_unit_line()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20line_type.append(%22Unit%22)%0A%20%20%20%20%20%20%20%20if%20surface.line.is_half_line()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20line_type.append(%22Half%22)%0A%20%20%20%20%20%20%20%20if%20surface.line.is_quarter_line()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20line_type.append(%22Quarter%22)%0A%0A%20%20%20%20%20%20%20%20type_name%20%3D%20type(surface).__name__%0A%20%20%20%20%20%20%20%20line_value%20%3D%20surface.line.value%0A%20%20%20%20%20%20%20%20line_desc%20%3D%20%22%20%26%20%22.join(line_type)%0A%20%20%20%20%20%20%20%20shape%20%3D%20f%22%7Bresult.shape%5B0%5D%7Dx%7Bresult.shape%5B1%5D%7D%22%0A%0A%20%20%20%20%20%20%20%20%23%20Format%20line%20value%20with%20decimal%20point%20alignment%0A%20%20%20%20%20%20%20%20print(f%22%7Btype_name%3A%3C15%7D%20%7C%20%7Bline_value%3A%3E5.2f%7D%20%7C%20%7Bline_desc%3A%3C9%7D%20%7C%20%7Bshape%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Practical%20Payoff%20Analysis%0A%0A%20%20%20%20Let's%20analyze%20payoffs%20for%20a%20realistic%20football%20match%20scenario%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(rf)%3A%0A%20%20%20%20%23%20Manchester%20United%20vs%20Liverpool%20-%20Payoff%20Analysis%0A%20%20%20%20grid_match%20%3D%20rf.GoalGrid(n%3D4)%20%20%23%200-4%20goals%20for%20faster%20display%0A%0A%20%20%20%20%23%20Set%20up%20different%20betting%20scenarios%0A%20%20%20%20scenarios%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22Man%20United%20-0.25%22%3A%20rf.AsianHandicap(line%3D-0.25)%2C%0A%20%20%20%20%20%20%20%20%22Liverpool%20%2B0.25%22%3A%20rf.AsianHandicap(line%3D0.25)%2C%0A%20%20%20%20%20%20%20%20%22Over%202.5%20Goals%22%3A%20rf.TotalGoals(line%3D2.5)%2C%0A%20%20%20%20%20%20%20%20%22Under%202.5%20Goals%22%3A%20rf.TotalGoals(line%3D2.5)%2C%20%20%23%20Same%20line%2C%20opposite%20interpretation%0A%20%20%20%20%7D%0A%0A%20%20%20%20print(%22Manchester%20United%20vs%20Liverpool%20-%20Payoff%20Analysis%22)%0A%20%20%20%20print(%22%3D%22%20*%2055)%0A%0A%20%20%20%20for%20scenario_name%2C%20payoff_surface%20in%20scenarios.items()%3A%0A%20%20%20%20%20%20%20%20payoff_matrix_scenario%20%3D%20payoff_surface.grid_payoff(grid_match)%0A%0A%20%20%20%20%20%20%20%20print(f%22%5Cn%7Bscenario_name%7D%3A%5Cn%22)%0A%20%20%20%20%20%20%20%20print(f%22Line%3A%20%7Bpayoff_surface.line.value%7D%22)%0A%20%20%20%20%20%20%20%20print(%22%5CnPayoff%20Matrix%3A%5Cn%22)%0A%20%20%20%20%20%20%20%20print(payoff_matrix_scenario)%0A%0A%20%20%20%20%20%20%20%20%23%20Show%20some%20key%20results%0A%20%20%20%20%20%20%20%20print(%22%5CnKey%20Results%3A%22)%0A%20%20%20%20%20%20%20%20results%20%3D%20%5B(0%2C%200)%2C%20(1%2C%201)%2C%20(2%2C%201)%2C%20(1%2C%202)%5D%0A%20%20%20%20%20%20%20%20for%20away%2C%20home%20in%20results%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20payoff%20%3D%20payoff_matrix_scenario.loc%5Bstr(away)%2C%20str(home)%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20result_desc%20%3D%20%22Draw%22%20if%20home%20%3D%3D%20away%20else%20(%22Home%20win%22%20if%20home%20%3E%20away%20else%20%22Away%20win%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%20%20%7Bhome%7D-%7Baway%7D%20(%7Bresult_desc%3A%3C8%7D)%3A%20%7Bpayoff%3A%2B5.2f%7D%22)%0A%0A%20%20%20%20%20%20%20%20if%20scenario_name%20%3D%3D%20%22Under%202.5%20Goals%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20For%20Under%2C%20flip%20the%20payoff%20values%20since%20it's%20the%20opposite%20of%20Over%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22%20%20Note%3A%20For%20'Under'%20bets%2C%20payoffs%20are%20opposite%20of%20'Over'%20calculations%22)%0A%0A%20%20%20%20%20%20%20%20print(%22-%22%20*%2040)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid%2C%20rf)%3A%0A%20%20%20%20%23%20Quarter%20line%20example%20-%20Asian%20handicap%20%2B0.25%0A%20%20%20%20quarter_handicap%20%3D%20rf.AsianHandicap(line%3D0.25)%0A%20%20%20%20quarter_payoff%20%3D%20quarter_handicap.grid_payoff(grid)%0A%0A%20%20%20%20%23%20Show%20some%20specific%20results%0A%20%20%20%20print(%22Quarter%20line%20(%2B0.25)%20payoff%20examples%3A%22)%0A%20%20%20%20print(f%220-0%20draw%3A%20%7Bquarter_payoff.loc%5B'0'%2C%20'0'%5D%3A.2f%7D%22)%20%20%23%20Half%20win%20for%20away%20team%0A%20%20%20%20print(f%221-1%20draw%3A%20%7Bquarter_payoff.loc%5B'1'%2C%20'1'%5D%3A.2f%7D%22)%20%20%23%20Half%20win%20for%20away%20team%0A%20%20%20%20print(f%221-0%20home%20win%3A%20%7Bquarter_payoff.loc%5B'0'%2C%20'1'%5D%3A.2f%7D%22)%20%20%23%20Full%20win%20for%20home%20team%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Custom%20Grid%20Sizes%0A%0A%20%20%20%20You%20can%20create%20grids%20of%20different%20sizes%20for%20different%20analysis%20needs%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(rf)%3A%0A%20%20%20%20%23%20Create%20a%20smaller%205x5%20grid%20for%20quick%20analysis%0A%20%20%20%20small_grid%20%3D%20rf.GoalGrid(n%3D5)%0A%20%20%20%20small_handicap%20%3D%20rf.AsianHandicap(line%3D1.5)%0A%0A%20%20%20%20print(%225x5%20grid%20Asian%20handicap%20(%2B1.5)%3A%22)%0A%20%20%20%20print(small_handicap.grid_payoff(grid%3Dsmall_grid))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20The%20ringfinity%20library%20provides%20a%20clean%2C%20inheritance-based%20API%20for%20calculating%20sports%20betting%20payoffs%3A%0A%0A%20%20%20%20-%20**%60GoalGrid%60**%3A%20Creates%20matrices%20of%20goal%20combinations%20with%20proper%20home%2Faway%20labeling%0A%20%20%20%20-%20**%60AsianHandicap%60**%3A%20Handles%20handicap%20betting%20with%20support%20for%20quarter%20lines%20and%20partial%20wins%0A%20%20%20%20-%20**%60TotalGoals%60**%3A%20Calculates%20over%2Funder%20betting%20payoffs%20based%20on%20total%20goals%0A%0A%20%20%20%20All%20payoff%20calculations%20return%20pandas%20DataFrames%20with%20proper%20index%20and%20column%20naming%0A%20%20%20%20for%20easy%20analysis%20and%20integration%20with%20other%20data%20science%20tools.%0A%0A%20%20%20%20For%20more%20details%20on%20betting%20lines%2C%20odds%2C%20and%20market%20functionality%2C%20see%20the%20%60demo_market_marimo.py%60%20notebook.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
2c769b4f9fb18a02114a21f878b0db6b