Simple Pound

A trip down personal finance lane.
  • rss
  • Home
  • About
  • Best Of…
  • Progress
  • Library
  • Book reviews
  • Archive
  • Contact

Geometric mean with negative numbers

July 12, 2008

Thanks for visiting! If you like what you're reading, you may want to subscribe to my RSS feed.

This won’t quite be a conventional Personal Finance post, but the fact that I cannot calculate my portfolio’s performance without converting negative returns into “false positive” ones annoyed me too much to just ignore. Since I couldn’t find a straightforward way around it, I decided to simply code the Excel function I was looking for myself.

While the code is by no means perfect (yet) it does the job nicely and I’m nevertheless pleased with the result. As long as it gets called properly, it converts your negative percentages into a value equivalent to (100 - x) / 100 where x is your percentage. For positive values, it does the conversion according to (100 + x) / 100. These conversions means that a decrease of 10% will be expressed as 0.9 and an increase of 10% as 1.1 which subsequently allows you to compute the geometric mean (which is exactly what it does).

Below is the VBA code you will need to utilise this functionality. Feel free to use it as you please but don’t worry if you have no clue how exactly to do that. I have included a step-by-step description of how to install and call it from your Excel worksheet underneath the code.

Function geometric(data As Variant)
     Dim vaData As Variant
     Dim rnData As Range
     Dim i As Long
     Dim j As Long
     Dim iblank As Long
     Dim jblank As Long
     Dim bblank As Boolean
     Set rnData = data
     vaData = rnData.Value
     temp = 1
     n = 0
     For j = 1 To UBound(vaData, 2)
          For i = 1 To UBound(vaData, 1)
               If vaData(i, j) <> Empty Then
                    vaData(i, j) = 1 + vaData(i, j)
                    ’ compute product for non-empty data cells
                    temp = temp * vaData(i, j)
                    ’ count number of items in list
                    n = n + 1
               End If
          Next i
     Next j
geometric = (temp ^ (1 / n)) - 1
End Function

Follow the steps below to make the above function available in your Excel worksheet:

  1. In Excel, open the file you want to use the function in. Note: at the moment the function will only be available on a per-file basis. That means, if you’re planning to use it in more than one file, you will need to repeat this procedure for every single file. I’m working on coding a proper add-on that you simply install into Excel and hence make available to any new or existing file. I told you it was work in progress… ;-)
  2. In the menu bar, next to the entry “File”, right-click on the Excel icon and select “View Code”
  3. The Microsoft Visual Basic Editor opens and you stare at a blank document
  4. In the menu bar, click on “Insert” followed by “Module”
  5. Copy and paste the above code into that “new” blank space and hit “Save”
  6. After you have saved the changes, click on “File” and select the entry “Close and return to Microsoft Excel”. This brings you back to where you started, and your function is ready to use.

Here is how you use the function:

  1. Open the file in which you have installed the above function
  2. Pick a cell that you want the result to contain and type “=geometric(”
  3. Note the opening bracket !
  4. With your mouse click and hold until you have highlighted the cell range that contains the numbers you want the geometric mean of. Alternatively, type the cell range yourself as A1:D4 where A1 should be replaced by the coordinates of your first cell and D4 should be replaced by the last cell’s identifier. At the moment, the geometric function only works with a cell range, not individual cells or numbers. I’m working on it… ;-)
  5. Close the bracket by typing “)”
  6. Hit ENTER to see the geometric mean of your highlighted cells

If you format the cell in question in such a way to convert your result back into a percentage (just right-click, choose Format - Number Format - Percentage), the result should make sense in the context of portfolio returns.

Note that the code above has been tested and verified in Excel 2002 and should work with any other Excel version(s) since. The only concern I have regards the compatibility with - you might guess it - Excel 2007. If anyone manages to run it under the new Office version, please let me know!

As usual, if you have questions or concerns, find a bug or just need a hand to get it to work, just give me a shout or leave a comment! I hope you will find it as useful as I did. :-D

Bookmark It

Add to Del.icio.us Add to digg Add to Facebook Add to Google Bookmarks Add to Newsvine Add to reddit Add to Stumble Upon Add to Technorati Add to Yahoo My Web
Hide Sites
Comments
11 Comments »
Categories
Misc
Tags
calculations, Excel, geometric mean, portfolio, spreadsheets
Comments rss Comments rss
Trackback Trackback

Portfolio Returns - The Basics

June 28, 2008

