Showing posts with label financial. Show all posts
Showing posts with label financial. Show all posts

Friday, February 24, 2012

financial year

how can you store a financial year in sql 2005

wt do you mean by that? can u explain it further so that we can get the exact idea wt u wanna do?|||

What i ment is that when a person selects a date how do you set another column just to show the financial year....

EG:

column 1 = '09/09/2004'

column 2(financial Year) = '2005'

what i have done is that i have created a case satement that selects the correct date

THANKS

|||

You can do it in a select statement:

SELECT tDate, CASE WHEN MONTH(tDate)>6 then YEAR(tDate)+1

ELSE YEAR(tDate) END AS FYear

FROM Dates

Or you can save the value in a new column such as a INT column through an update statement:

UPDATE Dates

SET fYear = CASE WHEN MONTH(tDate)>6 then YEAR(tDate)+1

ELSE YEAR(tDate) END

|||

I would absolutely suggest a calendar table like this for your translation needs. You calculate it once, store it away and then reference it. Here is an article (with code) I wrote on how to load a calendar table, including columns for fiscal_year and month:

A way to load a calendar table
http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1349.entry

It also has several references to other articles.

financial year

how can you store a financial year in sql 2005

wt do you mean by that? can u explain it further so that we can get the exact idea wt u wanna do?|||

What i ment is that when a person selects a date how do you set another column just to show the financial year....

EG:

column 1 = '09/09/2004'

column 2(financial Year) = '2005'

what i have done is that i have created a case satement that selects the correct date

THANKS

|||

You can do it in a select statement:

SELECT tDate, CASE WHEN MONTH(tDate)>6 then YEAR(tDate)+1

ELSE YEAR(tDate) END AS FYear

FROM Dates

Or you can save the value in a new column such as a INT column through an update statement:

UPDATE Dates

SET fYear = CASE WHEN MONTH(tDate)>6 then YEAR(tDate)+1

ELSE YEAR(tDate) END

|||

I would absolutely suggest a calendar table like this for your translation needs. You calculate it once, store it away and then reference it. Here is an article (with code) I wrote on how to load a calendar table, including columns for fiscal_year and month:

A way to load a calendar table
http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1349.entry

It also has several references to other articles.

Financial Year

Hi,
one of the important things in accounting systems is using financial
year. whenever the year changes, they change the financial year and
use the new one. some times they need to reference the previous
financial year accounts.
I would like to to know what is the best approach to store these case
in sql server?
I thought of an approach which we store a field for Financial year for
each table which needs it. and when querying we use the default
Financial Year. Well, might it be very time consuming when the size of
the database grows very much?
I mean does it take a lot of time to find the financial year we want
through lots of other financial year information.
Or are there any better methods and solution to do so in SQL Server
2005?
Thank you very much
Ali"Ali" <nikzad.a@.gmail.com> wrote in message
news:1189316098.187434.283920@.57g2000hsv.googlegroups.com...
> Hi,
> one of the important things in accounting systems is using financial
> year. whenever the year changes, they change the financial year and
> use the new one. some times they need to reference the previous
> financial year accounts.
> I would like to to know what is the best approach to store these case
> in sql server?
> I thought of an approach which we store a field for Financial year for
> each table which needs it. and when querying we use the default
> Financial Year. Well, might it be very time consuming when the size of
> the database grows very much?
> I mean does it take a lot of time to find the financial year we want
> through lots of other financial year information.
> Or are there any better methods and solution to do so in SQL Server
> 2005?
> Thank you very much
> Ali
>
Create a Calendar table:
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html
--
David Portas|||You can use Partitioning for your database for this purpose in case your SQL
Server version is 2005 and edition Enterprise.
Using partitioning, you will be able to save all different years in
different files. It will be more managable and faster. You may keep the old
and rarely used partitions (files of them) to slower disks relatively to the
recent and more used partitions (files of them).
You can find more information about partitioning in the following page:
Understand Partitioning:
http://msdn2.microsoft.com/en-us/library/ms188232.aspx
Ekrem Önsoy
"Ali" <nikzad.a@.gmail.com> wrote in message
news:1189316098.187434.283920@.57g2000hsv.googlegroups.com...
> Hi,
> one of the important things in accounting systems is using financial
> year. whenever the year changes, they change the financial year and
> use the new one. some times they need to reference the previous
> financial year accounts.
> I would like to to know what is the best approach to store these case
> in sql server?
> I thought of an approach which we store a field for Financial year for
> each table which needs it. and when querying we use the default
> Financial Year. Well, might it be very time consuming when the size of
> the database grows very much?
> I mean does it take a lot of time to find the financial year we want
> through lots of other financial year information.
> Or are there any better methods and solution to do so in SQL Server
> 2005?
> Thank you very much
> Ali
>

