1

I am familiar with building moving averages (whether SMA or EMA) from candle/OHLC data or indeed from a ticker which reports the price at a fixed interval.

But I would like to extend this to a raw trades feed I have access to. Now clearly trades can come at irregular intervals and depending on the resolution of the feed, likely I may have multiple trades with the same time.

Of course one approach is to aggregate trades into fixed time intervals - basically building my own candles (or 'buckets'). But then some intervals might have zero trades so this approach has issues.

Is there a way to extend SMA/EMA calculations to arbitrary trade times, given a trade time resolution of say 1 second?

3
  • 1
    Volume weighted moving average over n periods. Commented Jun 3, 2021 at 21:13
  • 1
    Aggregate the trades into fixed time intervals and omit the intervals that have no trades from your calculation. Commented Jun 3, 2021 at 23:27
  • @BobBaerker I was wondering if gaps would skew the average. I suppose for gaps I could carry on the last value but that would also skew in a different way. I suppose either has a place and it's finding which is more useful?
    – Mr. Boy
    Commented Jun 4, 2021 at 10:46

1 Answer 1

1

To create moving average for a non-timeseries data. You need to consider normalize your data with timestamp. You can fill the gaps between trades with scaled datas, values that smooth the curve from your last trade to your next trade. Make use of the e constant, you can multiply the last value with a result from a function of e to time.

For example: Your last trade is 1405, your next trade is 1550, the time span is n.

You can make something like: 1405, e/(n-1) * 1405, e/(n-2) * 1405, ... e/(n-t) * 1405 < 1550 (This is just an example, the real function must be tested)

It will smooth the curve and does nothing to the shape of your intended moving average.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .