Join the Quant Scientist Newsletter

Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...

Join 11,500+ Quant Scientists learning one article at a time

Join 11,500+ Quant Scientists learning one article at a time

mplfinance for beautiful stock price charts

mplfinance for beautiful stock price charts

October 05, 20244 min read

Here at Quant Science, we love using Python for financial market data analysis.

After all: it's the first step to building profitable trading strategies.

In today's issue of the QS Newsletter (get the code), we are going to build beautiful stock price charts with Python using the mplfinance package.

What You’ll Learn:

  1. How to download and process historic stock price data (for free)

  2. How to build OHLC stock price charts with volume

  3. Bonus: How to add moving averages to the price charts

Our example stock:

  • Assets: AAPL

  • Date Range: January 2022 - June 2022

BONUS: Get the Python Code for EVERYTHING you see in this post

Disclaimer:

The information and educational material provided by Quant Science, LLC are for educational purposes only and should not be considered as financial advice or recommendations to purchase, hold, or sell any securities or other financial instruments. Before you proceed, please review our full disclaimer here.

Create beautiful stock price charts (in 1 line of code)

Join the Quant Scientist Newsletter (and Get the Code)

Want exclusive access to our FULL codebase for this Quant Science tutorial plus dozens more? The code is in the QS021 Folder.

Join thousands of aspiring Python quants here 👉

NEW: Free 5-Day Algorithmic Trading Course

5 Day Algorithmic Trading Course

Since you're here, you probably want to learn how to get started developing (profitable) algorithmic trading strategies and reinvest those profits.

Here are the steps:

  1. Find edge

  2. Analyze risk

  3. Backtest trading strategies

  4. Execute trades automatically

Easy right? Well, not exactly... Avoid the 5 biggest mistakes beginners make with our free, 5-day email course:

Click here to join our free 5-Day Algorithmic Trading Course 👉

Now on to the show...

mplfinance for beautiful stock price charts

Ok, let's dive in and see how to use the mplfinance package to build beautiful stock price charts in a few lines of code.

First, make sure to sign up for our Newsletter to get all of the code you see today.

Load the Libraries, Data, and Get Price Data

In the first step, we'll import the necessary Python libraries and collect stock data for each asset using yfinance.

Run this code:

Imports

Sign up for our Newsletter to get all of the code you see today

The default chart type is a simple OHLC plot.

The result is a simple OHLC chart.

Plots

By adding the type argument, we can define the plot type.

Plots

Some people like simple line charts.

Plot

Other people like more complex charts like Renko charts.

Renko

We can also include moving averages to the plot. Use a single number for a single moving average. Use a tuple of numbers for several. The result is an OHLC chart with a 15 period moving average.

Plot

Let’s include three moving averages. The result is a candle chart with 7, 15, and 21 day moving averages.

Plot

We can also include volume. The result is a candle chart with multiple moving averages plotted with volume.

Plot

We can include non-trading days as well. The result is the same as above including non-trading days (note the gaps in the volume bars).

Plot

mplfinance handles intraday charting too. The result is a 1-minute chart showing the last 100 minutes of prices.

Plot

Congratulations!

You just learned how to create a comprehensive set of stock price charts in Python using the mplfinance package.

But, there's more to learn in algorithmic trading:

  • Backtesting your portfolio construction algorithm to make sure the strategy will work in the future

  • Executing the trades automatically

  • Monthly rebalancing

  • Tracking your actual Profit and Loss

  • Incorporating Trading Fees

Are you interested in learning algorithmic trading strategies that maximize returns responsibly, help you manage risk, and grow your investments?

We implement 3 core trading strategies including portfolio, momentum, and spread trades that have worked in our favor in the past and continue to produce results for our students.

Join 400+ of us that are learning to apply python to algorithmic trading to grow investments.

Leo was up 11.5% in just 13 trading days.

Leo up 13pct

Alex was waiting 9 years for a course like this:

testimonial

Ready to make Algorithmic Trading Strategies that actually work?

There's nothing worse than going at this alone--

Learning Python is tough.

❌ Learning Trading is tough.

Learning Math & Stats is tough.

It's no wonder why it's easy to feel lost, make bad decisions, and lose money.

Want help?

Python for Algorithmic Trading Course

👉 Join 10,700+ future Quant Scientists on our Python for Algorithmic Trading Course Waitlist: https://learn.quantscience.io/python-algorithmic-trading-course-waitlist

button course waitlist

investingstockspythonalgorithmic tradingsoftwareffn
Matt is a Data Science expert with over 18 years working in business and 10+ years as a Data Scientist, Consultant, and Trainer. Matt has built Business Science, a successful educational platform with similar goals to Quant Science, but focused on developing Data Scientists in business, marketing, and finance disciplines.

Matt Dancho

Matt is a Data Science expert with over 18 years working in business and 10+ years as a Data Scientist, Consultant, and Trainer. Matt has built Business Science, a successful educational platform with similar goals to Quant Science, but focused on developing Data Scientists in business, marketing, and finance disciplines.

Back to Blog

Start Your Journey To Becoming A Quant Today!

Join the Quant Scientist Newsletter

Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...

Join 11,500+ Quant Scientists learning one article at a time

Join 11,500+ Quant Scientists learning one article at a time

© 2024 Quant Science - All Rights Reserved

Next Cohort Launch: Wednesday, January 15th at 10AM EST