Compute geometric mean of returns of a data sample when some returns are negative
6 views (last 30 days)
Show older comments
Hi community,
I have a (probably a trivial) question in regards to computing the mean of log returns of 3 assets.
The dataset (real_ret) I have contains 92 returns whereas some are negative.
When I try to compute the following:
geometric_ret = exp(mean(log(real_ret))); (we should use this according to our finance professor, and it works when the dataset only contains positive values).
I get an answer that is 0.0048 + 0.0172i, 0.0173 + 0.0488i, etc..
I realize that the "+ 0.0172i" part comes from the fact that the dataset contains negative values, but how do you work around this issue to get the correct geometric mean of returns?
The dataset is a 92x4 double.
Thank you.
1 Comment
Bjorn Gustavsson
on 11 Nov 2021
The only way this makes sense to me is if your real_ret is the change of value (possibly relative change) such that all the values of the commodities/stocks/whatevers remain positive - if this is the case then you'd have to add the initial values to each and calculate the geometric mean of that, and compare to the geometric mean of the initial values.
Answers (1)
Shivam Lahoti
on 15 Feb 2024
Hi Jesper,
The appearance of complex numbers when computing the geometric mean of log returns suggests that the logarithm function is being applied to negative numbers, which is mathematically invalid for real numbers. Log returns should be calculated from positive asset prices, and they can be negative if prices decrease, but this should not cause complex numbers in the calculation.
To compute the correct geometric mean of log returns, take the following steps:
- Verify Log Returns: Ensure that the log returns are calculated correctly from positive price data as log(P_t / P_{t-1}).
- Use Arithmetic Mean for Log Returns: Calculate the arithmetic mean of the log returns directly. This is the correct approach when dealing with log returns, as they can be negative but still represent valid percentage changes over time.
- Exponentiate the Mean: Apply the exponential function to the arithmetic mean of the log returns to obtain the geometric mean return.
arithmetic_mean_log_returns = mean(real_ret);
geometric_ret = exp(arithmetic_mean_log_returns);
This will result in a real-valued geometric mean return for each asset. If you still encounter complex numbers, there may be errors in your dataset. Double-check the data to ensure all prices are positive and that the log returns are calculated correctly. Correct any data issues before attempting to recalculate the geometric mean return.
I hope it helps,
Shivam.
0 Comments
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!