Hello Team,
I am using the following awk script to calculate the SMA (Single Moving Average) for an specific period but now I would like to include the standard deviation output.
Could you please help me to modify this awk shell script
awk -F, -v points=5 ' { a[NR % points] = $2; if(NR>=points) { total_a = 0; for (i = 0; i < points; ++i) { total_a = total_a + a; } print ($1, $2, total_a/points); } }' data.csv
Input Data
Row Data
1 10.09
2 10.14
3 10.02
4 10.13
5 10.1
6 10.06
7 10.15
8 9.91
9 9.99
10 9.72
11 9.75
12 9.57
13 9.62
14 9.97
15 9.71
16 9.77
17 9.88
18 9.71
19 9.75
20 9.53
21 9.46
22 9.38
23 9.63
24 9.67
25 9.92
26 10.04
Expected Output:
Row Data SMA 5 Standard Deviation 5 Period
5 10.1 10.096 0.042237424
6 10.06 10.09 0.04472136
7 10.15 10.092 0.047074409
8 9.91 10.07 0.085556999
9 9.99 10.042 0.084237759
10 9.72 9.966 0.146232691
11 9.75 9.904 0.158442419
12 9.57 9.788 0.147837749
13 9.62 9.73 0.145464772
14 9.97 9.726 0.138361844
15 9.71 9.724 0.138506318
16 9.77 9.728 0.139484766
17 9.88 9.79 0.123450395
18 9.71 9.808 0.102058807
19 9.75 9.764 0.062481997
20 9.53 9.728 0.113912247
21 9.46 9.666 0.152131522
22 9.38 9.566 0.142632395
23 9.63 9.55 0.129460419
24 9.67 9.534 0.106695829
25 9.92 9.612 0.187339264
26 10.04 9.728 0.231637648