2

I am using TA-lib to compute various Technical Indicators. The dataset I have is stock price data for 1 minute intervals. Easiest way is to multiply 390 (390 minutes in a Trading day) with number of days, e.g. To compute 5SMA, SMA(inputs, timeperiod=5*390)

Is there any library for such purpose or any better solution ?

  • it won't work like that. If you have 15 days data (15*390) and specify timeperiod=5*390 you'll get 15*390-5*390=10*390 results back. Bcs TA-Lib will calc SMA for every 1 minute interval after first 5*390 intervals. Thus you need preliminary convert your data to daily intervals. TA-Lib has no funcs for such aggregation. As ta-lib is opensource, such funcs may be implemented, but you better to use just do this on level of your program. – truf Feb 25 '19 at 20:29
  • 1
    @truf I need the intraday indicators. Aggregating to daily interval is not an option as the application has to work on intraday stock prices only. :( – Sameer Pawar Feb 25 '19 at 21:36
  • but if you are using 5-days based indicator it will stay the same for all data in day 6th till it ends. Then it can be racalculated and indicater will be same for all data inside day 7th etc. If you really need different values for every data record inside the day then timeperiod=5*390 is the option. But I don't think the result will be close to original dayly-based SMA, It should be tested, but I won't be surprised if it differ a lot. Also if you need the 2nd option with timeperiod=5*390 and you're getting minutes data at runtime, you'll need – truf Feb 26 '19 at 17:00
  • to recalc SMA for all 5*390 data records every time (390 times a day) which may be time consuming. That's because original ta-lib isn't designed to be used for data received at runtime. I've forked it and adapt for this purpose, so indicators could be calculated incrementally for new data without recalculating old results. If you need something like that you may check my project at https://github.com/trufanov-nok/ta-lib-rt – truf Feb 26 '19 at 17:03

1 Answers1

0

This really depends on what you're seeking. If you're seeking average daily price, you'd have to convert your quote history from minute to daily-sized bars, then run it through in that new format. TA-Lib is an older array-based library, so you'd have to do this work while the data still has date/time context, before you put it in the array.

Here's an example of how to "quantize" quote history in C#.

history
 .OrderBy(x => x.Date)
 .GroupBy(x => x.Date.RoundDown(newBarSize))
 .Select(x => new Quote
 {
   Date = x.Key,
   Open = x.First().Open,
   High = x.Max(t => t.High),
   Low = x.Min(t => t.Low),
   Close = x.Last().Close,
   Volume = x.Sum(t => t.Volume)
 });

This is also available in the open-source Skender.Stock.Indicators library and can be used as simply history.Aggregate(PeriodSize.Day), for example.

This libary can replace TA-Lib, if you're looking for a more modern technical indicators library. For example, it has a history.GetSma(5) method, among others.

Dave Skender
  • 611
  • 5
  • 11