TransWikia.com

How to calculate steady/incremental growth?

Data Science Asked by STEIN on October 4, 2021

I have timeseries data for stocks at minute intervals.

What is the best way to calculate incremental growth, for example if I have a stock’s price from 9am to 2pm at minute intervals, how can calcule the incremental growth. I don’t want to simply calculate the difference between the price at 2pm and 9am, I want to be able to identify stocks which have risen steadily between the two time intervals

2 Answers

What stops you looking at lags?

df = data.frame(c(1,2,3,4,4,3,4,5,6,7))
colnames(df)<-c("price")
df$delta=lag(df$price, 1)
df$inc = df$price-df$delta
df

Would yield:

   price delta inc
1      1    NA  NA
2      2     1   1
3      3     2   1
4      4     3   1
5      4     4   0
6      3     4  -1
7      4     3   1
8      5     4   1
9      6     5   1
10     7     6   1

The condition here would be that each value of inc (except the first one) must be $>0$.

Answered by Peter on October 4, 2021

Simply calculate the derivative of the price level with respect to your time unit (in other words between two subsequent measurements).

If the derivative is 0 at some interval, it means that the price has been stable. If the derivative is positive, it means that the price has increased in that range. If the derivative is negative, then the price has decreased.

The value of the derivative (regardless of the sign) shows the slope of the change. In other words, the higher the derivative the more aggressive the change towards the direction that is denoted by the sign.

You can easily do this with numpy.diff.

Note: Differentiation is a "noisy" process and can lead to a very edgy graph of the derivative when you plot it, especially if you have sudden changes in the price level. To solve this, you should consider some smoothing tactics such as a moving average filter applied on the calculated values of the derivative or any other low-pass filter.

Answered by pcko1 on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP