Just 13 lines of code, I promise
First, we need to define the stocks we wanna watch:
Then let's use Python's ffn library to get the closing prices of the last three trading sessions (three because we might be on a weekend):
Once we have the prices, let's calculate the percentual change over the days, remove any n/a
values and get the last price diff using iloc[-1:]
:
We also need to transpose the data frame and reset the index before advancing to the final step:
Here we get the top 5 best and worst performing stocks over the last trading session.
Putting all together now:
Hope you have liked :)