Browse Groups

• ... You might try a while loop; ie: let upper-bound some-number; where some-number is equal to an integer (25 in your case) let dependent-variable 0; where
Jun 30, 2011 1 of 5
View Source
--- In netlogo-users@yahoogroups.com, "vectistim" <vectistim@...> wrote:
>
> Is there some sort of function for carrying out a summation?
>
> I want to calculate a Net Present Value (NPV) for a 25 year income, which would normally be:
>
> Sum from t=1 to 25 R/(1+r)^t
>
> Since I can't find a function for this, I presume that I need an algorithm for it, normally I would use a do, or for, loop but that doesn't seem to be an option either.
>
> Any ideas?
>
> Thank you.
>

You might try a while loop; ie:

let upper-bound some-number; where some-number is equal to an integer (25 in your case)
let dependent-variable 0; where dependent-variable is the NPV
let t 1; time counter (unit specific - years in your case)
while [t <= upper-bound]
[set dependent-variable dependent-variable + (25 * R / ((1 + r) ^ t))
set t t + 1]

The loop above assumes that the upper-bound, t and, the dependent-variable are local variables not needed outside the procedure called.

Hope this helps,
MCB
• Thank you. I ve managed to sort it using repeat, which is fairly similar to your second version. (I didn t know there was a while or a repeat, I d looked in
Jul 1, 2011 1 of 5
View Source
Thank you.

I've managed to sort it using repeat, which is fairly similar to your second version.
(I didn't know there was a while or a repeat, I'd looked in the dictionary for do and for loops and couldn't find them)

--- In netlogo-users@yahoogroups.com, "Alvaro" <algil_b@...> wrote:
>
> Hi
>
> You can use a reporter like this:
>
> to-report npv [f r]
> ;f : an array of net cash flow
> ;r : the rate
>
> let i 1
> let result 0
> if is-list? f
> [
> let p length(f)
> while [i <= p]
> [set result result + (item (i - 1) f) / ((1 + r) ^ (i - 1))
> set i i + 1]
> ]
> report result
> end
>
> Now let's say you have a case like this (taken from Wikipedia):
> A corporation must decide whether to introduce a new product line. The
> new product will have startup costs, operational costs, and incoming
> cash flows over six years. This project will have an immediate (t=0)
> cash outflow of \$100,000 (which might include machinery, and employee
> training costs). Other cash outflows for years 16 are expected to
> be \$5,000 per year. Cash inflows are expected to be \$30,000 each for
> years 16. All cash flows are after-tax, and there are no cash
> flows expected after year 6. The rate of return is 10%. The cash flow
> will be like this:
> Year 0 -> -100.000
> Year 1 -> 30.000 - 5.000
> Year 2 -> 30.000 - 5.000
> Year 3 -> 30.000 - 5.000
> Year 4 -> 30.000 - 5.000
> Year 5 -> 30.000 - 5.000
> Year 6 -> 30.000 - 5.000
> And the Present value will be : \$8,881.52
>
> In NetLogo yo should type in the screen:
> show npv [-100000 25000 25000 25000 25000 25000 25000] 0.1
> And the result is: observer: 8881.517486555618
>
> Notice that this code considers an array where you can put non constant
> values, but if the cash flow is constant, you can create a simpler
> reporter like this:
>
> to-report npvc [v r t]
> ;v : the fix value over the time
> ;r : the rate
> ;t : the time period
>
> let i 1
> let result 0
> while [i <= t]
> [set result result + v / ((1 + r) ^ i)
> set i i + 1]
> report result
> end
> Again, in the input screen you type
> show (npvc 25000 0.1 6) - 100000
> and the result is the same.
>
> Alvaro Gil
> École Polytechnique de Montréal
>
>
>
> --- In netlogo-users@yahoogroups.com, "vectistim" <vectistim@> wrote:
> >
> > Is there some sort of function for carrying out a summation?
> >
> > I want to calculate a Net Present Value (NPV) for a 25 year income,
> which would normally be:
> >
> > Sum from t=1 to 25 R/(1+r)^t
> >
> > Since I can't find a function for this, I presume that I need an
> algorithm for it, normally I would use a do, or for, loop but that
> doesn't seem to be an option either.
> >
> > Any ideas?
> >
> > Thank you.
> >
>
• This can also be written using map and n-values, as follows: to-report npvc [v r t] report sum map [v / ((1 + r) ^ ?)] n-values t [? + 1] end -- Seth Tisue |
Jul 8, 2011 1 of 5
View Source
This can also be written using map and n-values, as follows:

to-report npvc [v r t]
report sum map [v / ((1 + r) ^ ?)]
n-values t [? + 1]
end

--
Seth Tisue | Northwestern University | http://tisue.net