help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] IRR (Internal Rate of Return) using MathProg


From: Meketon, Marc
Subject: Re: [Help-glpk] IRR (Internal Rate of Return) using MathProg
Date: Sun, 16 Sep 2012 09:04:37 -0500

I think I have a solution.  I would like to use a simpler example, and let you (Noli) work out the details for IRR.

 

It is well known, and your links show how, to use Newton's algorithm (aka Newton Raphson's algorithm) to find the IRR, since it's really find a root of a polynomial (see the other post by Jeffery Kantor, which also describes the fact that depending on the cash flows, there could be multiple solutions).

 

For my simpler example, suppose you wanted to find, in GLPK, the square root of "n".  This is the same as solving for the root of the function f(x) = x*x -n .

 

Newton's algorithm, in general, is where you begin with a reasonable approximate, say x_0 = n/2, then iterate until convergence:

                                                                                                              

                x_(k+1) = x_k - f(x_k)/f'(x_k)

 

In our case, f'(x) = 2x, so   x - f(x)/f'(x) = x/2 + n/(2x),

 

It would be nice to have, after the "solve" statement, the ability to say something like the following in GLPK (note that I hardcoded 10 iterations):

 

param n:=16;

 

param x := n/2;

for{k in 1..10} {

  let x := x/2 + n/(2*x);

}

 

printf "Sqrt of %f = %f\n", n, x;

 

But GLPK doesn't allow the "let" statement.  I believe that AMPL does.

 

So a workaround, that seems to work is:

 

param xx{i in 0..10} := if i=0 then n/2 else xx[i-1]/2 + n/(2*xx[i-1]);

 

printf "Sqrt of %f = %f\n", n, xx[10];

 

Again, the number of iterations is hardcoded, but hopefully you would be able to code the Newton's iteration exactly the above.

 

Lastly, because of the possibility of multiple solutions, you should start (the if i=0 then clause ) with a good first solution, mostly likely the interest rate you used for the NPV calculation.

 

-Marc

 

-----Original Message-----
From: help-glpk-bounces+address@hidden [mailto:help-glpk-bounces+address@hidden On Behalf Of Noli Sicad
Sent: Friday, September 14, 2012 11:27 AM
To: address@hidden
Subject: [Help-glpk] IRR (Internal Rate of Return) using MathProg

 

Hi,

 

I like to incorporate IRR (Internal Rate of Return) in my report (i.e.

Report Section of my LP GLPK/MathProg model). I don't how to do this using mathprog

 

Linux Journal has article in IRR and programs in Java, C and Perl. You can download the source here.

http://www.linuxjournal.com/article/2545

 

However, I have difficulties deciphering it.

 

Some discussions on various methods on how to calculate IRR.

http://finance.thinkanddone.com/irr.html

 

My LP model is maximizing Net Present Value (i.e. revenues / Cash flow). Here is example of the cash flow (below).

 

Anybody like to have a go with this problem?

 

Thanks in advance.

 

Noli

 

##########################

Period (Year)     Cash Flow ($)

1              39076.42996

2              21948.87949

3              21957.06148

4              21817.10073

5              22434.00213

6              25217.30759

7              28801.0362

8              33663.80729

9              39526.52516

10           47082.82071

11           52139.3562

12           55712.83969

13           54963.69578

14           54197.3533

15           53469.32228

16           52777.66322

17           52120.61624

18           51496.4058

19           50903.35207

20           50340.01419

21           49804.81457

22           49296.50083

23           48813.47914

24           48814.3007

25           48907.10984

26           49105.38398

27           49426.2852

28           49890.16458

29           50521.35707

30           51349.79884

31           52411.43084

32           53749.2502

33           54080.18986

34           53474.36278

35           53848.60448

36           54417.4497

37           55213.81919

38           56277.52781

39           57656.46566

40           57792.59562

41           56875.42409

42           57304.41377

43           56658.08866

44           55805.88753

45           55531.78289

 

_______________________________________________

Help-glpk mailing list

address@hidden

https://lists.gnu.org/mailman/listinfo/help-glpk



This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]