5.10 Application: find the maximum number of days for continuously increasing duration
Find the number of continuous increase of value of the specified column in a loop operation.
Find the maximum number of days when the closing price increases continuously in the year 2019 based on the SSE Composite Index table. Below is part of the table:
Date | Open | Close | Amount |
---|---|---|---|
2019/12/31 | 3036.3858 | 3050.124 | 2.27E11 |
2019/12/30 | 2998.1689 | 3040.0239 | 2.67E11 |
2019/12/27 | 3006.8517 | 3005.0355 | 2.58E11 |
2019/12/26 | 2981.2485 | 3007.3546 | 1.96E11 |
2019/12/25 | 2980.4276 | 2981.8805 | 1.9E11 |
… | … | … | … |
SPL script:
A | |
---|---|
1 | =T(“000001.csv”) |
2 | =A1.select(year(Date)==2019).sort(Date) |
3 | =n=0,A2.max(if(Close>Close[-1],n+=1,n=0)) |
A1 Import the data table.
A2 Select records of the year 2019 and sort them by date.
A3 Loop closing price of each date to compare it with that of the previous date, during which add 1 to the count if the current price is higher, and get the largest count.
Execution result:
Value |
---|
6 |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
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