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
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:
How to download and process historic stock price data (for free)
How to build OHLC stock price charts with volume
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.
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 👉
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:
Find edge
Analyze risk
Backtest trading strategies
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...
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.
In the first step, we'll import the necessary Python libraries and collect stock data for each asset using yfinance
.
Run this code:
Sign up for our Newsletter to get all of the code you see today
The result is a simple OHLC chart.
By adding the type argument, we can define the plot type.
Some people like simple line charts.
Other people like more complex charts like Renko charts.
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.
Let’s include three moving averages. The result is a candle chart with 7, 15, and 21 day moving averages.
We can also include volume. The result is a candle chart with multiple moving averages plotted with volume.
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).
mplfinance
handles intraday charting too. The result is a 1-minute chart showing the last 100 minutes of prices.
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.
Alex was waiting 9 years for a course like this:
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?
👉 Join 10,700+ future Quant Scientists on our Python for Algorithmic Trading Course Waitlist: https://learn.quantscience.io/python-algorithmic-trading-course-waitlist
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