Skip to content

Commit

Permalink
Revised initial estimates for power and odds-ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Koutanov committed Jan 22, 2024
1 parent bfc48b5 commit ff294f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Overround.Tests/OddsRatioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public void TestApplyWithFairBooksumOf1()
double[] fairPrices = [1 / 0.1, 1 / 0.2, 1 / 0.3, 1 / 0.4];
double[] odds = method.Apply(fairPrices, idealOverround);
Assert.AreEqual(idealOverround, Booksum.FromPrices(odds), Delta);
ArrayAssert.AreEqual([8.328244274809158, 4.256997455470738, 2.8999151823579306, 2.2213740458015265], odds, Delta);
ArrayAssert.AreEqual([8.328, 4.257, 2.9, 2.221], odds, Delta);
}
{
double idealOverround = 1.15;
double[] fairPrices = [1 / 0.01, 1 / 0.29, 1 / 0.3, 1 / 0.4];
double[] odds = method.Apply(fairPrices, idealOverround);
Assert.AreEqual(idealOverround, Booksum.FromPrices(odds), Delta);
ArrayAssert.AreEqual([80.59798994974874, 2.968463004678565, 2.876046901172529, 2.2060301507537687], odds, Delta);
ArrayAssert.AreEqual([80.644, 2.97, 2.877, 2.206], odds, Delta);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Overround.Tests/PowerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public void TestApplyWithFairBooksumOf1()
double[] fairPrices = [1 / 0.1, 1 / 0.2, 1 / 0.3, 1 / 0.4];
double[] odds = method.Apply(fairPrices, idealOverround);
Assert.AreEqual(idealOverround, Booksum.FromPrices(odds), Delta);
ArrayAssert.AreEqual([7.792612295808612, 4.200100853723753, 2.9257830833421794, 2.2637912052854765], odds, Delta);
ArrayAssert.AreEqual([7.793, 4.2, 2.926, 2.264], odds, Delta);
}
{
double idealOverround = 1.15;
double[] fairPrices = [1 / 0.01, 1 / 0.29, 1 / 0.3, 1 / 0.4];
double[] odds = method.Apply(fairPrices, idealOverround);
Assert.AreEqual(idealOverround, Booksum.FromPrices(odds), Delta);
ArrayAssert.AreEqual([56.99885594904725, 2.9646851350987014, 2.877746548950255, 2.235448624371958], odds, Delta);
ArrayAssert.AreEqual([56.999, 2.965, 2.878, 2.235], odds, Delta);
}
}

Expand Down
13 changes: 9 additions & 4 deletions Overround/OddsRatio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ namespace Overround;

public class OddsRatio : IOverroundMethod
{
private const double InitStep = 0.1;
private const double InitStep = 0.01;
private const double ErrorThreshold = 1e-6;
private const int MaxIterations = 100;

private static double GetInitEstimate(double fairBooksum, double idealBooksum, int numOutcomes)
{
return (numOutcomes / fairBooksum - 1) / (numOutcomes / idealBooksum - 1);
}

private static double[] ComputeOdds(double[] fairPrices, double g)
{
double[] odds = new double[fairPrices.Length];
Expand All @@ -19,13 +24,13 @@ private static double[] ComputeOdds(double[] fairPrices, double g)
public double[] Apply(double[] fairPrices, double idealOverround)
{
double fairBooksum = Booksum.FromPrices(fairPrices);
double targetBooksum = idealOverround * fairBooksum;
double initEstimate = idealOverround;
double idealBooksum = idealOverround * fairBooksum;
double initEstimate = GetInitEstimate(fairBooksum, idealBooksum, fairPrices.Length);
Solution solution = Solver.Solve(initEstimate, InitStep, ErrorThreshold, MaxIterations, estimate =>
{
double[] odds = ComputeOdds(fairPrices, estimate);
double booksum = Booksum.FromPrices(odds);
return Math.Pow(booksum - targetBooksum, 2);
return Math.Pow(booksum - idealBooksum, 2);
});
return ComputeOdds(fairPrices, solution.Value);
}
Expand Down
10 changes: 5 additions & 5 deletions Overround/Power.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class Power : IOverroundMethod
private const double ErrorThreshold = 1e-6;
private const int MaxIterations = 100;

private static double GetInitEstimate(double overround, int numOutcomes)
private static double GetInitEstimate(double fairBooksum, double idealBooksum, int numOutcomes)
{
return 1 + Math.Log(1 / overround) / Math.Log(numOutcomes);
return Math.Log(idealBooksum / numOutcomes) / Math.Log(fairBooksum / numOutcomes);
}

private static double[] ComputeOdds(double[] fairPrices, double k)
Expand All @@ -24,13 +24,13 @@ private static double[] ComputeOdds(double[] fairPrices, double k)
public double[] Apply(double[] fairPrices, double idealOverround)
{
double fairBooksum = Booksum.FromPrices(fairPrices);
double targetBooksum = idealOverround * fairBooksum;
double initEstimate = GetInitEstimate(idealOverround, fairPrices.Length);
double idealBooksum = idealOverround * fairBooksum;
double initEstimate = GetInitEstimate(fairBooksum, idealBooksum, fairPrices.Length);
Solution solution = Solver.Solve(initEstimate, InitStep, ErrorThreshold, MaxIterations, estimate =>
{
double[] odds = ComputeOdds(fairPrices, estimate);
double booksum = Booksum.FromPrices(odds);
return Math.Pow(booksum - targetBooksum, 2);
return Math.Pow(booksum - idealBooksum, 2);
});
return ComputeOdds(fairPrices, solution.Value);
}
Expand Down

0 comments on commit ff294f9

Please sign in to comment.