Re: Efficient compounding of growth figures
- To: mathgroup at smc.vnet.net
- Subject: [mg68006] Re: Efficient compounding of growth figures
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Thu, 20 Jul 2006 06:04:47 -0400 (EDT)
- References: <e9kuas$l2l$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
FoldList[Times, 1, 1+samplelist] Michael Stern wrote: > I found the answer to my own question in a posting on this list from 2001. > > FoldList[#1(1+#2)&,1, samplelist] > > Thanks, > > MS > _____ > > From: Michael Stern [mailto:stern at merrinmanagement.com] To: mathgroup at smc.vnet.net > Subject: [mg68006] Efficient compounding of growth figures > > I have a list of periodic percentage changes in a time series. For example, > > samplelist= {0.018, 0.017, 0.009, 0.022, 0.009, -0.005, 0.027, 0.02, 0.013}; > > I need to create a new list that shows the effect of compounding these > changes over time. In other words, element n of the answer list equals > (1+Part[samplelist,1]) * (1+Part[samplelist,2]) * ... * > (1+Part[samplelist,n]) > > The answer, in the case of the example above, is {1.018, 1.03531, 1.04462, > 1.06761, 1.07721, 1.07183, 1.10077, 1.12278, 1.13738}. > > I have created the following function, which gives the correct answer, > inserting the starting normalized value 1 at the start of the list. > > compoundlist[changes_]:=Table[Product[Prepend[1 + changes, 1]j > <http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=j> , > {j, 1, i}], {i, 1, Length[Prepend[changes, 1]]}] > > This works perfectly but it is very inefficient. It repeats calculations > over and over again that need to be done only once. I would appreciate any > counsel on how to do this more efficiently. > > Thanks in advance, > > Michael Stern