I’m having trouble wrapping my head around how to calculate trailing averages in a table that contains many securities. The examples I’ve found only demonstrate how to perform the calculation on a single timeseries.
q)select from day where bbgid.ticker in ("BMO";"TD")date bbgid | open high low close volume vwap -----------------------| ---------------------------------------2014.07.02 BBG000BCRMB0| 54.93 55.32 54.93 55.06 4290490 55.16762014.07.02 BBG000BXSQ97| 78.6 79 78.45 78.79 1345347 78.83652014.07.03 BBG000BCRMB0| 55.35 55.39 55.1 55.12 5148023 55.22192014.07.03 BBG000BXSQ97| 79 79.47 78.83 78.87 1473150 79.07922014.07.04 BBG000BCRMB0| 55.22 55.35 55.22 55.28 2215873 55.30192014.07.04 BBG000BXSQ97| 78.91 79.18 78.88 78.89 330203 79.02052014.07.07 BBG000BCRMB0| 54.84 55.05 54.6 55.05 5173346 54.81712014.07.07 BBG000BXSQ97| 79.02 79.47 78.76 79.28 1601820 79.11712014.07.08 BBG000BCRMB0| 55 55.05 54.61 54.99 6530176 54.85342014.07.08 BBG000BXSQ97| 79.23 79.63 79 79.48 2017145 79.30572014.07.09 BBG000BCRMB0| 55.07 55.33 54.79 55.3 5248002 55.17492014.07.09 BBG000BXSQ97| 79.41 80 79.11 79.94 1525506 79.82172014.07.10 BBG000BCRMB0| 54.47 55.34 54.47 55.17 3822271 55.15832014.07.10 BBG000BXSQ97| 79.49 79.8 79.22 79.78 1689260 79.62652014.07.11 BBG000BCRMB0| 55.29 55.3 54.93 55.05 2013392 55.04972014.07.11 BBG000BXSQ97| 79.8 79.95 79.55 79.81 946332 79.78722014.07.14 BBG000BCRMB0| 55.23 55.3 55.06 55.23 3196446 55.19232014.07.14 BBG000BXSQ97| 80 80.4 79.95 80.09 1248129 80.112 2014.07.15 BBG000BCRMB0| 55.19 55.34 55.12 55.25 3109798 55.28442014.07.15 BBG000BXSQ97| 80.05 80.68 80.01 80.36 1920489 80.3963..
Am I organizing my tables incorrectly or is there a simple way of grouping by id and then inserting a new column?
Thanks,
Ryan