Financial Query Help

I am in need of a query that would calculate the balance as of a certain
date, say 12/31/2005 for AccountID = 1.
Current Balance = 100
Balance as of 12/31/05 should be 200.
But how do I write a query like this?
Thanks
Sonny
tblAccount - Shows current balances
ID--Balance--AccountName
1 -- 100 -- Test1
2 -- 200 -- Test2
3 -- 200 -- Test3
tblAccountHistory - Show transactions
ID--AccountID--TransDate--Amount--Action
1 -- 1 -- 12/1/2005 -- 500 -- Credit
1 -- 1 -- 12/5/2005 -- 100 -- Debit
1 -- 1 -- 12/10/2005 -- 100 -- Debit
1 -- 1 -- 12/15/2005 -- 100 -- Debit
1 -- 1 -- 1/5/2006 -- 100 -- DebitSonny
Can you post sample data?
SELECT Current Balance *2 FROM Table WHERE AccountID = 1
"Sonny Sablan" <sonny@.sablan.org> wrote in message
news:ODbjNxnQGHA.2536@.tk2msftngp13.phx.gbl...
>I am in need of a query that would calculate the balance as of a certain
>date, say 12/31/2005 for AccountID = 1.
> Current Balance = 100
> Balance as of 12/31/05 should be 200.
> But how do I write a query like this?
> Thanks
> Sonny
>
> tblAccount - Shows current balances
> ID--Balance--AccountName
> 1 -- 100 -- Test1
> 2 -- 200 -- Test2
> 3 -- 200 -- Test3
>
> tblAccountHistory - Show transactions
> ID--AccountID--TransDate--Amount--Action
> 1 -- 1 -- 12/1/2005 -- 500 -- Credit
> 1 -- 1 -- 12/5/2005 -- 100 -- Debit
> 1 -- 1 -- 12/10/2005 -- 100 -- Debit
> 1 -- 1 -- 12/15/2005 -- 100 -- Debit
> 1 -- 1 -- 1/5/2006 -- 100 -- Debit
>
>|||There is sample data...
After my question.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:OUERjZoQGHA.4952@.TK2MSFTNGP09.phx.gbl...
> Sonny
> Can you post sample data?
> SELECT Current Balance *2 FROM Table WHERE AccountID = 1
>
>
>
> "Sonny Sablan" <sonny@.sablan.org> wrote in message
> news:ODbjNxnQGHA.2536@.tk2msftngp13.phx.gbl...
>|||he did. ;-)
select AccountID, sum(Amount*(case Action when 'Credit' then 1 when 'Debit'
then -1 else 0 end)) [total]
from tbAccountHistory
where AccountID=1 and TransDate <= '20051231'
group by AccountID
-oj
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:OUERjZoQGHA.4952@.TK2MSFTNGP09.phx.gbl...
> Sonny
> Can you post sample data?
> SELECT Current Balance *2 FROM Table WHERE AccountID = 1
>
>
>
> "Sonny Sablan" <sonny@.sablan.org> wrote in message
> news:ODbjNxnQGHA.2536@.tk2msftngp13.phx.gbl...
>|||Thanks oj...
Sonny
"oj" <nospam_ojngo@.home.com> wrote in message
news:u6heUeoQGHA.4960@.TK2MSFTNGP12.phx.gbl...
> he did. ;-)
> select AccountID, sum(Amount*(case Action when 'Credit' then 1 when
> 'Debit' then -1 else 0 end)) [total]
> from tbAccountHistory
> where AccountID=1 and TransDate <= '20051231'
> group by AccountID
> --
> -oj
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:OUERjZoQGHA.4952@.TK2MSFTNGP09.phx.gbl...
>|||Thanks, I really need a cofee.
"oj" <nospam_ojngo@.home.com> wrote in message
news:u6heUeoQGHA.4960@.TK2MSFTNGP12.phx.gbl...
> he did. ;-)
> select AccountID, sum(Amount*(case Action when 'Credit' then 1 when
> 'Debit' then -1 else 0 end)) [total]
> from tbAccountHistory
> where AccountID=1 and TransDate <= '20051231'
> group by AccountID
> --
> -oj
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:OUERjZoQGHA.4952@.TK2MSFTNGP09.phx.gbl...
>

Financial Periods YTD & Date Ranges

I am developing a set of reports for a site based on AS2000.

The reports will have columns for each finance period in the current year from period 01 to the current reporting period from the Primary Time dimension.

i.e. If period 4 is the default period, The report should show columns for periods 1,2,3,4 with a total that sums the four columns.

When the default period 5 the columns should be 1,2,3,4,5.

I cannot use the current year and explode that to show all periods in the year, as there are postings in future periods beyond the current accounting period that should not be displayed on the report.

I am setting the default member of the time dimension to the current reporting period. (2005/08 for example)
I am trying to use a named set based on an MDX expression to set the column range for the report.

The first test I tried was to set the MDX for the period range to some fixed values
{[Primary Time].[ACCSCAL].&[200501]:[Primary Time].[ACCSCAL].&[200508]}
This gave the expected result showing columns 01/2005 to 08/2005

I then tried changing the last period to use the default member of the dimension
{[Primary Time].[ACCSCAL].&[200501]:[Primary Time].[ACCSCAL].DefaultMember}
This again gave the expected result range and I could change the default member on the dimension and see the columns on the report update correctly.

I then tried testing that the first period can be found correctly
{[Primary Time].[ACCSCAL].&[200508].FirstSibling:[Primary Time].[ACCSCAL].&[200508]}
This again gave the expected result range from 01/2005 to 08/2005

I then tried combining the default member and first sibling calculations
{[Primary Time].[ACCSCAL].DefaultMember.FirstSibling:[Primary Time].[ACCSCAL].DefaultMember}
This gave a single column "All Primary Time", this was not what I was expecting.

So I tried changing the mdx to test the value of the first sibling of the default member, expecting 01/2005
{[Primary Time].[ACCSCAL].DefaultMember.FirstSibling}
This again gave a single column "All Primary Time".

So I then tried changing the mdx to test that a single period would work in the named set
{[Primary Time].[ACCSCAL].DefaultMember}
This again gave a single column "All Primary Time".

So I tried changing the mdx to test the value of the default member, expecting 08/2005
{[Primary Time].[ACCSCAL].&[200508]}
This again gave a single column for 08/2005 as expected

By now this has me totally confused!

Do you have any idea why the default member works when used as the second part of the range but does not work when used on its own or as the first element of the range?

Is this the correct way of achieving the report I am aiming for or is there a better method to use?

Any suggestions you have would be welcome.

Apologies is this is a FAQ.

What is the actual MDX expression for the Default Member of [Primary Time].[ACCSCAL]?|||The Default Member is [Primary Time].[ACCSCAL].&[200508]

Financial functions for SQL Server

Hi everybody,

Does anyone have financial functions to be run in SQL Server 2000? For example, future value, interest rate, payments, and so on. Or where can I find them on Internet?

Thanks in advance

Jaime

Here might be a good place to start?
http://www.google.se/search?hl=sv&q=future+value%2C+interest+rate%2C+payments+function+%2BSQL+Server&meta=

/Kenneth

|||

No so good...

I have found some commercial libraries but none (free) that lists all financial functions. At least, I have found future value implementation. That's why I asked if someone has already a list of functions ready to use.

Jaime

Financial function

Hello,

I seek a solution for the cacule of YIELD TO MATURITY of the bonds. In Excel av YIELD() but SQL server ?

Do you have an idea?

Thank you

I do not know the exact logic of the function but you should be able to code the same in a UDF or procedure in SQL Server. In SQL Server 2005, you can implement the same using C#/VB.NET function/procedure. Alternatively, you can invoke the Excel function via OLE automation or pass-through query provided you have to data in a Excel sheet. This approach however is not that pretty and probably overkill.

