PyQuant News 🐍
PyQuant News 🐍

@pyquantnews

11 Tweets 1 reads Dec 07, 2022
What do hedge funds like Jane Street, Man Group, and Goldman Sachs have in common?
Internal market price databases.
Any serious quant has a database of prices.
The good news?
It's easy to build one with Python.
Here's how:
By the end of this thread you will know how to:
β€’ Use a library to build a database
β€’ Download stock data for free
β€’ Store the data in a database
I’m going to show you how to do it with Python.
Let’s get started!
Use yfinance to get stock data.
SQLite is a database you can store on your computer. You can use pandas to interact directly with the database.
The best part?
You can create it with 1 line of Python code.
Next, let’s get data.
To make it easy, create 3 functions to download the data, save data within a range, and save data for the last trading day.
Start with a function to get data.
This uses yfinance, moves the date to a column, renames the columns, and adds the symbol.
Next, save the data.
Create a function that uses `get_stock_data` to get a range of stock data and insert it into the market database.
The function uses pandas to connect to the database and insert the data in the DataFrame into the database.
Finally, get the last trading day's data.
Create a function that inserts the last trading day into the database.
This is useful for automating the script to get the current day's data.
With everything set up, use it!
Saving data is one line of code.
You can schedule this to run every day to build your historic data.
Once the data is populated, use pandas to query it with the SQL you know and love.
Since the symbol is saved, you can query by symbol and other filters.
Create a separate table for technical indicators and join by symbol. Or economic data and join by date.
Now you can buid your own quant database like the pros:
β€’ Use a library to build a database
β€’ Download stock data for free
β€’ Store the data in a database
Retweet the top tweet so you can find this later!
Then, follow @pyquantnews for more tweets and threads about getting started with Python for quant finance.
If you like Tweets about getting started with Python for quant finance, you might enjoy my weekly newsletter: The PyQuant Newsletter.
Real Python code for quant finance you can use now.
Join 7,400+ subscribers who are taking action with Python.
pyquantnews.com

Loading suggestions...