my problem is that I have some data that is quarterly but needs be recalculated daily using another daily value. Basically, I am working with quarterly financial data but I need to recalculate some of the ratios for a daily frequency using daily price data. In this case below, I am given a value for c.atq and c.csh12q quarterly and a value for s1.prccd daily. I need to calculate the ratio for the current c.atq using the current s1.prccd. When the the c.atq changes at the end of the quarter, the process should continue with the new value.
select s1.DATADATE, c.ATQ, s1.PRCCD, c.ATQ/(s1.PRCCD*c.CSH12Q) as PATQ
from sec_dprc s1
left outer join co_ifndq c
on s1.GVKEY = c.GVKEY
and s1.DATADATE = c.DATADATE
where s1.GVKEY = 008068
order by s1.DATADATE
this is small table of the results:
DATADATE ATQ PRCCD PATQ
19/12/1984 00:00 NULL 28 NULL
20/12/1984 00:00 NULL 27.25 NULL
21/12/1984 00:00 NULL 27.5 NULL
24/12/1984 00:00 NULL 27.5 NULL
26/12/1984 00:00 NULL 27.5 NULL
27/12/1984 00:00 NULL 27.625 NULL
28/12/1984 00:00 NULL 27.75 NULL
31/12/1984 00:00 12273 28 4.400022371
02/01/1985 00:00 NULL 27.5 NULL
03/01/1985 00:00 NULL 26.75 NULL
04/01/1985 00:00 NULL 25 NULL
07/01/1985 00:00 NULL 24 NULL
08/01/1985 00:00 NULL 25 NULL
09/01/1985 00:00 NULL 25.375 NULL
I need the value of c.ATQ to be duplicated over all the following daily dates until it changes next quarter.
Thanks!!
part 2:
GVKEY rankx rdq QTR ATQ CSH12Q DATADATE
008068 2 1984-02-03 00:00:00.000 1 11775.402 96.569 1983-12-31 00:00:00.000
008068 3 1984-05-07 00:00:00.000 2 11428.602 96.751 1984-03-31 00:00:00.000
008068 4 1984-08-02 00:00:00.000 3 11642.902 98.104 1984-06-30 00:00:00.000
008068 5 1984-10-18 00:00:00.000 4 11654.5 98.984 1984-09-30 00:00:00.000
similarly:
DATADATE ATQ PRCCD PATQ datadate rdq
1984-01-31 00:00:00.000 NULL 28 NULL NULL NULL
1984-02-01 00:00:00.000 NULL 28.625 NULL NULL NULL
1984-02-02 00:00:00.000 NULL 27.875 NULL NULL NULL
1984-02-03 00:00:00.000 11775.2 26.75 4.55841 1983-12-31 1984-02-03 00:00:00.000
1984-02-06 00:00:00.000 NULL 27 NULL NULL NULL
1984-02-07 00:00:00.000 NULL 26.875 NULL NULL NULL
1984-02-08 00:00:00.000 NULL 25.75 NULL NULL NULL
If there isn’t a key already to link the quarterly date, an id could be emulated by using something like
Syntax wise it would look better with a function , but it should work by changing the datetime part of the join to:
If that gives double records, a common table expression (with) could be used to get the quarterly data separately first.