Anyway, what is the reason for trying to implement the function in SQL Server? You can get the data from SQL Server into Excel easily and perform the computation there. You can then persist results back to the database if you want to. And you can automate this whole process using say DTS or SSIS package for example.

|||SET NOCOUNT ON
CREATE TABLE Cash_Flows
(
cashflow DECIMAL(8,2),
valuta DATETIME
)
INSERT INTO Cash_Flows VALUES (-95.92,'20060115')
INSERT INTO Cash_Flows VALUES (5,'20070115')
INSERT INTO Cash_Flows VALUES (5,'20080115')
INSERT INTO Cash_Flows VALUES (5,'20090115')
INSERT INTO Cash_Flows VALUES (105,'20100115')

GO

CREATE FUNCTION yield_to_maturity(@.issue_date SMALLDATETIME)
RETURNS DECIMAL(15,14)
AS BEGIN
DECLARE @.ytm_tmp FLOAT
DECLARE @.ytm FLOAT
DECLARE @.pv_tmp FLOAT
DECLARE @.pv FLOAT

SET @.ytm_tmp = 0
SET @.ytm = 0.1
SELECT @.pv_tmp = SUM(cashflow) FROM Cash_Flows
SET @.pv = (SELECT SUM(cashflow/POWER(1.0+@.ytm,(DATEDIFF(month,@.issue_date, valuta)* 30 + DAY(valuta)-DAY(@.issue_date)
- CASE WHEN(@.issue_date)>=30 AND DAY(valuta) = 31 THEN 1 ELSE 0 END )/
360.0 )) FROM Cash_Flows)

WHILE ABS(@.pv) >= 0.000001
BEGIN
DECLARE @.t FLOAT
SET @.t = @.ytm_tmp
SET @.ytm_tmp = @.ytm
SET @.ytm = @.ytm + (@.t-@.ytm)*@.pv/(@.pv-@.pv_tmp)
SET @.pv_tmp = @.pv
SET @.pv = (SELECT SUM(cashflow/POWER(1.0+@.ytm,(DATEDIFF(month,@.issue_date, valuta) * 30 + DAY(valuta)-DAY(@.issue_date)
- CASE WHEN(@.issue_date)>=30 AND DAY(valuta) = 31 THEN 1 ELSE 0 END
) /360.0))
FROM Cash_Flows)
END
RETURN @.ytm
END
GO

SELECT dbo.yield_to_maturity('20060115')
DROP FUNCTION yield_to_maturity
DROP TABLE Cash_Flows
GO
SET NOCOUNT OFF

The fundamental principle of every asset valuation is that the fair value of an asset equals the present value of its cash flows. So, every asset valuation consists more or less of these three steps.
1. Estimate the expected cash flows
2. Determine one or more appropriate discount rates, that you will use to discount the cash flows
3. Calculate Present Value of 1. using 2.

While this is a nice exercise, the above covers only the most basic cases. You can only calculate plain vanilla bonds without embedded derivatives with that formula. Also, it doesn't take into account common day conventions like ISMA 251 or money market conventions. The formula rather uses a simple 30/360 day convention, which nowadays isn't common anymore in Europe. You would need to extend that on your own.
Calculating the YTM is an iterative process while not really is what SQL Server excels at. Like UC said, you would rather do this in a spreadsheet application with a specialised Add-In or some other front-end language|||Isn't the sigature automatically inserted anymore?
--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt? http://www.insidesql.de/blogs

Financial Accounting Cube

Hi,

I'm designing a cube for analyzing financial data from an accounting application.

Basically, the facts table looks like:

(idAccount, idTime, nValue)

that shows every financial operation for any account, and it's very easy to build a cube for analysing the accounting movements.

But there is another important measure, that's the balance of every account in any time.

A tipical report would be, for a whole year, the sum of movements of any account and the balance at the end of the period.

I think adding a new column to the facts table like:

(idAccount, idTime, nValue, nBalance)

wouldn't work, because any account has a balance in any time, even thought there isn't movements in that time period.

What do you think would be a good design approach?

