function ans = odds(vector)
%ODDS(ODDS1,ODDS2,ODDS3...) calculates the most efficient bets to make
%depending on the input odds to minimize loss.
%
%The function takes in n money line odds. For example a soccer match,
%+100 for an underdog win, -125 for the favored team to win, and +220
%for a draw. The function calculates the percentage of your bet that
%should go to each outcome in order to minimize your loss no matter
%what event actually occurs.
%
%I'm mainly curious if I coded it correctly, so I would really like
%some input. I am convinced that for n=2 it works, but I'm not sure
%about highr n's.
N = length(vector);
for ii = 1:N
if vector(ii)<0
vector(ii) = -100/vector(ii);
elseif vector(ii)>0
vector(ii) = vector(ii)/100;
end
end
clear ii;
%% Minimization intercepts
minInt = eye(N+1);
minInt(N+1,N+1) = vector(1);
minInt(N+1,1) = 1;
x{1} = ones(N+1);
x{1}(:,2:end) = minInt(:,2:end);
P(1) = det(x{1});
for ii = 2:N+1
x{ii} = ones(N+1);
x{ii}(:,1:(ii-1)) = minInt(:,1:(ii-1));
x{ii}(:,(ii+1):end) = minInt(:,(ii+1):end);
P(ii) = det(x{ii});
end
x{N+2} = minInt;
P(N+2) = det(x{N+2});
clear ii; clear x
%% Odds intercepts
for jj = 1:N
y = -ones(N+1,1);
y(end,1) = 0;
y(jj,1) = vector(jj);
x{jj} = [eye(N);zeros(1,N)];
x{jj} = [x{jj} y];
end
clear jj;
clear y;
for jj = 1:N
y{jj,1} = ones(N+1);
y{jj,1}(:,2:end) = x{jj}(:,2:end);
A(jj,1) = det(y{jj,1});
for ii = 2:N+1
y{jj,ii} = ones(N+1);
y{jj,ii}(:,1:(ii-1)) = x{jj}(:,1:(ii-1));
y{jj,ii}(:,(ii+1):end) = x{jj}(:,(ii+1):end);
A(jj,ii) = det(y{jj,ii});
end
y{jj,N+2} = x{jj};
A(jj,N+2) = det(y{jj,N+2});
end
ans = rref([A;P])