semiannualBegin
First introduced in versions: 3.00.4, 3.00.3.1
Syntax
semiannualBegin(X, [startingMonth=1], [offset], [n=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.
By default, each period corresponds to a half-year, and the function returns the first day of the half-year containing X. The months included in each half-year period are determined by the startingMonth parameter.
When both offset and n are specified and n > 1, the function calculates period start 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 start date of the half-year containing offset according to startingMonth, and uses that date as the reference point. A new period start boundary is then generated every n half-year periods, and the function returns the first day of the period to which X belongs.
Parameters
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.
Returns
A DATE scalar or vector.
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 |