I’m back from holiday and it’s time to start my new series on portfolio returns (as discussed in my previous post) with some basics on averages, limits and other interesting information you can extract from your data without too much effort. Since I’m working on a spreadsheet alongside these posts, I will also include some Excel references that you can use to shortcut the calculations.

Based on my outline, this is what I’m looking to cover in this post:

  • arithmetic mean
  • geometric mean
  • frequency distribution / histograms
  • maximum and minimum value
  • positive / negative number of weeks / months / years

Arithmetic Mean

The arithmetic mean is more commonly referred to as the average (or just mean) and is calculated by summing all numbers of a list and subsequently dividing the result by the number of items in the list. Finding the average of three numbers A, B and C would involve forming the sum A + B + C and dividing by 3. It answers the question “If all quantities had the same value, what would that value have to be in order to achieve the same total?” and the calculation is relevant whenever the quantities concerned add together to produce a total. For instance, if you buy milk, bread and butter you will be expected to pay a total sum to cover the price of these three items and calculating the average would tell you what price a different product X would have to have so that you could buy three instances of X and end up paying the same amount.

The trouble with the simple average is that is greatly influenced by outliers, i.e. extreme values at either end of the spectrum. If you calculate the average of ten 5s and 1000 you will end up with (10 * 5 + 1000) / 11 = 95.45 which is unproportionately large and could give the impression (assuming the individual data points are not known) that the data is concentrated around values just short of 100. This problem is a simple example of skewed distributions where the mean of a data series doesn’t coincide with the median (the “middle value” if you were to list them all).

Finally, the arithmetic mean is not suitable for calculating stock performance since you’re looking for the product of the yearly performance, not the sum of those values. Consider an investment that loses 10% of its value in the first year and gains 30% in the second year. Now the annualised performance since you started investing is not [(-10%) + 30%]/2 = 10% but in fact 8.2% since the 30% increase only affects the 90% of your investment that’s left after the first year. To correctly calculate annualised performance rates like this we will have to use the geometric mean.

Excel Function: AVERAGE(number1, [number2], …)

Geometric Mean

The geometric mean is a value that gives an indication of the central tendency of a set of numbers (i.e. of a distribution) regardless of whether this distribution is normal or skewed. In other words, it shows the “typical value” of a list of values. Note that this is different from the most common value which is a mathematical value called “mode”. It answers the question “If all quantities had the same value, what would that value have to be in order to achieve the same product?” and hence is relevant whenever quantities multiply together to produce a product. The geometric mean is always less than or equal to the arithmetic mean.

To calculate the geometric mean you need to multiply all the values in your set and subsequently find a scientific calculator to take the nth root of the product where n is the number of numbers you previously multiplied. In the simplest case when calculating the geometric mean of two values A and B you would need to take the square root of A*B. Unfortunately, this also means that the geometric mean in its purest form can only be applied to positive values as (in conventional mathematics and without exploring imaginary values) you cannot take the root of a negative number.

While we all hope that our investments are going to increase year after year, we can’t simply assume this and happily apply the geometric mean without a little work first. To take negative growth into account, you will need to look at your percentage values from a slightly different angle. Let’s go back to our original example of a return of -10% in the first year and 30% in the second year. After the first year, only 90% of your original investment will remain - that is, your portfolio will stand at 0.9 instead of 1 (= 100%). In the second year, you’re more lucky and see a 30% growth of that remainder. If you would have had a fresh portfolio (i.e 100% = 1) you’d now be left with 130% of your money or 1.30. Since you only had 90% remaining we need to multiply 0.9 by 1.30 to get 1.17. This means that in relative terms to the amount you started with, your investment is worth 17% more after 2 years. To now calculate the annualised growth rate of your investment we need to take the square root of 1.17 which yields 1.0816 or a growth of 8.16% per annum.

The Excel function given below does not convert your percentages accordingly so the restriction with regards to positive values still applies. So far, I haven’t been able to find an in-built function that does the work for you which I find rather frustrating. It is extremely annoying to represent a 10% drop in my portfolio as 0.90 and if I don’t come across a more workable solution soon, I will probably end up writing a function myself :-) If you know something that I don’t please let me know before I spent hours writing an Excel Add-In from scratch.

Excel Function: GEOMEAN(number1, [number2], …)

Frequency Distribution

If you’re a visual thinker like myself, you will appreciate that I often find it more helpful to look at a graph instead of raw numbers. An obvious choice in the case of portfolio returns is a histogram which is based on a frequency distribution. At this stage, I won’t dwell on this topic for long as I haven’t got sufficient data yet to experiment with histograms and the associated frequency distributions yet. As soon as that is the case, I will almost certainly give you a little more insight into this topic.

For the moment, imagine that you have two buckets in which you need to throw little cards that represent your portfolio performance - whether you’re looking at weekly or monthly returns or any other values is fairly irrelevant as long as you have enough data. Your task now is to separate the positive returns from the negative ones by throwing them into their respective buckets. Once you’re done with that, you can draw a simple bar graph with the number of items per basket representing the height of an individual bar (assuming one unit width per bar). Voila - there is your first histogram :-D

If you imagine that you could have as many buckets as you like, then you only need to come up with a criteria to decide which bucket contains what data to create whatever histogram you like. You could distinguish between negative and positive values, determine 5% steps or pick any other classification you might find useful. The only rule is that categories must not overlap - i.e. there is always one unique bucket for every single piece of data and at no point would any value (whether in your sample or not) match two or more buckets.

The interesting thing about histograms is that it’s not technically the height of a bar that determines the value it represents (unlike in a simple bar chart where only the height matters) but it’s the area that is covered by it. Hence you could draw a bar that’s one inch wide and three inches high and that would represent the same value as a bar that’s three inches wide and one inch high. For this reason the bars of a histogram have to be adjacent with no gaps in between.

Because you are free to choose however many buckets you want to use when constructing a histogram (the official term for my made-up bucket is “bin”) much research has been done to determine the optimal number of bins as too small a number might hide valuable insights while too many bins render the diagram useless. The level of granularity is crucial. One formula that has been put forward is k = [(max(x) - min(x)) / bin width h] where k represents the optimal number of bins and max(x) and min(x) denote the maximum and minimum values of your data respectively. Whatever value you calculate, you should round up to the nearest full value and use this to create your categories.

Excel 2007 includes an Add-In that creates a histogram from your data if presented in the correct way (data values in one column, bin limits in second column) and hence extends the basic FREQUENCY function that simply returned an array of values. While I have Excel 2007, the data arrangement it requires to execute properly doesn’t work very well if you’re planning to have more than just a histogram graph in your worksheet. Further, from the previews I have seen of the functionality, the histogram looks wrong as there are in fact gaps between the bars (which violates the rules given above). Hence, once more I find myself wondering whether I should invest the time and effort to create something a little more elegant myself. Stay tuned :-)

Maximum and Minimum Value

Since I assume you graduated from primary school long ago, I don’t really need to explain the meaning of maximum and minimum value to you. I simply include it for completeness’s sake and to create a central place for all important Excel functions ;-)

Excel Function: MAX(number1, [number2], …) and MIN(number1, [number2], …)

Positive and Negative Number of Weeks

This is an interesting little insight I came across in the book I was reading about Asset Allocation not long ago. While it doesn’t tell you that much per se, it gives you valuable perspective and a sense of patience when you’re tempted to give up your long-term investing for short-term speculation. If you can see that your investment is up most weeks / months / years and only down in value occassionally, you might find it easier to sit out the rough patch - rest assured that other (better) times will come.

To avoid having to count these items manually every time you update the performance, you can use the Excel function COUNTIF that looks at a list of values and only counts the instances that fit a criteria given as part of the formula. By using the criteria “>0″ you will end up with a count of all positive values, while “<0″ returns a total of negative occurences.

Excel Function: COUNTIF(range, criteria)

I hope you enjoyed this first introduction into maths and basic statistics as I very much look forward to researching the upcoming posts! If you have any questions or concerns, just leave a comment and either myself or another reader will surely be able to help.

Bookmark It

Add to Del.icio.us Add to digg Add to Facebook Add to Google Bookmarks Add to Newsvine Add to reddit Add to Stumble Upon Add to Technorati Add to Yahoo My Web
Hide Sites
Comments
No Comments »
Categories
Investing
Tags
calculations, Excel, histogram, mean, portfolio returns, spreadsheets, statistics
Comments rss Comments rss
Trackback Trackback

How do you measure your portfolio’s return?

June 16, 2008

Admittedly, it’s been getting very quiet on the blog front and you’ve all heard the excuses of working late and being busy, so I won’t bore you for very long before moving on to more interesting stuff. But can I just say that I also walked 20 miles for charity and that took away some blogging time! :-P I bet that’s a new one for most of you…

