semiannualBegin

Syntax

semiannualBegin(X, [startingMonth=1], [offset], [n=1])

Arguments

X is a scalar/vector of data type DATE, DATEHOUR, DATETIME, TIMESTAMP or NANOTIMESTAMP.

startingMonth (optional) 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.

Details

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

If the parameter offset is specified, the result is updated every n semiannual periods. The parameters offset and n must be specified together, and offset takes effect only when n > 1.

Examples

semiannualBegin(2025.08.10);
// output: 2025.07.01

semiannualBegin(2025.10.10 10:10:10.008, 3);
// output: 2025.09.01

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 semiannualBegin(date, 1, 2024.01.01, 2)
semiannualBegin_date avg_price sum_qty
2024.01.01 62.714 16,200
2025.01.01 81.9 18,000
2026.01.01 52.38 4,500