Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Time series data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-09-11 : 13:57:51
Ron Light writes "This question deals with time series data. Here are my tables:

Prices
--------
Date
Ticker
Price

Weight
----------
WeightID
Value

The table “Prices” simply contains each business days closing quote for a given stock. The goal is to get a 20 day weighted moving average.
In the weight table you might see this:
WeightID Value
------------------
1 .1
2 .08
3 .07

...

20 .001

The values in “Weight” always add up to 1.
First get the previous 20 days price multiplied by the respective weight value then add up those 20 days to get the weighted moving average.

I was really trying to do this with SQL, I may give in and use a stored procedure."

nr
SQLTeam MVY

12543 Posts

Posted - 2002-09-12 : 04:32:29
select sum(Price * Value)
from Prices, Weight
where Date = dateadd(dd,WeightID * -1, convert(varchar(8),getdate(),112)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -