This projects main functionality is the visualization of the following stock performance indicators (called "stock PI's" in the following):
-
Requirements
-
Project Description
2.1 User Interaction
2.2 Stock PI Cache
2.3 CSV Downloader
-
Structure
-
Known Issues and Troubleshooting
-
Sample Stock Tickers
- Python 3 or greater
- Installed packages listed in requirements.txt (e.g. with pip install -r requirements.txt)
After running the main.py, the user is prompted to:
- Select a stock PI for
visualization
- OR:
Download
stock PI's from Yahoo! Finance into a CSV (the file has to be filled with stock tickers and indices beforehand and has to have a "Country"-column - see example.csv
To visualize a stock PI, the user has to select a main stock ticker
used for comparison to the same PI of other stocks.
The user can either use all instances of the stock PI in the cache/ directory for comparison or specify the stocks used for comparison with the following filters:
When visualizing the PEG-ratio, the user additionally has the ability to select the maximum range of the ratios to be displayed in the plot. If the PEG-ratio of the main stock
is not in this range, the user is alerted and can specify a new range.
After all user-inputs, one of the following plots is displayed:
The red data-point marks the PI of the main stock
specified by the user and it's ticker is constantly displayed.
When hovering over a black comparison-data-point it's ticker is also displayed.
The blue line indicates the mean of the specified PI's and the light-blue area indicates their standard deviation.
When comparing stock PI's, one thing is crucial: A large database. To retreive this data I used the libary yfinance which scrapes Yahoo! Finance. Unfortunately the computation time for the requests being send to Yahoo! Finance is very long. This results in a huge detriment to user experience if real-time scraping of a large stock-database is performed.
My solution for this problem: I implemented data_into_csv.py to pre-download stock PI's and save them in the CSV files located in cache/.
The stock PI's are always selected out of cache/. However, if cache/ does not contain the main stock PI
, the most-fitting CSV-file (chosen by country) is automatically updated with real-time data from Yahoo! Finance.
You can also download CSV's containing stock tickers fairly easily yourself with csv_downloader.py. In this file you will find the code that I used to download the ticker-CSV's from EOD Historical Data into cache/. You can use it as a guide.
-
Issues related to Yahoo! Finance
-
When executing data_into_csv.py I sometimes received the following errors:
TypeError: 'NoneType' object is not iterable
ConnectionError: HTTPSConnectionPool(host='finance.yahoo.com', port=443)
Running the script again always fixed it for me.
-
Sparse CSV files
After sending a large number of requests in a short time period to Yahoo! Finance, one's IP address gets temporarily banned and Yahoo! Finance sends back empty data. This is why the CSV files get more sparse towards the end.
-
-
I tried my best to catch errors related to user-inputs. Also the user should always be able to abort the running main.py by typing
break
. Sometimes this throws weird errors after abortion. -
Because the cache/ was pre-downloaded and is not regularly updated, I cannot guarantee for the accuracy of the cached data.
AAPL
for Apple, Inc.MSFT
for Microsoft, Inc.BABA
for Alibaba Group Holding, Ltd.- You can search for any public company on Yahoo! Finance and it's ticker will appear next to it's name.