Code.FinancialDesignPatterns.ProRataDistributor.FindLastIndexPossitiveWeight(int[])

Here are the examples of the csharp api class Code.FinancialDesignPatterns.ProRataDistributor.FindLastIndexPossitiveWeight(int[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Example 7

1. Example

View license
public decimal[] DistributeAllButLast(decimal amount, int[] weights, int decimalPlaces, out decimal deviation)
            {
                var sumWeights = weights.Sum();
                int indexLastPositive = FindLastIndexPossitiveWeight(weights);

                var result = new decimal[weights.Length];
                decimal total = 0;

                for (int i = 0; i < indexLastPositive; i++) {
                    decimal truncated = Truncate(weights[i] * amount / sumWeights, decimalPlaces);
                    result[i] = truncated;
                    total += truncated;
                }

                // last positive weight
                var residual = amount - total;
                var truncatedResidual = Truncate(residual, decimalPlaces);
                result[indexLastPositive] = truncatedResidual;

                deviation = residual - truncatedResidual;

                return result;
            }