2
$\begingroup$

I have a list of 1000 lists, each comprising 100 pairs of numbers, with the first of these numbers running from 1 to 100, and the second being an output from an equation, dependent upon variable G.

Each list gives the results of an equation over 100 time periods (the 1-100 bit), for variable G in my equation taking each whole value between 1 and 1000 (hence 1000 lists).

I also have the following Net Present Value code:

NPV[d_,T_,r_,ex_]:= Sum[r[[t]]-ex[[t]]/Product[1+d[[j]],{j,1,t}],{t,1,T}]

I can make r equal to one of my 1000 lists, and one which ignores the first number in each pair (the 1-100 numbers). Thus r can be specified as a list of 100 numbers corresponding to an output over time for a given value of G. The NPV code discounts these outputs relative to their position in the list (the first output discounted by d, the second d^2 and so on.). ex is also a function of G, so I can input the same value for G that corresponds to the list I have chosen for r, and turn this into a list of 100 numbers. These figures are likewise discounted as above. Thus if I make r equal to the list output when G = 200, I can plug 200 into my ex equation. I can therefore calculate the NPV for any specified value of variable G, when T = 100, and when I also pick a value for d.

However, what I am trying to do is plot the NPV results across all values of G between 1 and 1000, for T = 100, ex = 50000*G, and d = 0.05.

Any ideas how I make that work with my NPV code?

$\endgroup$
2
$\begingroup$

Here's a little demo for some ideas.

lists = {
   {{1, 0.23}, {2, 0.32}, {3, 0.12}, {4, 0.11}, {5, 0.1}},
   {{1, 0.43}, {2, 0.52}, {3, 0.22}, {4, 0.21}, {5, 0.2}},
   {{1, 0.53}, {2, 0.62}, {3, 0.32}, {4, 0.31}, {5, 0.3}}};

NPV[d_, T_, r_, ex_] := Sum[r[[t]] - ex[[t]]/Product[1 + d[[j]], {j, 1, t}], {t, 1, T}]

calc[G_] := Module[{},
  r = Last /@ lists[[G]];
  T = Length[r];
  (* make up some values for ex and d as functions of G *)
  ex = 0.123 r/G;
  d = 0.456 r/G;
  NPV[d, T, r, ex]]

Labeled[ListLinePlot[Array[calc, Length[lists]],
  AxesOrigin -> {1, 0}, Frame -> True, PlotMarkers -> Automatic],
 {Rotate["Net Present Value", 90 Degree], "G from 1 to 3"},
 {Left, Bottom}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks Chris, that's getting me somewhere. However, I don't think I've fully understood the syntax. I want: ex = 50000*G and d = 0.05. d is not dependent on G, and I don't think I have fully understood why r is needed in the ex and d equations you have given. When I input these equations for d and ex, it doesn't work. Is there any way to put these two equations in and get it to run smoothly? $\endgroup$ – Steve Jan 5 '17 at 17:20
  • $\begingroup$ @Steve You could add those details, as far as you have them, as an additional section to your question. It would make clearer reading. $\endgroup$ – Chris Degnen Jan 5 '17 at 19:06
  • $\begingroup$ I have tried to amend it Chris. Thanks for your help. $\endgroup$ – Steve Jan 6 '17 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.