5.6 Locate multiple specified members and compare each with the neighboring row
Calculate the growth rate of closing price in each day of the last 10 transaction dates in the year 2019 compared with price of the previous day. Below is part of the data 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 | =A2.p(to(-10,-1)) |
4 | =A3.new(A2(~).Date:Date, string(A2(~).Close/A2(~-1).Close-1, “0.000%” ):Increase) |
A1 Import the data file.
A2 Select records of the year 2019 and sort them by date.
A3 Use A.p() function to return ordinal numbers of the last 10 records.
A4 Loop each day to calculate growth rate of the current closing price compared with price of the previous transaction date.
Execution result:
Date | Increase |
---|---|
2019/12/18 | -0.178% |
2019/12/19 | 0.001% |
2019/12/20 | -0.402% |
2019/12/23 | -1.404% |
2019/12/24 | 0.673% |
… | … |
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