There are two approaches to calculation of duration of a portfolio: (a) weighted-average time to receipt of aggregate cash flows and (b) weighted average of the duration of individual bonds. The first method, duration calculation based on aggregate cash flows is theoretically sound but the second method, the weighted average of individual durations is more common in practice.
Aggregate cash flow method
In the aggregate cash flows method, aggregate cash flows of all the bonds are laid out their cash flow yield is determined by equating the present value of aggregate cash flows to the sum of current prices of all bonds. The Macaulay duration of the portfolio is then calculated by weighting each period by the ratio of the present value of aggregate cash flow occurring at the end of the period to the present value of total aggregate cash flows (i.e. the market value of all bonds on time 0) and summing them up. Even though this approach is theoretically sound, it has a few drawbacks: (a) cash flow yield is not readily available in most cases, (b) it does not correctly account for callable bonds or floating-rate notes, (c) interest rate is typically expressed with reference to benchmark interest rates and not cash flow yield, and (d) changes in cash flow yield is not necessarily same as the change in yields to maturity.
In the weighted average of duration of the individual bonds approach, duration of each bond is weighted by the ratio of its market value to the total market value of the portfolio and summed up. Even though this approach is easier to apply, and it can use effective duration for callable and other complex bonds, it assumes a parallel shift in the yield curve which not always the case.