# Prize Payout Calculator Help

#### btaylor

##### New member
Hi all,
I am a programmer and in one of my projects I need a cash payout calculator based on upper and lower minimums and variable input.

Here are the variables:
Total amount to payout
Total number of payouts
Set minimum first place payout
Set minimum last payout
"K" to vary the slope of the curve

Example
Total amount to payout is 10000.
Payout is for 15 places.
1st places is guaranteed 4000.
Last payout (15) is 100.

I had someone help "many" years ago, but the total amount paid out was more than the size of the payout pool. Here is the code:

( ^ ) operator is for exponent
K = inK (inK is the K value to modify the slope)
N = pay_places (N=number of places to pay out)
AA = last_pay (AA=base prize minimum)
Z = max_pay (Z=top prize minimum)
D = pool (D=total payout)
Sum = 0
F = Z / AA
BB = F ^ (1 / ((N - 1) ^ K))

loop I = 0 TO N - 1
Sum = Sum + AA * BB ^ (I ^ K)​
end

NewSum = 0

loop I = N - 1 TO 0 by -1
NewSum = NewSum + AA * BB ^ (I ^ K) * D / Sum​
recommend = AA * BB ^ (I ^ K) (This adds up high)
pay_out = round((AA * BB ^ (I ^ K)),1) (but correctly sets hi and lo bounds)
.
. (more code to write out data)
.
end

Thanks in advance for any assistance
Bob

Last edited:

#### Klaas van Aarsen

##### MHB Seeker
Staff member
Hi all,
I am a programmer and in one of my projects I need a cash payout calculator based on upper and lower minimums and variable input.

Here are the variables:
Total amount to payout
Total number of payouts
Set minimum first place payout
Set minimum last payout
"K" to vary the slope of the curve

Example
Total amount to payout is 10000.
Payout is for 15 places.
1st places is guaranteed 4000.
Last payout (15) is 100.

I had someone help "many" years ago, but the total amount paid out was more than the size of the payout pool. Here is the code:

( ^ ) operator is for exponent
K = inK (inK is the K value to modify the slope)
N = pay_places (N=number of places to pay out)
AA = last_pay (AA=base prize minimum)
Z = max_pay (Z=top prize minimum)
D = pool (D=total payout)
Sum = 0
F = Z / AA
BB = F ^ (1 / ((N - 1) ^ K))

loop I = 0 TO N - 1
Sum = Sum + AA * BB ^ (I ^ K)​
end

NewSum = 0

loop I = N - 1 TO 0 by -1
NewSum = NewSum + AA * BB ^ (I ^ K) * D / Sum​
recommend = AA * BB ^ (I ^ K) (This adds up high)
pay_out = round((AA * BB ^ (I ^ K)),1) (but correctly sets hi and lo bounds)
.
. (more code to write out data)
.
end

Thanks in advance for any assistance
Bob
Hi Bob! Welcome to MHB!

I haven't tried to analyze your formulas, since I do not know what the rationale behind them is.
But am I right to assume the total amount paid out is almost the same as the payout pool?
If so, your problem is likely caused by rounding errors.

Simplest solution would be to reduce the payout pool by the difference and redo the calculation.

#### btaylor

##### New member

Yes on the total payout must match the amount in the payout pool.

Depending on the amount of the total pool, the difference in the total of all the calculated payoff /place can be thousands off unless I start messing with "K." I can get it pretty close but then the slope gets very steep from 1st to 2nd.

When I figure out how to attach some images to my posts, I'll get some screen shots of the setup and results window.

Bob

#### btaylor

##### New member
Hi Bob! Welcome to MHB!

I haven't tried to analyze your formulas, since I do not know what the rationale behind them is.
But am I right to assume the total amount paid out is almost the same as the payout pool?
If so, your problem is likely caused by rounding errors.

Simplest solution would be to reduce the payout pool by the difference and redo the calculation.
I am attaching two images one from a default setting after importing the total entry$. The other is a balanced payout but had to mess with the smoothing too much. Despite what the smoothing (K) is set at the total payout should always be in balance just with a tighter or bigger spread of payouts below 1st place. Simplest solution would be to reduce the payout pool by the difference and redo the calculation. Not possible. The upper and lower payouts and 80% (in this case) are guaranteed. Also, don't forget that all the fields on the left are variables and the user can modify them to what works best for his result. I don't have to stick with my original code (from the early 90's on Compuserve). If someone comes up with a better solution I'll sure code it to see if it works. Bob #### Attachments • 15.1 KB Views: 24 • 15.7 KB Views: 25 #### Klaas van Aarsen ##### MHB Seeker Staff member Thank you for the reply. Yes on the total payout must match the amount in the payout pool. Depending on the amount of the total pool, the difference in the total of all the calculated payoff /place can be thousands off unless I start messing with "K." I can get it pretty close but then the slope gets very steep from 1st to 2nd. When I figure out how to attach some images to my posts, I'll get some screen shots of the setup and results window. Bob If there is too little money in the pool, there is no solution. And if there is just enough money, you will indeed get a steep slope... #### Klaas van Aarsen ##### MHB Seeker Staff member I am attaching two images one from a default setting after importing the total entry$. The other is a balanced payout but had to mess with the smoothing too much. Despite what the smoothing (K) is set at the total payout should always be in balance just with a tighter or bigger spread of payouts below 1st place.

Simplest solution would be to reduce the payout pool by the difference and redo the calculation.

Not possible. The upper and lower payouts and 80% (in this case) are guaranteed. Also, don't forget that all the fields on the left are variables and the user can modify them to what works best for his result.

I don't have to stick with my original code (from the early 90's on Compuserve). If someone comes up with a better solution I'll sure code it to see if it works.

Bob
All right, I have just implemented a formula and an algorithm of my own.
I get:
Code:
Place   Calculated
1       100.00
2       100.00
3       100.00
4       100.06
5       100.51
6       102.65
7       110.20
8       131.87
9       185.52
10      304.23
11      544.95
12      1000.00
Total   2880.00
Or alternatively, when optimizing for rounded values:
Code:
Place   Calculated
1       100.00
2       100.00
3       100.00
4       100.00
5       101.00
6       103.00
7       110.00
8       132.00
9       185.00
10      304.00
11      545.00
12      1000.00
Total   2880.00
Would you consider either of them a better solution?

#### btaylor

##### New member
"If there is too little money in the pool, there is no solution.
And if there is just enough money, you will indeed get a steep slope..."

Then it is up the the director to adjust how many places he will pay and what the top and bottom amounts are.

The number of participants varies per event, the total pool will vary depending how much money is collected, thus dictating how many places and how much he wants to pay. One time he may have 20 and another time 200. On the 20 he may only pay 3 places; on 200 he may pay 30, 40, or 50 places. That's why they can muck around with the figures to get the best payout spread.

I would like to see what you developed. Can the variables be modified to allow for a flatter curve?

BTW, I may have mislead everybody on the needs. As noted on the screen shots, those  amounts are the minimums for that place payout. So if the top amount is > 1000 then that would be OK. Same with the minimum last payout.

I really appreciate your time at looking at this.

Bob

#### Klaas van Aarsen

##### MHB Seeker
Staff member
Well, here is the algorithm I used (bisection with a constant "power" curve).
I'm afraid it's in a different language than what you may be used to (C++).

Code:
#include <stdio.h>
#include <math.h>

double calcPrice(int place, int n, double m, double M, double power)
{
return m + (M - m) * pow((double)place / (n - 1), power);
}

void calcPayout(double payout, double m, double M, int n)
{
printf("Payout\t%.2f\n", payout);
printf("Max\t%.2f\n", M);
printf("Min\t%.2f\n", m);
printf("Places\t%.d\n", n);

int NMAX = 200;
double PAYOUT_TOL = 0.005;
double ALGORITHM_TOL = 0.00001;

bool solutionFound = false;
double a = 0.01;
double b = 100.0;
double c;
double fa = -1;
double fb = +1;
double fc;
for (int N = 1; N <= NMAX; ++N)
{
c = (a + b) / 2;

double sum = 0;
for (int i = 0; i < n; ++i)
{
sum = sum + calcPrice(i, n, m, M, c);
}
fc = payout - sum;
printf("%d\t%f\t%.2f\t%f\n", N, c, fc, (b - a) / 2);

if ((fabs(fc) < PAYOUT_TOL) || ((b - a) / 2 < ALGORITHM_TOL))
{
solutionFound = true;
break;
}

if (fc * fa >= 0)
{
a = c; fa = fc;
}
else
{
b = c; fb = fc;
}
}

if (!solutionFound)
{
}
else
{
printf("Place\tCalculated\n");
double sum = 0;
for (int i = 0; i < n; ++i)
{
double price = calcPrice(i, n, m, M, c);
sum = sum + price;
printf("%d\t%.2f\n", i + 1, price);
}
printf("Total\t%.2f\n\n", sum);
}
}

void main(void)
{
calcPayout(2880, 100, 1000, 12);
calcPayout(2880, 100, 1000, 12);
}
To introduce a parameter that influences the curve, you can use:

Code:
double gParameter = 0.0;

double calcPrice(int place, int n, double m, double M, double power)
{
double parameterToPower = pow(gParameter , power);
double lastPlaceToPower = pow(n - 1 + gParameter , power);

double factor = (M - m) / (lastPlaceToPower - parameterToPower);
double offset = m - factor * parameterToPower;
return offset + factor * pow((double)place + gParameter , power);
}

void calcPayout(double payout, double m, double M, int n)
{
...
}

void main(void)
{
calcPayout(2880, 100, 1000, 12);
gParameter = 1.0;
calcPayout(2880, 100, 1000, 12);
}
The parameter will have to be greater or equal to zero.

#### btaylor

##### New member
Thank you for the coding. I can handle C++ so I'll translate it and put into procedure to test.

It may be a while but I'll get some feedback to you.

Bob