comp.lang.ada
 help / color / mirror / Atom feed
* Ada routine to compute Internal Rate Of Return
@ 1998-12-09  0:00 Marin David Condic
  1998-12-09  0:00 ` Tom Moran
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Marin David Condic @ 1998-12-09  0:00 UTC (permalink / raw)


Does anybody have an Ada function to compute Internal Rate of Return
(IRR)? I've got a Net Present Value (NPV) function that takes an array
of cash flows & and interest rate. I could build something that tries to
converge this on zero, which would result in IRR, but I'm not sure about
developing an algorithm that will converge quickly. If someone has
solved this problem in Ada, I'd appreciate seeing some source code.
Thanks.

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669

"Transported to a surreal landscape, a young girl kills the first woman
she meets and then teams up with three complete strangers to kill
again."

        -- TV listing for the Wizard of Oz




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-09  0:00 Ada routine to compute Internal Rate Of Return Marin David Condic
@ 1998-12-09  0:00 ` Tom Moran
  1998-12-10  0:00   ` Marin David Condic
  1998-12-10  0:00 ` Michael F Brenner
  1998-12-12  0:00 ` Al Christians
  2 siblings, 1 reply; 8+ messages in thread
From: Tom Moran @ 1998-12-09  0:00 UTC (permalink / raw)


Do you have a polynomial zero finder about?
As for speed, for realistic projects you can probably make a pretty
good initial guess, and for the real world your coefficients are such
guesses that it's not worth computing to much accuracy.
(And NPV is a better indicator than IRR anyway.)




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-09  0:00 ` Tom Moran
@ 1998-12-10  0:00   ` Marin David Condic
  1998-12-10  0:00     ` Tom Moran
  0 siblings, 1 reply; 8+ messages in thread
From: Marin David Condic @ 1998-12-10  0:00 UTC (permalink / raw)


Tom Moran wrote:
> 
> Do you have a polynomial zero finder about?
> As for speed, for realistic projects you can probably make a pretty
> good initial guess, and for the real world your coefficients are such
> guesses that it's not worth computing to much accuracy.
> (And NPV is a better indicator than IRR anyway.)

No I do not have a polynomial zero finder. Got one of those lying around
on the workbench somewhere? Probably right next to stud finder if your
workbench is well organized.

Speed is not usually much of a concern for this sort of thing since you
typically only need to calculate it once for a given set of
wild-ass-guesses about future cash flows. However, one wouldn't want to
be grotesque about it either - just on principal if not because of
unknown future uses.

Yes, yes, yes, yes. NPV is a better indicator. But there are a lot of
senior bozos who have gotten used to IRR and want to see that number
too. It can be kind of handy in capital budgeting decisions. And yes,
IRR can be both misleading and misinterpreted, but you kind of have to
spit it out anyway - so I need a routine to do it. I'm also aware that
the precision of a computed IRR far exceeds the precision of the
rectally-extracted numbers on which it is based. But as an exercise in
Computer Science, we could have some fun computing it to the precision
of a Long_Long_Float, couldn't we?

And while I'm out begging for someone to solve my problems for me, how
about a routine to compute Modified Internal Rate Of Return? ;-)

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669
***To reply, remove "bogon" from the domain name.***

"Transported to a surreal landscape, a young girl kills the first woman
she meets and then teams up with three complete strangers to kill
again."

        -- TV listing for the Wizard of Oz




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-10  0:00   ` Marin David Condic
@ 1998-12-10  0:00     ` Tom Moran
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Moran @ 1998-12-10  0:00 UTC (permalink / raw)


I e-mailed a little IRR routine that uses a simple bisection search.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-09  0:00 Ada routine to compute Internal Rate Of Return Marin David Condic
  1998-12-09  0:00 ` Tom Moran
@ 1998-12-10  0:00 ` Michael F Brenner
  1998-12-10  0:00   ` Marin David Condic
  1998-12-11  0:00   ` dennison
  1998-12-12  0:00 ` Al Christians
  2 siblings, 2 replies; 8+ messages in thread
From: Michael F Brenner @ 1998-12-10  0:00 UTC (permalink / raw)


While Ada is a cool language, it is interesting to note that
two of the spreadsheets I have on my computers have an IRR function.

One of these spreadsheets should be accessible through the
recently posted COM interface, so one way to do it in Ada might be
to use Ada through COM to ask the spreadsheet to do it for you, if
that COM interface can handle this.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-10  0:00 ` Michael F Brenner
@ 1998-12-10  0:00   ` Marin David Condic
  1998-12-11  0:00   ` dennison
  1 sibling, 0 replies; 8+ messages in thread
From: Marin David Condic @ 1998-12-10  0:00 UTC (permalink / raw)