Why not break it into two (Seems like they are unrelated facts that happen to have common dimensions):

idAccount, idTime, nValue

idAccount, idTime, nBalance

|||

Could work, but with that approach I would have a row in the fact table for every day and for every account, and that doesn't look very efficient.

Imagine a "sales" account, that has a balance value in day 10 of 10,000$, and there are more sales after that day:

(idAccount="sales", idTime=10, nBalance=10000)

(idAccount="sales", idTime=15,nValue=500)

so, (idAccount="sales", idTime=15, nBalance=10500)

That means, the balance value changes after any accounting operation.

And now, what happens if the user makes a report that has a row for every account with two more columns: nBalance and nValue, and chooses only the day 20?

For the "sales" account nValue = 0, that's clear, but, what happens with nBalance?

It should be 10500, becuase the balance didn't change after the day 15.

The problem is that I don't know how to create the nBalance measure in order to get that behaviour.

The only way I can figure out is filling the (idAccount, idTIme, nBalance) table with the balance of every account for every day, and that seems to be a waste of resources, because there're many accounts that have very few changes in their balance over the year.

Any suggestion?

P.S. Another problem is the calculation of aggregations for nBalance. Aggregations for nBalance in the account dimension must be a sum of nBalance for any account. But for time dimension, nBalance is the value of nBalance in the last time of the time dimension.

I can figure out many "real wolrd" problems similar to this. For example, imagine that you have a solution for identifying the stock in a warehouse. There are, at least, two main measures: the ins and outs of the warehouse and the actual stock in a certain value of time.

Sunday, February 19, 2012

Finacial function

I'm looking for financial function in T/SQL.
I need to implement the Rate-Function like in VBA.
Thanks
EricEric,
Here is a shot at it. It's probably much less reliable than the VBA
function,
but maybe you can tweak it some. Note I define a pv function also, since
rate() is iterated to be a good pv() predictor.
create function pv (
@.rate decimal(10,9),
@.nper int,
@.pmt decimal(18,4),
@.fv decimal(18,4),
@.type int
) returns decimal(18,4) as begin
return
(-@.fv -
@.pmt*(1+@.rate*@.type)*(power(1+@.rate,@.npe
r)-1)/@.rate)/power(1+@.rate,@.nper)
end
go
create function rate (
@.nper int,
@.pmt decimal(18,4),
@.pv decimal(18,4),
@.fv decimal(18,4) = 0.0,
@.type int = 0,
@.guess float = 0.1
) returns decimal(10,9) as begin
declare @.guesspv decimal(18,4)
declare @.nextguesspv decimal(18,4)
set @.guesspv = dbo.pv(@.guess, @.nper, @.pmt, @.fv, @.type)
declare @.error decimal(18,17)
declare @.nextguess float
set @.error = abs(log(@.guesspv/@.pv))
set @.nextguess = @.guess+@.error*@.guess
set @.nextguesspv = dbo.pv(@.nextguess, @.nper, @.pmt, @.fv, @.type)
declare @.tries int set @.tries = 20
while @.error > 0.000001 begin
if @.tries = 0 return null
set @.guess = @.guess +
(@.pv-@.guesspv)/(@.nextguesspv-@.guesspv)*(@.nextguess-@.guess)
set @.guesspv = dbo.pv(@.guess, @.nper, @.pmt, @.fv, @.type)
set @.error = abs(log(@.guesspv/@.pv))
set @.nextguess = @.guess+@.error*@.guess
set @.nextguesspv = dbo.pv(@.nextguess, @.nper, @.pmt, @.fv, @.type)
set @.tries = @.tries - 1
end
return @.guess
end
go
select dbo.rate(10*1, -1000, 6500, default, default, default)
go
drop function rate, pv
-- Steve Kass
-- Drew University
-- A32884BB-911C-472A-90F2-C72346B90995
Eric wrote:

