quarterEnd
Syntax
quarterEnd(X, [endingMonth=12], [offset], [n=1])
Details
Return the first day of the quarter that X belongs to. The first months of the quarters are determined by startingMonth.
When both offset and n are specified and n > 1, the function calculates dates based on periods consisting of n quarters. In this case, offset determines how the multi-quarter periods are aligned. Specifically, the system first calculates the end date of the quarter containing offset according to endingMonth, and uses that date as the reference point. A new period-ending boundary is then generated every n quarters, and the function returns the last day corresponding to the period to which X belongs.
Parameters
X is a scalar/vector of data type DATE, DATEHOUR, DATETIME, TIMESTAMP or NANOTIMESTAMP.
endingMonth is an integer between 1 and 12 specifies the ending month of the
last quarter in a year. The default value is 12, which represents calendar quarters.
For example, when endingMonth = 3, the quarters are defined as
April–June, July–September, October–December, and January–March of the following
year.
offset is a scalar of the same data type as X. It must be no greater than the minimum value of X. The default value is the minimum value of X.
n is a positive integer. The default value is 1.
Returns
A DOUBLE scalar/vector.
Examples
quarterEnd(2012.06.12);
// output: 2012.06.30
quarterEnd(2012.06.13 10:10:10.008,5);
// output: 2012.08.31
date=2016.01.12 2016.02.25 2016.05.12 2016.06.28 2016.07.10 2016.08.18 2016.09.02 2016.10.16 2016.11.26 2016.12.30
time = [09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12,09:38:13]
sym = take(`MSFT,10)
price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29 52.38
qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800 4500
t1 = table(date, time, sym, qty, price);
select avg(price),sum(qty) from t1 group by quarterEnd(date,12,2016.01.01,2)
| quarterEnd_date | avg_price | sum_qty |
|---|---|---|
| 2016.03.31 | 39.53 | 4100 |
| 2016.09.30 | 92.1 | 18800 |
| 2017.03.31 | 51.33 | 15800 |
Related functions: quarterBegin, businessQuarterBegin, businessQuarterEnd