Michael F Brenner wrote:
> 
> While Ada is a cool language, it is interesting to note that
> two of the spreadsheets I have on my computers have an IRR function.
> 
> One of these spreadsheets should be accessible through the
> recently posted COM interface, so one way to do it in Ada might be
> to use Ada through COM to ask the spreadsheet to do it for you, if
> that COM interface can handle this.

Well, if all I wanted was an answer, this would work. But then, most of
these business calculations are possible to get out of a spreadsheet -
why bother to write Ada at all? One part is intellectual exercise. The
remaining part is the need to develop some code where I don't know what
the ultimate target will be. (I don't want it to depend on someone
else's software) I'm using it in connection with a class I'm doing in
Finance & want to try simulating something that needs this calculation.
If what I'm doing works, I want to be able to pass the code around and
don't want to have it limited to only PC's with Excel (or whatever)
installed.

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669
***To reply, remove "bogon" from the domain name.***

"Transported to a surreal landscape, a young girl kills the first woman
she meets and then teams up with three complete strangers to kill
again."

        -- TV listing for the Wizard of Oz




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-10  0:00 ` Michael F Brenner
  1998-12-10  0:00   ` Marin David Condic
@ 1998-12-11  0:00   ` dennison
  1 sibling, 0 replies; 8+ messages in thread
From: dennison @ 1998-12-11  0:00 UTC (permalink / raw)


In article <74pgv2$94b@top.mitre.org>,
  mfb@mbunix.mitre.org (Michael F Brenner) wrote:
> While Ada is a cool language, it is interesting to note that
> two of the spreadsheets I have on my computers have an IRR function.
>
> One of these spreadsheets should be accessible through the
> recently posted COM interface, so one way to do it in Ada might be
> to use Ada through COM to ask the spreadsheet to do it for you, if
> that COM interface can handle this.

For that matter, most Windows spreadsheets support DDE. There should be DDE
bindings in any self-respecting Win32 bindings.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada routine to compute Internal Rate Of Return
  1998-12-09  0:00 Ada routine to compute Internal Rate Of Return Marin David Condic
  1998-12-09  0:00 ` Tom Moran
  1998-12-10  0:00 ` Michael F Brenner
@ 1998-12-12  0:00 ` Al Christians
  2 siblings, 0 replies; 8+ messages in thread
From: Al Christians @ 1998-12-12  0:00 UTC (permalink / raw)


Marin David Condic wrote:
> 
> Does anybody have an Ada function to compute Internal Rate of Return
> (IRR)? I've got a Net Present Value (NPV) function that takes an array
> of cash flows & and interest rate. I could build something that tries to
> converge this on zero, which would result in IRR, but I'm not sure about
> developing an algorithm that will converge quickly. If someone has
> solved this problem in Ada, I'd appreciate seeing some source code.
> Thanks.
> 

Here's my code to do the inverse interpolation:

-------------------------------------------------------------------



   function Interpolate_R_of_R( Profit: 
Profit_Types.Profit_Element_Vector;
				-- rr0 & rr1 are 1st 2  guesses at
				-- rate of return
                                rr0, rr1:   Long_Float;
                                last_item:  Natural := 0 ) return
Long_Float is
   pv0, pv1, pv2, r2:  Long_Float;
   r0:  Long_Float := rr0;
   r1:  Long_Float := rr1;
   begin
      -- calculate present values. 	
      pv0 := pv( Profit, r0, last_item );
      pv1 := pv( Profit, r1, last_item );
      for i in 1 .. 100 loop
         exit when abs ( r0 - r1 ) < 0.000000001;
         if pv0 * pv1 >= 0.0 then
            Ada.Text_IO.Put_Line( "Error -- Rate of Return not Found" );
            exit;
	 end if;		
         r2  :=  ( r0 * pv1 - r1 * pv0 ) / ( pv1 - pv0 );
         pv2 :=  pv( Profit, r2, last_item );
         if  pv0 * pv2 > 0.0 then
            pv0 := pv2;
            r0  := r2;
         else
            pv1 := pv2;
            r1  := r2;
         end if;
      end loop;
      if  abs pv0 < abs pv1 then
         return r0;
      else
         return r1;
      end if;
   exception
      when others =>
         Ada.Text_IO.Put_Line( "Error Interpolating R of R" );
         raise;
   end;

---------------------------------------------------------------------

The code not shown, for example determining if there are any real
roots and finding the initial range may be harder.  This algorithm
will usually converge quickly.  For something more advanced, see
Brent's and Muller's methods in the Numerical Recipes book.

Al




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1998-12-12  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-09  0:00 Ada routine to compute Internal Rate Of Return Marin David Condic
1998-12-09  0:00 ` Tom Moran
1998-12-10  0:00   ` Marin David Condic
1998-12-10  0:00     ` Tom Moran
1998-12-10  0:00 ` Michael F Brenner
1998-12-10  0:00   ` Marin David Condic
1998-12-11  0:00   ` dennison
1998-12-12  0:00 ` Al Christians

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox