yearEnd

Syntax

yearEnd(X, [endingMonth=12], [offset], [n=1])

Details

Return the last day of the year that X belongs to and that ends in the month of endingMonth.

By default, each period corresponds to one year, and the function returns the last day of the year containing X. The ending month of the year is determined by the endingMonth parameter.

When both offset and n are specified and n > 1, the function calculates period end dates based on n-year periods. In this case, offset determines how multi-year periods are aligned. Specifically, the system first calculates the end date of the year containing offset according to endingMonth, and uses that date as the reference point. A new period end boundary is then generated every n years, 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 (optional) is an integer between 1 and 12 indicating a month. The default value is 12.

offset (optional) 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 (optional) is a positive integer. The default value is 1.

Returns

A scalar or vector of the DATE type.

Examples

yearEnd(2012.06.12, 3);
// output: 2013.03.31

yearEnd(2012.06.12, 9);
// output: 2012.09.30

yearEnd(2012.06.12);
// output: 2012.12.31

yearEnd(2012.06.12, 12, 2009.04.03, 2);
// output: 2013.12.31

date=2011.04.25+(1..10)*365
time = take(09:30:00, 10);
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);

t1;
date time sym qty price
2012.04.24 09:30:00 MSFT 2200 49.6
2013.04.24 09:30:00 MSFT 1900 29.46
2014.04.24 09:30:00 MSFT 2100 29.52
2015.04.24 09:30:00 MSFT 3200 30.02
2016.04.23 09:30:00 MSFT 6800 174.97
2017.04.23 09:30:00 MSFT 5400 175.23
2018.04.23 09:30:00 MSFT 1300 50.76
2019.04.23 09:30:00 MSFT 2500 50.32
2020.04.22 09:30:00 MSFT 8800 51.29
2021.04.22 09:30:00 MSFT 4500 52.38
select avg(price),sum(qty) from t1 group by yearEnd(date, 4, 2010.04.01, 2);
yearEnd_date avg_price sum_qty
2012.04.30 49.6 2200
2014.04.30 29.49 4000
2016.04.30 102.495 10000
2018.04.30 112.995 6700
2020.04.30 50.805 11300
2022.04.30 52.38 4500

Related functions: yearBegin, businessYearBegin, businessYearEnd