businessQuarterBegin

Syntax

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

Details

Return the first business day (Monday to Friday) of the quarter that X belongs to. The first months of the quarters are determined by startingMonth. Here, business days are determined solely by the day of the week: Monday through Friday are considered business days, while Saturday and Sunday are considered non-business days.

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 first business day of the quarter containing offset according to startingMonth, and uses that date as the reference point. A new period start boundary is then generated every n quarters, and the function returns the first business day corresponding to the period to which X belongs.

DolphinDB and pandas both provide similar date offset functionality at the conceptual level. For a comparison of calculation rules, see Functions Related to Date Offset.

Parameters

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

startingMonth (optional) is an integer between 1 and 12 that specifies the starting month of the first quarter in a year. The default value is 1, which represents calendar quarters, i.e., January–March, April–June, July–September, and October–December.

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/vector of type DATE.

Examples

businessQuarterBegin(2012.06.12);
// output: 2012.04.02

businessQuarterBegin(2012.06.12, 3);
// output: 2012.06.01

businessQuarterBegin(2012.06.12, 8, 2011.08.01, 3);
// output: 2012.05.01

date=2011.04.25+(1..10)*90
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
2011.07.24 09:30:00 MSFT 2200 49.6
2011.10.22 09:30:00 MSFT 1900 29.46
2012.01.20 09:30:00 MSFT 2100 29.52
2012.04.19 09:30:00 MSFT 3200 30.02
2012.07.18 09:30:00 MSFT 6800 174.97
2012.10.16 09:30:00 MSFT 5400 175.23
2013.01.14 09:30:00 MSFT 1300 50.76
2013.04.14 09:30:00 MSFT 2500 50.32
2013.07.13 09:30:00 MSFT 8800 51.29
2013.10.11 09:30:00 MSFT 4500 52.38
select avg(price),sum(qty) from t1 group by businessQuarterBegin(date, 10, 2010.10.01, 2);
businessQuarterBegin_date avg_price sum_qty
2011.04.01 49.6 2200
2011.10.03 29.49 4000
2012.04.02 102.495 10000
2012.10.01 112.995 6700
2013.04.01 50.805 11300
2013.10.01 52.38 4500

Related functions: businessQuarterEnd, quarterBegin, quarterEnd