Math
A stock retrieval script in Python
One of the most versatile packages for stock analysis is undoubtedly Yahoo Finance. It contains a plethora of investment related information for both retail and institutional investors, all free of charge.
However, one main drawback of relying solely on the website’s graphical user interface (GUI), is the incessant number of clicks and scrolls we need to press in order to retrieve the desired information.
Thankfully, a more convenient method exists in the form of the yfinance package.
For the professional investors, quants and academics in our midst, a more mathematically rigorous form of data exists in the form of Alpha Vantage.
It comes preloaded with a ton of computational finance tools such as linear algebra, statistics, differential equations and the like.
However, so far, the Yfinance package is more ubiquitous.
Using it, one can wrangle a Python script, that provides all the relevant information at literally the touch of a button.
This is what I demonstrate here.
Assuming the viewpoint of a retail investor
Before we wade into the code, some things to keep in mind, is that this post is written from the viewpoint of a passive retail investor.
One who buys a tranche of stock, and intends to hold on to it for a long period of time.
Hence, each time the investor checks it, it is mainly to see its price action for the particular day, as well as witness its latest price.
A far greater level of customizability exists, but that shall be a topic for another day.
So far instance, the market for Electric Vehicles has been booming of late.
And we would like to purchase some EV stocks.
And we would like to craft a script to monitor a basket of EV stocks.
We chose:
- NIO
- XPENG
- Ford
- Tesla
And we have them, right below.
All 4 stocks at our fingertips.
And the relevant scripts is included below.
A quick glance above reveals the various configurable parameters, such as the granularity of the time, as well as the time horizon.
If you’re so inclined, you can configure the color of the plot to show red or green, depending on the price action for the day.
And that is the customizability provided by knowing your way around the yfinance package.