3
$\begingroup$

I need to calculate weighted median return for a portfolio (using MATLAB). There is information available online: MATLAB Central/rates&weights and Excel/note 4+4+4+7+7/5 logic

How would you calculate weighted median for following portfolios with given weights and returns?

Much of online help is about returns with frequencies. I think the Matlab code in the solution above does not account for ties correctly.

Eg. A portfolio has 6 investments with the following returns:

            A       B     C     D     E     F
weights:    0.1     0.1   0.1   0.2   0.1   0.4
returns:    10%     20%   30%   1%    2%    1%

weighted mean = *easy!*
weighted median = 1%??

            A      B     C      D      E      F     G     H
weights:    0.15   0.1   0.15   0.09   0.01   0.01  0.14  0.35
returns:    0.05%  1%    1%     1%     1%     2%    2%    5%

weighted mean = *easy!*
weighted median = 1.5%?? <or should it be (1+1+1+1+2+2)/6??>
$\endgroup$
2
  • $\begingroup$ Could you elaborate on what sense you think it treats ties incorrectly? The weighted median in the example quite clearly is 1%, because the weights assigned to it are 0.6 out of 1.0, showing that 1% constitutes the bottom 60% of this weighted empirical distribution. $\endgroup$
    – whuber
    Commented Jul 21, 2015 at 18:16
  • $\begingroup$ Please see the updated example. I have added the (1+1+1+1+2+2)/6 in the query now to highlight my doubt. Medians are not affected by this but per the second URL, I want to be sure I'm not missing anything. I haven't used weighted medians before. $\endgroup$
    – Maddy
    Commented Jul 21, 2015 at 18:57

1 Answer 1

3
$\begingroup$

As detailed in this answer on the math SE, weights in a weighted median are expressed duplicates of the datum. In your top example, replace the weights with their multiples of ten, like so:

            A       B     C     D     E     F
weights:    1       1     1     2     1     4
returns:    10%     20%   30%   1%    2%    1%

Sort these by return and you have 1 1 1 1 1 1 2 10 20 30; the median of this pseudo-dataset is the weighted median, in this case the average of the middle two values, i.e. 1%. If you repeat this exercise for the second set, you'll see that the value is 1.5%.

Also note that the weighted-median is the same for any vector of weights proportional to this one. (This is straightforward to prove, but I leave that to you.)

$\endgroup$
2
  • $\begingroup$ Can you please check - I get median in second case as 1.5% when done manually using your approach $\endgroup$
    – Maddy
    Commented Jul 21, 2015 at 20:15
  • $\begingroup$ You are correct, I must have switched a number or two :) $\endgroup$ Commented Jul 21, 2015 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.