>I'm looking for financial function in T/SQL.
>I need to implement the Rate-Function like in VBA.
>Thanks
>Eric
>
>|||One option is to create a VB6 class that has methods that implement the
requisite financial functions (perhaps calling VBA financial functions). You
then call your financial functions from TSQL by using the extended stored
procedures sp_OACreate, sp_OAMethod, and sp_OADestroy.
Here's what you'd need to do:
1. Compile your VB6 class into a DLL. You better have good error handling in
it otherwise you risk crashing your SQL Server.
2. Place that DLL into the WIN32 directory on your SQL Server, and REGISTER
it on your SQL Server by using RegSvr32.exe
3. Call methods of your VB6 class/dll from any stored procedure, using
something like the following (some of the names have been changed to protect
the innocent):
BEGIN
blah blah blah
DECLARE @.Object int -- holds a reference to your object instantiated
from the vb6 class.
-- Set a string equal to your entire method call - including any
parameter values.
SET @.MethodToCall = 'CalculatePayment(' + @.RatePercent + ', ' +
@.RateIncrease + ', ' + @.Months + ', ' + @.Fees + ')'
--Instantiate an instance of VB6 class and put it's reference in
@.object
EXEC sp_OACreate 'Your_VB_DLL.ClassName, @.object OUT
--Run the financial function (e.g., CalculatePayment method) of your
class - and place it's output into @.Return
EXEC sp_OAMethod @.object, @.MethodToCall, @.return OUT
-- Destroy the instance of our DataConversion class now that we're
done with it.
EXEC sp_OADestroy @.object
blah blah blah
END
4. Any time you upgrade your VB6 DLL, be sure to Unregister the old one
(using RegSvr32.exe... -U), then replace the old DLL with the new one, and
then register the new one like in step 2 above. No need to restart your SQL
Server.
-HTH
"Eric" <jug@.nospam.nospam> wrote in message
news:u0QX3AabFHA.724@.TK2MSFTNGP12.phx.gbl...
> I'm looking for financial function in T/SQL.
> I need to implement the Rate-Function like in VBA.
> Thanks
> Eric
>|||Steve, Do you also have a similar function to calculate the Pmt amount?
========================================
======================
quote:
Originally posted by Steve Kass
Eric,
Here is a shot at it. It's probably much less reliable than the VBA
function,
but maybe you can tweak it some. Note I define a pv function also, since
rate() is iterated to be a good pv() predictor.
create function pv (
@.rate decimal(10,9),
@.nper int,
@.pmt decimal(18,4),
@.fv decimal(18,4),
@.type int
) returns decimal(18,4) as begin
return
(-@.fv -
@.pmt*(1+@.rate*@.type)*(power(1+@.rate,@.npe
r)-1)/@.rate)/power(1+@.rate,@.nper)
end
go
create function rate (
@.nper int,
@.pmt decimal(18,4),
@.pv decimal(18,4),
@.fv decimal(18,4) = 0.0,
@.type int = 0,
@.guess float = 0.1
) returns decimal(10,9) as begin
declare @.guesspv decimal(18,4)
declare @.nextguesspv decimal(18,4)
set @.guesspv = dbo.pv(@.guess, @.nper, @.pmt, @.fv, @.type)
declare @.error decimal(18,17)
declare @.nextguess float
set @.error = abs(log(@.guesspv/@.pv))
set @.nextguess = @.guess+@.error*@.guess
set @.nextguesspv = dbo.pv(@.nextguess, @.nper, @.pmt, @.fv, @.type)
declare @.tries int set @.tries = 20
while @.error > 0.000001 begin
if @.tries = 0 return null
set @.guess = @.guess +
(@.pv-@.guesspv)/(@.nextguesspv-@.guesspv)*(@.nextguess-@.guess)
set @.guesspv = dbo.pv(@.guess, @.nper, @.pmt, @.fv, @.type)
set @.error = abs(log(@.guesspv/@.pv))
set @.nextguess = @.guess+@.error*@.guess
set @.nextguesspv = dbo.pv(@.nextguess, @.nper, @.pmt, @.fv, @.type)
set @.tries = @.tries - 1
end
return @.guess
end
go
select dbo.rate(10*1, -1000, 6500, default, default, default)
go
drop function rate, pv
-- Steve Kass
-- Drew University
-- A32884BB-911C-472A-90F2-C72346B90995
Eric wrote:

>I'm looking for financial function in T/SQL.
>I need to implement the Rate-Function like in VBA.
>Thanks
>Eric
>
>