More fun with percentages
Posted: September 24th, 2018, 1:52 pm
I posted a request a few months ago about hard-coding a particular percentage calculation, and received some useful validation.
viewtopic.php?f=27&t=11210
So I thought I'd crave your indulgence again...
Briefly, I'm trying to automate a routine for calculating the overall percentage rise (or fall) over those five-year time series that are common in the world of investing -- ie, an investment trust's percentage perfomance over (say) 2013, 2014, 2015, 2016, and 2017.
If the annual outcomes are all positive, the calculation is trivially easy. An IT delivering a consistent 10%, say, would have delivered an accumulatated 61.051% over the five years.
The problem comes when some annual outcomes are negative. Here, calculations involving multiplication produce "silly" results with the wrong sign.
If the sixth year is not +10% but minus 10%, for instance, the conventional multiplication (1 x 1.1 x 1.1 x 1.1 x 1.1 x 1.1 x (-1.1)) produces -1.771561 (wrong sign), ie 1.61051 x -1.1, rather than 1.61051 minus (1/10th of 1.61051 = 0.161051) = 1.449459.
So before I code something really clutzy, I thought I'd ask here to see if there's any more elegant solution. As ever, I'm aware that these calculations are not without their hidden dangers, and so I could be barking up the wrong tree altogether. So either way, validation or correction will be useful.
MDW1954
PS I've deliberately chosen to show the calculation above in its "long hand" form for clarity. I'm aware that (where the growth each year is always the same) I could have raised to the nth power, instead.
viewtopic.php?f=27&t=11210
So I thought I'd crave your indulgence again...
Briefly, I'm trying to automate a routine for calculating the overall percentage rise (or fall) over those five-year time series that are common in the world of investing -- ie, an investment trust's percentage perfomance over (say) 2013, 2014, 2015, 2016, and 2017.
If the annual outcomes are all positive, the calculation is trivially easy. An IT delivering a consistent 10%, say, would have delivered an accumulatated 61.051% over the five years.
The problem comes when some annual outcomes are negative. Here, calculations involving multiplication produce "silly" results with the wrong sign.
If the sixth year is not +10% but minus 10%, for instance, the conventional multiplication (1 x 1.1 x 1.1 x 1.1 x 1.1 x 1.1 x (-1.1)) produces -1.771561 (wrong sign), ie 1.61051 x -1.1, rather than 1.61051 minus (1/10th of 1.61051 = 0.161051) = 1.449459.
So before I code something really clutzy, I thought I'd ask here to see if there's any more elegant solution. As ever, I'm aware that these calculations are not without their hidden dangers, and so I could be barking up the wrong tree altogether. So either way, validation or correction will be useful.
MDW1954
PS I've deliberately chosen to show the calculation above in its "long hand" form for clarity. I'm aware that (where the growth each year is always the same) I could have raised to the nth power, instead.