When you want to calculate each value of a sequence in Pandas and divide it by stdev of a certain section.

Asked 2 years ago, Updated 2 years ago, 98 views

Thank you for your continuous support.

[Background]
I put the price of the stock in price and use the window function to find the sma as follows

 sma8=pd.Series(price).rolling(8).mean().values
sma24 = pd.Series(price).rolling(8).mean().values

[What I want to do]
Write something like a concept.

sma20_std=pd.Series(price).rolling(20).std().values
Zscore=(price-sma20)/sma20_std

As shown in , I would like to calculate the difference between sma and moving average line divided by the standard deviation (for the past 20 pairs).
I'm thinking of creating indicators such as buying and selling Zscore if it's more than a certain number.

Of course, the above is an incorrect code for spouting errors, so I'm looking for an appropriate way to write them, but I haven't been able to reach such a documentation.
Thank you for your cooperation.

python3 pandas google-colaboratory

2022-09-30 14:44

1 Answers

I solved myself.
The above code is correct.The error was caused by my careless mistake.
Sorry for the trouble.


2022-09-30 14:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.