semiannualEnd

First introduced in versions: 3.00.4, 3.00.3.1

Syntax

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

Details

Return the last day of the semiannual period that X belongs to. The first months of each semiannual period is determined by endingMonth.

By default, each period corresponds to a half-year, and the function returns the last day of the half-year containing X. The months included in each half-year period are determined by the endingMonth parameter.

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

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 DATE scalar.

Examples

semiannualEnd(2025.08.10);
// output: 2025.12.31

semiannualEnd(2025.10.10 10:10:10.008, 3);
// output: 2026.03.31

date=[2024.04.20,2024.05.31,2024.07.07,2024.10.24,2024.12.20,2025.01.19,2025.04.24,2025.04.28,2025.10.06,2026.01.06]
sym = take(`AAA,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, sym, qty, price);

select avg(price),sum(qty) from t1 group by semiannualEnd(date, 12, 2024.01.01, 2)
semiannualEnd_date avg_price sum_qty
2024.06.30 39.53 4,100
2025.06.30 85.13666666666667 21,300
2026.06.30 51.835 13,300