Top Best/Worst Performing Stocks with Python

Photo by Austin Distel on Unsplash

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 :)

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Rebirth of sensenet docs

It’s time to pickle the beast…

Generalization Process applied to API design of UI components.

Http request and response and how web applications work

Task 18 :Configuring Wordpress and Mysql.

The SuperTrend RSI Confirmation Strategy in Python.

Workflow: Replacing TextExpander

Replacing TextExpander

Create a REST API with Spring Boot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Glauco Custódio

Glauco Custódio

More from Medium

How to Pull Stock Data into your Python ProgramHow to Pull Stock Data into your Python Program

How to Pull Stock Data into your Python Program

Data Analysis in Python; Can recessions be predicted?

Incremental import of last 7 days tweets in pandas using tweepy.

Simplifying Payroll with Python