First, for each date in your input dataset, assign the amount of time between the date and today.
For example: the next date set {today, tomorrow, yesterday, a week from today} becomes {0, 1, 1, 7} . Formally: val[i] = abs(today - date[i]) .
Second, invert the values so that their relative weights are reversed. The easiest way to do this is: val[i] = 1/val[i] .
Other offers:
val[i] = 1/val[i]^2val[i] = 1/sqrt(val[i])val[i] = 1/log(val[i])
The hardest and most important part is deciding how to invert the values. Think about the nature of the balance. (Do you need noticeable differences between two distant dates, or maybe two far dates should have fairly equal weights? Do you want a date that is very close to today to have an extremely large weight or a sufficiently large weight?).
Note that you must come up with an invert procedure in which you cannot divide by zero. In the above example, dividing by val[i] results in dividing by zero. One way to avoid dividing by zero is called smoothing . The most trivial way to “smooth out” your data is to use smoothing with the addition, where you simply add one to each value (so today it becomes 1, tomorrow it becomes 2, next week it becomes 8, etc.).
Now the easiest part is to normalize the values so that they sum to one.
sum = val[1] + val[2] + ... + val[n] weight[i] = val[i]/sum for each i
source share