Example #1
0
        public void Redistribute_TotalWeightLessThanOne_RedistributedWeightIsAprroxOne()
        {
            var weights = new StockWeights
            {
                { "TLV", 0.1m }, { "FP", 0.2m }, { "EL", 0.3m }
            };

            weights = weights.Redistribute();

            Assert.IsTrue(weights.Sum(w => w.Value).IsApproxOne());
        }
Example #2
0
        /// <summary>
        /// Equaly redistributes weights such that their sum is 1.
        /// </summary>
        /// <remarks>
        /// This applies for both cases, weights over 1 or less than 1.
        /// </remarks>
        public static StockWeights Redistribute(this StockWeights weights)
        {
            var totalWeight = weights.Sum(w => w.Value);             // this needs to become 1 after redistribution

            return(weights.Select(w => (w.Key, w.Value / totalWeight)).AsStockWeights());
        }