3.15 Inter-sequence computation: perform alignment operations on members of multiple sequences
Perform four arithmetic operations on members of corresponding positions in multiple sequences.
Calculate relative rates of return between SZSE 300 Price Index (399007) and SZSE Component Index (399001) on each transaction date from 2019-12-24 to 2019-12-26.
Date | Code | Name | Open | Close | Amount |
---|---|---|---|---|---|
2020/2/18 | 399001 | Shenzhen | 11244.7651 | 11306.4863 | 3.19E+11 |
2020/2/17 | 399001 | Shenzhen | 10974.9328 | 11241.4993 | 3.12E+11 |
2020/2/14 | 399001 | Shenzhen | 10854.4551 | 10916.3117 | 2.77E+11 |
2020/2/13 | 399001 | Shenzhen | 10936.5011 | 10864.3222 | 2.87E+11 |
2020/2/12 | 399001 | Shenzhen | 10735.0475 | 10940.7952 | 2.66E+11 |
… | … | … | … | … | … |
SPL Syntax of the alignment arithmetic operations is A ?? B , which performs “?” (?{+,-,*,/,%,}) operation on members of two sequences by corresponding positions.
SPL script:
A | |
---|---|
1 | =connect(“db”) |
2 | =[“399007”,“399001”].(A1.query(“select * from StockIndex where code=? and date between ‘2019-12-23’ and ‘2019-12-26’”,~)) |
3 | >A1.close() |
4 | =A2.(~.calc(to(2,4),Close/Close[-1])) |
5 | =A4(1)–A4(2) |
A1 Connect to the data source.
A2 Retrieve records of SZSE 300 Price Index and those of SZSE Component Index from 2019-12-23 to 2019-12-26. Retrieving records on the date 2019-12-23 is for calculating the growth rate.
A4 Calculate growth rate of each date from 24-26.
A5 Perform alignment subtraction between two sequences to get relative rates of return.
Execution result:
Member |
---|
0.0031349096521252617 |
0.0011897141619391371 |
-4.4910504685946595E-4 |
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