Anyway, as I promised in my last post (yes it’s been a while) I have had an idea about a series of posts that might be of interest to you, especially if you really really like numbers (like I do). While reallocating my pension across several funds, I kept wondering how to best measure how well (or badly) my choices were performing compared to the market in general. For a start I have split money fairly evenly across index funds and actively managed funds in a way that will hopefully allow me to compare apples with apples - i.e. simply speaking, for each asset class I have picked an index fund as well as an actively managed fund to compare their performance against each other.

Somehow, that didn’t seem good enough and so I did some research on what else I could do. As I said, I like Maths and numbers because they have an inherent logic and beauty… great, now I sound like a total geek. Or idiot. Your choice ;-)

Hence, here’s my line-up of posts that will hopefully appear throughout June and July (bear with me as I’m also going on holiday in three days). I’m not going to explain much (or anything) at this stage, because otherwise there’s not much point in writing separate posts about each. I simply hope you’ll be excited to read what’s coming up and all the things you might be able to learn soon(ish).

1. Post : The Basics
- arithmetic mean (average loss, average gain)
- geometric mean
- frequency distribution
- maximum value
- minimum value
- positive # of years / months / weeks
- negative # of years / months / weeks

2. Post : Risk
- VAR: value at risk
- M-squared

3. Post : Statistics
- standard deviation
- semi-variance (semi-deviation)
- downside variance
- below-target probability

4. Post : All About Interaction
- covariance: degree of variability of returns between two assets
- correlation coefficient
- units of annual return per unit of std. dev.
- expected final value of $1.00 / £1.00

5. Post : First lesson in Greek
- beta coefficient or an assets’ degree of responsiveness to market movements

6. Post : Advanced Greek
- alpha or superior returns

7. Post : More Jargon
- sharpe ratio

Some of these will be rather obvious, or aren’t even really mathematical but I thought they were nevertheless useful when analysing your portfolio. I’m going to try my best to explain even the more complex concepts in a straight-forward way that will make you (and me) understand why exactly a particular formula might in fact be useful.

Knowing myself, all of the above will eventually end up in a big spreadsheet, which I naturally will also make available to you so you don’t have to play with Excel for hours to get it all onto one page (surprisingly enough not everyone finds that sort of stuff fascinating).

I’m getting rather excited while writing this, so hopefully my energy won’t be wasted and you’ll enjoy it as well! :-D Let me know if you think I’ve omitted anything absolutely obvious that shouldn’t be missing from a series of posts on portfolio calculations.

Bookmark It

Add to Del.icio.us Add to digg Add to Facebook Add to Google Bookmarks Add to Newsvine Add to reddit Add to Stumble Upon Add to Technorati Add to Yahoo My Web
Hide Sites
Comments
1 Comment »
Categories
Investing, Popular
Tags
calculations, Investing, portfolio, risk return, series, statistics
Comments rss Comments rss
Trackback Trackback

Net Worth

39.2%

Categories

  • Budgeting (6)
  • General (11)
  • Goals (7)
  • Housing (8)
  • Insurance (1)
  • Investing (36)
    • Bonds (5)
    • Funds (13)
    • Shares (3)
  • Misc (15)
  • News (17)
  • Popular (11)
  • Read this! (20)
  • Reviews (19)
    • Books (3)
    • End of month (16)
  • Savings (16)
  • Uncategorized (1)

Library

I am reading...

Just finished...
The Art of Asset Allocation
The Essays of Warren Buffet

Blogroll

  • Dividend Money
  • Fat Pitch Financials
  • Get Rich Slowly
  • I Will Teach You To Be Rich
  • Money Watch (UK)
  • Money, Matter, and More Musings
  • MoneyPot (UK)
  • My Open Wallet
  • My Wealth Builder
  • No Credit Needed
  • Plonkee Money (UK)
  • Punny Money
  • The Digerati Life
  • The Dividend Guy Blog
  • The Finance Buff
  • The Simple Dollar
  • This is Money (UK)
  • Well-Heeled
  • Wise Bread

Financial Sites

  • Digital Look
  • Fool
  • Morningstar (UK)
  • Totally Money

Sponsors

Financial Web
Information about everything from Debt Consolidation to Credit Cards

Tags

Asia bank charges bond prices Bonds Books Budgeting calculations compound interest CPI credit risk Dilbert downloads emergency fund end of month Europe Excel Fixed Income funds Goals graduates house prices index tracker inflation interest rates Investing ISA national insurance net worth News overdraft charges parents piano portfolio quotes risk return Savings Shares Simple Dollar spreadsheets statistics stock indices student loans tax Tom Brennan Zopa
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox