Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > sql server programming > july 2009 >

sql server programming : IRR calculation


Partha Mandayam
7/2/2004 12:15:30 PM
This link may help you

http://www.frick-cpa.com/tvom/TVOM_FV_Annuity.asp

Regards

Partha Mandayam
Software Consultant
Home page: http://partha.tripod.com


*** Sent via Devdex http://www.devdex.com ***
Partha Mandayam
7/2/2004 12:15:35 PM
Here's a more detailed article

http://www.intelligententerprise.com/print_article_flat.jhtml?article=/o
nline_only/celko/030303_1.jhtml

Regards

Partha Mandayam
Software Consultant
Home page: http://partha.tripod.com


*** Sent via Devdex http://www.devdex.com ***
Joe Celko
7/2/2004 3:24:40 PM
I did an article on NPV functions via table look-up in INTELLIGENT
ENTERPRISE and then showed how to use a query to get the IRR. The point
of the article was to demonstrate how to do table look-ups in SQL, not
how to get the best NPV values. At the end, I did a IRR with a MIN()
aggregate. The problem is that since NPV is a polynominal, you can have
more than one IRR.

I'd recommend getting a financial tool of some kind for this problem.
You get floating point errors, ugly iterations, etc.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Devdex http://www.devdex.com ***
Steve Kass
7/2/2004 4:28:32 PM
N,

I don't know how messy your income streams are, but I would expect
Newton's method not to require too many iterations. I doubt guessing is a
bad idea either. Here's a Newton's method solution, and you'll probably
have to adjust the present value calculation for whatever quirky rules there
are. Mine is based on simple interest and an assumption that each year has
365 days. You'll also want to add parameters to the function to select out
specific accounts or whatever, depending on what's in your table.

create table IncomeStream (
amt float,
d datetime
)
insert into IncomeStream values (-1000,'19980101')
insert into IncomeStream values (200,'19990101')
insert into IncomeStream values (200,'20000101')
insert into IncomeStream values (200,'20010101')
insert into IncomeStream values (200,'20020101')
insert into IncomeStream values (200,'20030101')
insert into IncomeStream values (200,'20040101')

go

create function irr(
@d datetime
) returns decimal(18,10) as begin
declare @irrPrev float set @irrPrev = 0
declare @irr float set @irr = 0.1
declare @pvPrev float
declare @pv float
set @pvPrev = (
select sum(amt)
from IncomeStream
)
set @pv = (
select sum(amt/power(1e0+@irr,cast(d-@d as float)/360e0))
from IncomeStream
)
while abs(@pv) >= 0.0001 begin
declare @t float
set @t = @irrPrev
set @irrPrev = @irr
set @irr = @irr + (@t-@irr)*@pv/(@pv-@pvPrev)
set @pvPrev = @pv
set @pv = (
select sum(amt/power(1e0+@irr,cast(d-@d as float)/365e0))
from IncomeStream
)
end
return @irr
end
go
select dbo.irr('19980101')

go

drop function irr
drop table IncomeStream
go

Steve Kass
Drew University
[quoted text, click to view]

Steve Kass
7/2/2004 7:06:49 PM
For income streams that start with payments and end with revenues (or
vice versa), Descartes's rule of signs guarantees that the IRR exists
and is unique. Newton's method is a reliable method for finding it in
such cases, but for messier income streams, the problem is, well, messier.

SK

[quoted text, click to view]
N
7/2/2004 8:44:21 PM
Hi guys

Has anyone here had any experience with internal rate of return
(IRR)calculations on SQL Server. We have an asset management system where a
client invests money and then makes transactions over a period of time. We
need to calculation an IRR value for inception, year and quarter data. This
IRR is an exceptionally iterative calc and i just wanted to know if anyone
has had experience with this?

At the moment we do not follow the strict formula for calculating the IRR as
this is too iterative and we use a guessing system based on the transactions
in the period concerned.

Thanks
N

N
7/5/2004 10:33:52 AM
Thanks guys. I appreciate the input!

[quoted text, click to view]

MD
7/2/2009 4:35:56 AM
Hi Guys,

I got the same problem like N.

Please do post if there is any Sql server program or somthing to calculate XIRR.

Thanks
MD

From http://www.developmentnow.com/g/113_2004_7_0_0_429699/IRR-calculation.htm

Posted via DevelopmentNow.com Groups
Charlie
9/4/2009 4:45:35 AM
You can find IRR, XIRR, and a library of other SQL CLR financial functions in a package called XLeratorDB which is at www.westclintech.com

From http://www.developmentnow.com/g/113_2004_7_0_0_429699/IRR-calculation.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button