Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Split a value into list of rounded numbers according to a list of target proportions
ResourceFunction["RoundedPercentageAllocation"][total,proportions] creates a list of integers that sum to total and are also as close to the given proportions as possible. | |
ResourceFunction["RoundedPercentageAllocation"][total,proportions,d] creates a list of numbers that sum to total and are multiples of d. |
Split 100 into proportions of 1/3 and 2/3 to the nearest integer:
In[1]:= |
Out[1]= |
In most financial currencies, one would typically allocate it to the nearest 0.01:
In[2]:= |
Out[2]= |
As long as the total is a multiple of the allocation amount, the result will always sum to the original total:
In[3]:= |
Out[2]= |
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
However, the proportions in the result are usually not exactly the requested proportions:
In[8]:= |
Out[8]= |
If the input number is not divisible by the allocation size then the result will add up to less then the original:
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
If you allocate an amount to proportions that do not sum to one, the proportions will be rescaled so that they do sum to 1:
In[11]:= |
Out[11]= |
This work is licensed under a Creative Commons Attribution 4.0 International License