Preprocess and analyze stock returns with Python

Learn to statistically analyze the stock performance of a company with Python.

Who would have been the lucky ones who bought NVIDIA shares before they went up 20% in a single day?

Daily return histogram of NVIDIA shares, showing a distribution that includes a peak of more than 20% increase in a single day.
F1. Daily Return Histogram of NVIDIA

In this tutorial, we will calculate the stock returns of NVIDIA to analyze their statistical behavior.

Data

Thanks to the yfinance library, we can download the stock data of NVIDIA with its ticker NVDA.

import yfinance as yf

df = yf.download('NVDA')
Raw data downloaded from NVIDIA's stock using the yfinance library, showing opening, closing, high, and low prices.
F2. Raw data of NVIDIA via yfinance.

Questions

  1. How to download stock data of a specific company using Python?
  2. What command allows filtering data by specific dates?
  3. How is the daily return of a stock calculated?
  4. What is the method to visualize the distribution of daily return?
  5. How to interpret the distribution of daily return?
  6. How is the cumulative return of an investment calculated?

Read the full story

Sign up now to read the full story and get access to all articles for subscribers only.

Subscribe
Already have an account? Sign in

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to datons.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.