6.17 Order-based grouping: by the neighboring condition
When grouping an ordered set, create a new group whenever the result of computing a grouping condition is true.
Find the longest days when the closing price of SSE Composite Index in the year 2020 rises continuously (treat the first transaction as rising). Below is part of the stock data:
DATE | CLOSE | OPEN | VOLUME | AMOUNT |
---|---|---|---|---|
2020/01/02 | 3085.1976 | 3066.3357 | 292470208 | 3.27197122606E11 |
2020/01/03 | 3083.7858 | 3089.022 | 261496667 | 2.89991708382E11 |
2020/01/06 | 3083.4083 | 3070.9088 | 312575842 | 3.31182549906E11 |
2020/01/07 | 3104.8015 | 3085.4882 | 276583111 | 2.88159227657E11 |
2020/01/08 | 3066.8925 | 3094.2389 | 297872553 | 3.06517394459E11 |
… | … | … | … | … |
A.group() function works with @i option to create a new group whenever the condition changes.
SPL script:
A | |
---|---|
1 | =T(“SSEC.csv”) |
2 | =A1.select(year(DATE)==2020).sort(DATE) |
3 | =A2.group@i(CLOSE<CLOSE[-1]) |
4 | =A3.max(~.len()) |
A1 Import the SSEC table.
A2 Select records of the year 2020 and sort them by date in ascending order.
A3 Create a new group whenever the current closing price is less than price of the previous date.
A4 Count the largest number of days when the price rises continuously.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL