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_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20pyrf%20demo%20(*market.py*)%0A%0A%20%20%20%20This%20notebook%20demonstrates%20the%20functionality%20of%20*pyrf%2Fmarket.py*%0A%0A%20%20%20%20The%20market%20module%20provides%3A%0A%0A%20%20%20%20-%20**QuotedLine**%3A%20Betting%20line%20representation%20with%20quarter-point%20precision%0A%20%20%20%20-%20**DecimalOdds**%3A%20Decimal%20odds%20with%20implied%20probability%20calculations%0A%20%20%20%20-%20**BetState**%3A%20Betting%20side%20representation%20(Goal%20Total%2C%20Home%2FAway)%0A%20%20%20%20-%20**QuoteLeg**%3A%20Complete%20betting%20quotes%20with%20market%2C%20line%2C%20side%2C%20and%20odds%0A%20%20%20%20-%20**Market**%3A%20Different%20types%20of%20betting%20markets%20(Goal%20Diff%2C%20Goal%20Total%2C%20Match%20Result)%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%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%20Betting%20Lines%0A%0A%20%20%20%20Betting%20lines%20are%20the%20foundation%20of%20sports%20betting%20markets.%20Let's%20explore%20different%20types%20of%20lines%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%20def%20_()%3A%0A%20%20%20%20%20%20%20%20%23%20Examples%20of%20different%20line%20types%0A%20%20%20%20%20%20%20%20lines%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Unit%20lines%22%3A%20%5B0.0%2C%201.0%2C%202.0%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Half%20lines%22%3A%20%5B0.5%2C%201.5%2C%202.5%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Quarter%20lines%22%3A%20%5B0.25%2C%200.75%2C%201.25%2C%202.25%5D%2C%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20for%20line_type%2C%20values%20in%20lines.items()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%5Cn%7Bline_type%7D%3A%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20value%20in%20values%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%20%3D%20rf.QuotedLine(value)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20characteristics%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20line.is_unit_line()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20characteristics.append(%22Unit%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20line.is_half_line()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20characteristics.append(%22Half%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20line.is_quarter_line()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20characteristics.append(%22Quarter%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20neighbours%20%3D%20line.neighbours()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%20%20%7Bvalue%7D%3A%20%7B'%20%26%20'.join(characteristics)%7D%20%7C%20Neighbours%3A%20%7Bneighbours%7D%22)%0A%0A%20%20%20%20_()%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%20Decimal%20Odds%20and%20Implied%20Probabilities%0A%0A%20%20%20%20Odds%20represent%20the%20probability%20of%20an%20outcome%20and%20the%20corresponding%20payout%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%20def%20_()%3A%0A%20%20%20%20%20%20%20%20%23%20Common%20betting%20odds%20and%20their%20implications%0A%20%20%20%20%20%20%20%20common_odds%20%3D%20%5B1.50%2C%201.80%2C%202.00%2C%202.50%2C%203.00%2C%204.00%2C%205.00%5D%0A%0A%20%20%20%20%20%20%20%20print(%22Odds%20Analysis%3A%22)%0A%20%20%20%20%20%20%20%20print(%22Decimal%20Odds%20%7C%20Implied%20Probability%20%7C%20Payout%20on%20%24100%22)%0A%20%20%20%20%20%20%20%20print(%22-%22%20*%2050)%0A%0A%20%20%20%20%20%20%20%20for%20odds_value%20in%20common_odds%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20odds%20%3D%20rf.DecimalOdds(odds_value)%0A%20%20%20%20%20%20%20%20%20%20%20%20probability%20%3D%20odds.implied_probability()%0A%20%20%20%20%20%20%20%20%20%20%20%20payout%20%3D%20odds_value%20*%20100%20%20%23%20Payout%20on%20%24100%20bet%0A%20%20%20%20%20%20%20%20%20%20%20%20profit%20%3D%20payout%20-%20100%20%20%23%20Profit%20(excluding%20stake)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%7Bodds_value%3A%5E12%7D%20%7C%20%7Bprobability%3A%5E18.2%25%7D%20%20%7C%20%24%7Bprofit%3A%3E6.0f%7D%20profit%22)%0A%0A%20%20%20%20_()%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%20Market%20Types%0A%0A%20%20%20%20The%20library%20supports%20different%20betting%20markets%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%20Available%20market%20types%0A%20%20%20%20markets%20%3D%20list(rf.Market)%0A%0A%20%20%20%20print(%22Available%20betting%20markets%3A%22)%0A%20%20%20%20for%20market%20in%20markets%3A%0A%20%20%20%20%20%20%20%20print(f%22-%20%7Bmarket.name%7D%3A%20%7Bmarket.value%7D%22)%0A%0A%20%20%20%20print(%22%5CnAvailable%20betting%20sides%3A%22)%0A%20%20%20%20sides%20%3D%20list(rf.BetState)%0A%20%20%20%20for%20side%20in%20sides%3A%0A%20%20%20%20%20%20%20%20print(f%22-%20%7Bside.name%7D%3A%20%7Bside.value%7D%22)%0A%0A%20%20%20%20print(%22%5CnSide-Market%20Compatibility%3A%22)%0A%20%20%20%20print(%22-%20Goal%20Diff%3A%20HOME%2C%20AWAY%22)%0A%20%20%20%20print(%22-%20Goal%20Total%3A%20OVER%2C%20UNDR%22)%0A%20%20%20%20print(%22-%20Match%20Result%3A%20HOME%2C%20AWAY%20(when%20supported)%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%20Creating%20Price%20Quotes%0A%0A%20%20%20%20Price%20quotes%20combine%20market%20type%2C%20betting%20lines%2C%20and%20odds%20into%20complete%20betting%20offers%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%20def%20_()%3A%0A%20%20%20%20%20%20%20%20%23%20Create%20some%20example%20price%20quotes%0A%20%20%20%20%20%20%20%20quotes%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.ASIAN_HCAP%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(-0.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.HOME%2C%20%20%23%20Home%20team%20giving%200.5%20goal%20handicap%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.95)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.ASIAN_HCAP%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(0.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.AWAY%2C%20%20%23%20Away%20team%20receiving%200.5%20goal%20handicap%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.85)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.TOTAL_GOAL%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(2.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.OVER%2C%20%20%23%20Over%202.5%20goals%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.90)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.TOTAL_GOAL%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(2.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.UNDR%2C%20%20%23%20Under%202.5%20goals%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.95)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%0A%20%20%20%20%20%20%20%20print(%22Sample%20Price%20Quotes%3A%22)%0A%20%20%20%20%20%20%20%20print(%22Market%20Type%20%20%20%20%20%7C%20Line%20%7C%20Side%20%20%7C%20Odds%20%7C%20Implied%20Prob%22)%0A%20%20%20%20%20%20%20%20print(%22-%22%20*%2055)%0A%0A%20%20%20%20%20%20%20%20for%20quote%20in%20quotes%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20market_name%20%3D%20quote.market.value%0A%20%20%20%20%20%20%20%20%20%20%20%20line_value%20%3D%20quote.line.value%0A%20%20%20%20%20%20%20%20%20%20%20%20side_name%20%3D%20quote.side.value%0A%20%20%20%20%20%20%20%20%20%20%20%20odds_value%20%3D%20quote.odds.value%0A%20%20%20%20%20%20%20%20%20%20%20%20probability%20%3D%20quote.odds.implied_probability()%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%7Bmarket_name%3A%3C15%7D%20%7C%20%7Bline_value%3A%3E4%7D%20%7C%20%7Bside_name%3A%3C5%7D%20%7C%20%7Bodds_value%3A%3E4%7D%20%7C%20%7Bprobability%3A%3E10.1%25%7D%22)%0A%0A%20%20%20%20%20%20%20%20%23%20Check%20that%20Goal%20Total%20odds%20are%20balanced%0A%20%20%20%20%20%20%20%20ou_quotes%20%3D%20%5Bq%20for%20q%20in%20quotes%20if%20q.market%20%3D%3D%20rf.Market.TOTAL_GOAL%5D%0A%20%20%20%20%20%20%20%20total_ou_prob%20%3D%20sum(q.odds.implied_probability()%20for%20q%20in%20ou_quotes)%0A%20%20%20%20%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22%5CnOver%2FUnder%20total%20probability%3A%20%7Btotal_ou_prob%3A.3f%7D%20(bookmaker%20margin%3A%20%7B(total_ou_prob%20-%201)%20*%20100%3A.1f%7D%25)%22%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20_()%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%20Quarter%20Line%20Analysis%0A%0A%20%20%20%20Quarter%20lines%20are%20unique%20in%20betting%20as%20they%20split%20stakes%20between%20two%20adjacent%20lines%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%20Analyze%20quarter%20line%20behavior%0A%20%20%20%20quarter_lines%20%3D%20%5B0.25%2C%200.75%2C%201.25%2C%202.25%5D%0A%0A%20%20%20%20print(%22Quarter%20Line%20Analysis%3A%22)%0A%20%20%20%20print(%22Line%20%7C%20Bounds%20%20%20%20%20%7C%20Description%22)%0A%20%20%20%20print(%22-%22%20*%2045)%0A%0A%20%20%20%20for%20line_value%20in%20quarter_lines%3A%0A%20%20%20%20%20%20%20%20line%20%3D%20rf.QuotedLine(line_value)%0A%20%20%20%20%20%20%20%20lower%2C%20upper%20%3D%20line.neighbours()%0A%0A%20%20%20%20%20%20%20%20if%20line_value%20%25%201%20%3D%3D%200.25%3A%20%20%23%20x.25%20lines%0A%20%20%20%20%20%20%20%20%20%20%20%20description%20%3D%20f%22Split%20between%20%7Blower%7D%20and%20%7Bupper%7D%22%0A%20%20%20%20%20%20%20%20else%3A%20%20%23%20x.75%20lines%0A%20%20%20%20%20%20%20%20%20%20%20%20description%20%3D%20f%22Split%20between%20%7Blower%7D%20and%20%7Bupper%7D%22%0A%0A%20%20%20%20%20%20%20%20print(f%22%7Bline_value%3A%3E4%7D%20%7C%20(%7Blower%7D%2C%20%7Bupper%7D)%20%7C%20%7Bdescription%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%20Betting%20Scenario%0A%0A%20%20%20%20Let's%20create%20a%20realistic%20betting%20scenario%20with%20multiple%20markets%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%20Football%20match%3A%20Manchester%20United%20vs%20Liverpool%0A%20%20%20%20%23%20Create%20realistic%20price%20quotes%20with%20proper%20sides%0A%0A%20%20%20%20print(%22Manchester%20United%20vs%20Liverpool%20-%20Betting%20Odds%22)%0A%20%20%20%20print(%22%3D%22%20*%2050)%0A%0A%20%20%20%20%23%20Goal%20Diff%20quotes%0A%20%20%20%20ah_quotes%20%3D%20%5B%0A%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.ASIAN_HCAP%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.HOME%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(-0.25)%2C%20%20%23%20Man%20United%20giving%20quarter%20goal%0A%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.95)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.ASIAN_HCAP%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.AWAY%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(0.25)%2C%20%20%23%20Liverpool%20receiving%20quarter%20goal%0A%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.85)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%5D%0A%0A%20%20%20%20%23%20Goal%20Total%20quotes%0A%20%20%20%20ou_quotes_betting%20%3D%20%5B%0A%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.TOTAL_GOAL%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.OVER%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(2.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.88)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20%20%20%20%20market%3Drf.Market.TOTAL_GOAL%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20side%3Drf.BetState.UNDR%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(2.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.92)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%5D%0A%0A%20%20%20%20%23%20Display%20Goal%20Diff%0A%20%20%20%20print(%22%5CnAsian%20Handicap%3A%22)%0A%20%20%20%20teams%20%3D%20%5B%22Manchester%20United%22%2C%20%22Liverpool%22%5D%0A%20%20%20%20for%20i%2C%20quote%20in%20enumerate(ah_quotes)%3A%0A%20%20%20%20%20%20%20%20prob%20%3D%20quote.odds.implied_probability()%0A%20%20%20%20%20%20%20%20line_type%20%3D%20%22Quarter%22%20if%20quote.line.is_quarter_line()%20else%20%22Other%22%0A%20%20%20%20%20%20%20%20line_str%20%3D%20f%22%7Bquote.line.value%3A%2B5.2f%7D%22%0A%0A%20%20%20%20%20%20%20%20print(f%22%20%20%7Bteams%5Bi%5D%3A%3C17%7D%20%7Bline_str%7D%20(%7Bquote.side.value%7D)%20%40%20%7Bquote.odds.value%3A%3C4%7D%20(%7Bprob%3A.1%25%7D)%20%5B%7Bline_type%7D%5D%22)%0A%0A%20%20%20%20%23%20Display%20Goal%20Total%0A%20%20%20%20print(%22%5CnOver%2FUnder%202.5%20Goals%3A%22)%0A%20%20%20%20for%20quote%20in%20ou_quotes_betting%3A%0A%20%20%20%20%20%20%20%20prob%20%3D%20quote.odds.implied_probability()%0A%20%20%20%20%20%20%20%20print(f%22%20%20%7Bquote.side.value%3A%3C5%7D%20%7Bquote.line.value%3A%3C6%7D%20%40%20%7Bquote.odds.value%3A%3C4%7D%20(%7Bprob%3A.1%25%7D)%22)%0A%0A%20%20%20%20%23%20Calculate%20bookmaker%20margins%0A%20%20%20%20ah_prob_sum%20%3D%20sum(q.odds.implied_probability()%20for%20q%20in%20ah_quotes)%0A%20%20%20%20ou_prob_sum%20%3D%20sum(q.odds.implied_probability()%20for%20q%20in%20ou_quotes_betting)%0A%0A%20%20%20%20print(%22%5CnBookmaker%20Margins%3A%22)%0A%20%20%20%20print(f%22%20%20Goal%20Diff%3A%20%7B(ah_prob_sum%20-%201)%20*%20100%3A.2f%7D%25%22)%0A%20%20%20%20print(f%22%20%20%20%20%20%20Goal%20Total%3A%20%7B(ou_prob_sum%20-%201)%20*%20100%3A.2f%7D%25%22)%0A%0A%20%20%20%20print(%22%5CnValidation%3A%22)%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20f%22%20%20All%20quotes%20valid%3A%20%7Ball(True%20for%20_%20in%20ah_quotes%20%2B%20ou_quotes_betting)%7D%22%0A%20%20%20%20)%20%20%23%20Just%20show%20they%20were%20created%20successfully%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%20Integration%20with%20Payoff%20Calculations%0A%0A%20%20%20%20Let's%20connect%20the%20market%20quotes%20with%20actual%20payoff%20calculations%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%20small%20goal%20grid%20for%20demonstration%0A%20%20%20%20grid_demo%20%3D%20rf.GoalGrid(n%3D3)%0A%0A%20%20%20%20%23%20Example%3A%20Goal%20Diff%20%2B0.25%20(Liverpool%20away%20team%20receiving%20handicap)%0A%20%20%20%20quote_demo%20%3D%20rf.QuoteLeg(%0A%20%20%20%20%20%20%20%20market%3Drf.Market.ASIAN_HCAP%2C%0A%20%20%20%20%20%20%20%20side%3Drf.BetState.AWAY%2C%20%20%23%20Away%20team%20receiving%20handicap%0A%20%20%20%20%20%20%20%20line%3Drf.QuotedLine(0.25)%2C%0A%20%20%20%20%20%20%20%20odds%3Drf.DecimalOdds(1.85)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Calculate%20payoff%20surface%0A%20%20%20%20handicap_demo%20%3D%20rf.AsianHandicap(line%3Dquote_demo.line.value)%0A%20%20%20%20payoff_surface_demo%20%3D%20handicap_demo.grid_payoff(grid_demo)%0A%0A%20%20%20%20print(f%22Goal%20Diff%20%2B%7Bquote_demo.line.value%7D%20(%7Bquote_demo.side.value%7D)%20Payoff%20Surface%3A%22)%0A%20%20%20%20print(f%22Odds%3A%20%7Bquote_demo.odds.value%7D%20(Implied%20Probability%3A%20%7Bquote_demo.odds.implied_probability()%3A.1%25%7D)%22)%0A%20%20%20%20print(%22%5CnPayoff%20Matrix%20(rows%3Daway%20goals%2C%20cols%3Dhome%20goals)%3A%22)%0A%20%20%20%20print(payoff_surface_demo)%0A%0A%20%20%20%20%23%20Calculate%20expected%20payout%20for%20specific%20result%0A%20%20%20%20result_home%2C%20result_away%20%3D%201%2C%201%20%20%23%201-1%20draw%0A%20%20%20%20payoff_value%20%3D%20payoff_surface_demo.loc%5Bstr(result_away)%2C%20str(result_home)%5D%0A%20%20%20%20stake%20%3D%20100%0A%20%20%20%20net_result%20%3D%20payoff_value%20*%20stake%20*%20(quote_demo.odds.value%20-%201)%20if%20payoff_value%20%3E%200%20else%20payoff_value%20*%20stake%0A%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20f%22%5CnExample%3A%20%24100%20bet%20on%20%7Bquote_demo.side.value%7D%20%2B%7Bquote_demo.line.value%7D%20%22%0A%20%20%20%20%20%20%20%20f%22with%20result%20%7Bresult_home%7D-%7Bresult_away%7D%3A%22%0A%20%20%20%20)%0A%20%20%20%20print(f%22Payoff%20coefficient%3A%20%7Bpayoff_value%7D%22)%0A%20%20%20%20print(f%22Net%20result%3A%20%24%7Bnet_result%3A%2B.2f%7D%22)%0A%0A%20%20%20%20%23%20Show%20the%20quarter%20line%20behavior%0A%20%20%20%20if%20quote_demo.line.is_quarter_line()%3A%0A%20%20%20%20%20%20%20%20neighbours%20%3D%20quote_demo.line.neighbours()%0A%20%20%20%20%20%20%20%20print(f%22%5CnQuarter%20line%20splits%20stake%20between%20%7Bneighbours%5B0%5D%7D%20and%20%7Bneighbours%5B1%5D%7D%20handicaps%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%20Summary%0A%0A%20%20%20%20This%20notebook%20demonstrated%20the%20market%20functionality%20of%20ringfinity%3A%0A%0A%20%20%20%20-%20**QuotedLine**%3A%20Handles%20different%20line%20types%20with%20quarter-point%20precision%0A%20%20%20%20-%20**DecimalOdds**%3A%20Converts%20odds%20to%20implied%20probabilities%0A%20%20%20%20-%20**BetState**%3A%20Represents%20betting%20sides%20(Goal%20Total%2C%20Home%2FAway)%20with%20market%20validation%0A%20%20%20%20-%20**QuoteLeg**%3A%20Combines%20market%2C%20line%2C%20side%2C%20and%20odds%20into%20complete%20immutable%20quotes%0A%20%20%20%20-%20**Market%20Integration**%3A%20Shows%20how%20quotes%20connect%20to%20payoff%20calculations%0A%0A%20%20%20%20Key%20features%20demonstrated%3A%0A%0A%20%20%20%20-%20*Side%20validation*%20ensures%20correct%20side-market%20combinations%0A%20%20%20%20-%20*Immutable%20Price%20Quote%20objects*%20prevent%20accidental%20modifications%0A%20%20%20%20-%20*Quarter%20line%20behavior*%20and%20*split%20stake%20calculations*%0A%20%20%20%20-%20*Bookmaker%20margin%20analysis*%20across%20different%20markets%0A%0A%20%20%20%20The%20market%20module%20provides%20the%20foundation%20for%20building%20complete%20betting%20analysis%0A%20%20%20%20and%20trading%20systems%20on%20top%20of%20the%20core%20payoff%20calculations.%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%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
712658e8ba4e415a076c5fd287c5054f