%% oddsmath.sty
%% Copyright 2026 Edward Glush, Bet Better Pty Ltd
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
%
% This work has the LPPL maintenance status `maintained'.
% The Current Maintainer of this work is Edward Glush.
%
% Macros for converting betting-odds formats and computing
% implied probabilities, fair probabilities and bookmaker overround,
% for teaching materials and papers on wagering markets.
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\ProvidesPackage{oddsmath}[2026/10/01 v1.0 odds conversion and implied-probability macros]
\RequirePackage{xfp}

% \DecToProb{2.50} -> implied probability of decimal odds (0.4000)
\newcommand*{\DecToProb}[1]{\fpeval{round(1/(#1),4)}}

% \DecToPct{2.50} -> implied probability as percent (40.00)
\newcommand*{\DecToPct}[1]{\fpeval{round(100/(#1),2)}}

% \ProbToDec{0.40} -> fair decimal odds for a probability (2.5)
\newcommand*{\ProbToDec}[1]{\fpeval{round(1/(#1),4)}}

% \DecToAmerican{2.50} -> American (moneyline) odds (+150 / -167 style, number only)
\newcommand*{\DecToAmerican}[1]{\fpeval{(#1) >= 2 ? round(((#1)-1)*100,0) : round(-100/((#1)-1),0)}}

% \AmericanToDec{-150} -> decimal odds (1.6667)
\newcommand*{\AmericanToDec}[1]{\fpeval{(#1) > 0 ? round(1+(#1)/100,4) : round(1+100/(-(#1)),4)}}

% \FracToDec{5}{2} -> decimal odds from fractional (3.5)
\newcommand*{\FracToDec}[2]{\fpeval{round(1+(#1)/(#2),4)}}

% \Overround{1.91}{1.91} -> two-way book overround as percent (4.71)
\newcommand*{\Overround}[2]{\fpeval{round((1/(#1)+1/(#2)-1)*100,2)}}

% \OverroundIII{a}{b}{c} -> three-way book overround as percent
\newcommand*{\OverroundIII}[3]{\fpeval{round((1/(#1)+1/(#2)+1/(#3)-1)*100,2)}}

% \FairProb{1.91}{1.91} -> de-margined (fair) probability of the FIRST price
\newcommand*{\FairProb}[2]{\fpeval{round((1/(#1))/(1/(#1)+1/(#2)),4)}}

% \FairProbIII{a}{b}{c} -> fair probability of the first price in a 3-way market
\newcommand*{\FairProbIII}[3]{\fpeval{round((1/(#1))/(1/(#1)+1/(#2)+1/(#3)),4)}}

% \ExpectedValue{dec odds}{true prob} -> EV of a 1-unit stake
\newcommand*{\ExpectedValue}[2]{\fpeval{round((#1)*(#2)-1,4)}}

% \KellyFraction{dec odds}{true prob} -> Kelly stake fraction
\newcommand*{\KellyFraction}[2]{\fpeval{round(((#1)*(#2)-1)/((#1)-1),4)}}

\endinput
