Indicators | Graphs |
---|---|
This project is a simple look at performing "technical analysis" on stock market time series data using Python 3 and SQLite.
- Acquire data from external data source
- Integrate and organize the data into owned database
- Perform data analysis to derive technical indicators
- (Bonus) Generate data visualizations to aid in understanding data
To accomplish this, we will retrieve time series (and other stock market data such as earnings reports) from external sources. Since external data sources may not be 100% reliable, we will make use of two different sources: Twelve Data https://twelvedata.com/ and AlphaVantage https://www.alphavantage.co/
Data will be retrieved with API calls made with the "requests" Python library, and then loaded into a SQLite database. The SQLite module is part of the standard library for Python 3, and provides "...a small, fast, self-contained, high-reliability, full-featured, SQL database engine." https://www.sqlite.org/index.html
After data is loaded into the SQLite DB, SQL queries can be used to calculate for a variety of "technical indicators" such as the Relative Strength Index (RSI), Moving Average Convergence/Divergence indicator (MACD), and other metrics such as the Price/Earnings Ratio and Earnings Yield. This information may then be used to attempt to predict future price changes and assist in making trading decisions.
Additionally, the use of the "plotly" python library allows us to create financial charts, which assists in analysis of data by providing a visual component.
This project requires a Python 3 environment plus the following packages:
- requests (for API calls) https://pypi.org/project/requests/
- pandas (nicer looking table output) https://pypi.org/project/pandas/
- plotly (graphing data) https://plotly.com/python/
Both can be conveniently installed via PIP
pip install requests
pip install pandas
pip install plotly==5.21.0
Additionally, to retrieve new data, you will need to get your own free API keys from Twelve Data https://twelvedata.com/ and AlphaVantage https://www.alphavantage.co/ and put them into the appropriate locations in the keys.json file. (If you want to skip this part, you can use the provided sample database pre-loaded with data located in /samples/data1.sqlite)
- Download the src *.py files into the same local directory.
- Sign up for your free API keys from TwelveData and optionally, AlphaVantage, if you want to get earnings data which is used to calculate PEratio and Earnings Yield.
- Add your API keys to keys.json in the same dir. If you don't have the keys.json file, the script will create it and prompt you for your API keys.
- Add some stock symbols into stocklist.txt (one per line, following the format: symbol,exchange Ex.: NVDA,NASDAQ)
- Run
GetData.py
to load data into the DB. (A new SQLite DB file named data1.sqlite will be created if it doesn't already exist.) - Follow the prompts. Answer Y to download new time series data based on the stocks listed in the stocklist.txt file. Optionally, answer Y when prompted to download earnings data used for some calculations.
- Run
Demo.py
to view results from a variety of saved queries. By default, results will output to the terminal, and any option with visualizations enabled will automatically create and display the graphics in your default browser. Optionally, results may be output into Excel or whichever default app your system uses to view .CSV files by changing the external editor option ('X' at the menu). These files will be placed in your%TEMP%
dir. You can also turn off the visualization option ('V' from the manu).
- You may use the provided /samples/data1.sqlite SQLite DB file that already has some sample data loaded into it. If so, you may skip steps 2-6. Make sure the file is in the same dir as the .py files.
- You may use the provided /samples/stocklist.txt file which already contains some stock symbols. If so, you may skip step 4. Make sure the file is in the same dir as the .py files.
This project currently has the following limitations:
- Only checks for stocks listed on the NASDAQ and NYSE. This can be updated in the future.
- The 'free' API access from Twelve Data and AlphaVantage both have varying API request limits. For the exact rate and daily API limits, please visit the respective website.
This project is intended only for informational purposes only and is not intended to give financial advice.
GNU General Public License v3.0