[R-SIG-Finance] Aggregating time series by key and time
Robert A'gata
rhelpacc at gmail.com
Tue Oct 11 01:57:33 CEST 2011
Hi,
I have a time series. Mostly trade time series which contain time,
tradeType, tradePrice and tradeSize columns. Says
trdType trdPrice trdSize
2011-10-07 12:17:50 3 1357.998 9
2011-10-07 12:29:10 1 1351.480 4
2011-10-07 12:30:56 3 1361.366 8
2011-10-07 12:30:56 3 1361.366 3
2011-10-07 12:32:33 3 1316.613 4
2011-10-07 12:34:20 2 1321.174 4
2011-10-07 12:35:17 3 1345.164 10
2011-10-07 12:40:23 1 1341.528 10
2011-10-07 12:40:23 2 1331.528 4
2011-10-07 12:43:03 2 1332.578 8
I'd like to aggregate trdSize for trades occurred at the same
timestamp and of the same trade type. So it is not only aggregating by
time. I'm wondering if there is a good way to do this. Any advice
would be greatly appreciated. For reference, the output of such a
function for the above example would be:
trdType trdPrice trdSize
2011-10-07 12:17:50 3 1357.998 9
2011-10-07 12:29:10 1 1351.480 4
2011-10-07 12:30:56 3 1361.366 11
2011-10-07 12:32:33 3 1316.613 4
2011-10-07 12:34:20 2 1321.174 4
2011-10-07 12:35:17 3 1345.164 10
2011-10-07 12:40:23 1 1341.528 10
2011-10-07 12:40:23 2 1331.528 4
2011-10-07 12:43:03 2 1332.578 8
Because at 2011-10-07 12:30:56 we have 2 trades of trdType=3 occurred
with sizes 8 and 3. However, at 2011-10-07 12:40:23, we have 2 trades
occurred at the same price but they differ in trdType. So we do not
perform aggregation. Thank you.
Best regards,
Robert
More information about the R-SIG-Finance
mailing list