Portfolio summary calculations

The lot calculations are by far the trickiest part of entire process. Once that step is done, the summary values for each security are calculated. These are the values that appear in each row under the Performance tab. First, cost basis, market value, gain, and todays gain are all computed as the sum of the corresponding values of all the lots for a security. Then the gain percentage is calculated by:

gain percentage = gain / cost basis

The total return for each security is calculated similarly: Returns gain and cash out are summed over all the lots for the security, then the total return is calculated by:

total return = returns gain / cash out

Next, the summary values for the portfolio are calculated. These are the values that appear along the final row in the Performance tab. First, for each of the securities in the portfolio, cost basis, market value, gain, and today's gain are converted from the security's currency to the portfolio currency (which you can set in the Edit Portfolio page). Then the converted values are summed over all the currencies to give the portfolio values. Market value is adjusted by adding any cash deposits and subtracting any cash withdrawals. Then gain percentage is computed in the by-now familiar way:

gain percentage = gain / cost basis

Finally, the overall return is computed by converting the returns gain and cash out from each of the securities from the security currency to the portfolio currency, then summing them to get portfolio values. The total return is the calculated by:

total return = returns gain / cash out

Currency: an extra wrinkle for global portfolios

Currency is an issue worth revisiting, because it can get a little complicated. Every security on Google Finance has a currency in which it is valued. For example, GOOG is priced in dollars, whereas Vodafone (LON:VOD) is priced in British pence. The currency we use for a security is the currency used by the stock exchange on which the security is traded. Since all the securities need to be combined in order to show portfolio currencies, you have the option to specify a portfolio currency by clicking the "Edit Portfolio" link on the main portfolio page. When the security values, such as gain or market value, are rolled up for all the companies, each is first converted from its own currency to the portfolio currency, using today's exchange rate. Then all the summary values will be displayed in the portfolio currency.

End Notes

[1] U.S. Dept. of the Treasury, Internal Revenue Service Publication 550, "Investment Income and Expenses (Including Capital Gains and Losses)", 2008. Chapter 4, Section "Basis of Investment Property", Subsection "Identifying stocks or bonds sold", Paragraph "Identification not possible": "If you buy and sell securities at various times in varying quantities and you cannot adequately identify the shares you sell, the basis of the securities you sell is the basis of the securities you acquired first." This rule is sometimes called FIFO, for "First in, First Out". Since Google Finance does not let you manually match sales with lots, this is a reasonable rule to use.

9/30/09, written by Patrick Coskren, Software Engineer