Generate Financial Market Charts with Python in 3 Minutes

Alexandre Stakonski
3 min readNov 30, 2021
Photo by Christina Morillo from Pexels
Photo by Christina Morillo from Pexels

Python is one of the most versatile languages in the coding world, it’s very simple to understand and also very powerful. Today we’ll be using Python combined with online available tools for retrieving Bitcoin data and plotting it into a chart.

If it’s your first time coding I hope you enjoy the ride, Python language is designed to be simple and easy to understand — no previous experience is needed.

1. First steps for coding

Let’s get started by opening Google Drive and creating a Colaboratory file, which is very likely to Jupyter Notebook style — another concept of programming, where results are printed on the fly. If you don’t see it, select “Connect more apps” and search for “Colaboratory”.

Python comes with very good built-in functions, but the best way to use it is by importing libraries. There are thousands of options, which gives you endless combinations when we talk about developing solutions.

For starting we will be installing and importing the yfinance library by typing:

!pip install yfinance

import yfinance

After typing press CTRL + ENTER on your keyboard or click in the ► button to start installing and importing the yfinance library to our project. It provides updated data for a lot of financial market options, including stocks, commodities, cryptocurrencies, etc.

3. Retrieving our data

After importing the necessary library, we will be instructing the program to download all the information we need. In this case we’ll be using Bitcoin’s data from a 12 months timeframe.

To accomplish this just execute the following command:

data = yfinance.download(tickers=’BTC-USD’, period=’1y’)

It will save a variable called data, which contains the information we just called. You can play around later by changing the asset from “BTCUSD” to other options like “APPL”, “EURUSD”, etc.

4. Time to draw charts!

Since our database is created, we just need to print it out on a chart by executing the following:

data[‘Adj Close’].plot()

There you go! We now have visual information plotted in a nice chart.

Exploring new ways with code

Congratulations for finishing this tutorial, you can go ahead and change the parameters as you wish. There are more information, examples and useful tips about this library here.

Don’t forget to share you experience in the comments section bellow and I see you soon with more content. Good coding!

--

--