[PERFORMANCE] Provision indicator class with pre-computed values
ColCh opened this issue · 0 comments
ColCh commented
As I see, SMA (for example) starts with zero values
and then calculates price for passed values, or calculates next generator value
BUT I save calculated values into DB, and there is already calculated values for indicators
So, providing already calculated values from DB may greatly increase performance for calculation.
For now, it's required to calculate values for every indicator from scratch (e.g. on app startup), even if there is values retrieved from DB
e.g.
// startup code
const pastSMAValues = await mySMADBValues.select(); // [0, 0, 0, 1, 1.1, 1.2, 1.1]
const mySMA = new SMA({ pastValues: pastSMAValues });
// runtime code
// new tick retrieved from stream api
cont newTick = { /* OHLC tick */ };
mySMA.nextValue(newTick); // 1.15 -> new SMA value for new tick based on passed pre-calculated SMA values