Python3 based ASX data download and web application with basic features:
-
ability to search by sector, keyword, movement, dividend yield or other attributes
-
watchlist and sector stock lists, sortable by key metrics (eps, pe, daily change etc.)
-
graphs of datasets over 12 months (or whatever data is available)
-
portfolio optimisation using PyPortfolioOpt
-
Market and per-sector performance incl. top 20/bottom 20
-
Virtual portfolios with trend visualisations, profit/loss by stock
-
Stock point-scoring by rules over time, based on their price performance
-
Visualisations provided by plotnine and matplotlib
This software is provided to you "as-is" and without warranty of any kind, express, implied or otherwise, including without limitation, any warranty of fitness for a particular purpose. In no event shall the author(s) be liable to you or anyone else for any direct, special, incidental, indirect or consequential damages of any kind, or any damages whatsoever, including without limitation, loss of profit, loss of use, savings or revenue, or the claims of third parties, whether or not the author(s) have been advised of the possibility of such loss, however caused and on any theory of liability, arising out of or in connection with the possession, use or performance of this software.
-
Python 3.8
-
Django
-
Djongo (python MongoDB for Django apps)
-
Other requirements documented in requirements.txt
On the system to run the website, you'll need to install required software:
git clone https://github.com/ozacas/asxtrade.git
cd asxtrade
sudo pip3 install -r requirements.txt
cd src/viewer # for setting up the website
Next, you'll want to setup a database to store the ASX data: instructions for this can be found at the MongoDB website
python3 manage.py migrate
python3 manage.py createsuperuser
python3 manage.py runserver # run on local dev. host
This application only works with daily data fetched after 4pm each trading day from the ASX website. It will take several hours per run. After the run, you must update the current month's pre-pivoted market data cache. The setup and daily run process is similar to:
# setup database password to use
export PASSWORD=<your db password here>
# run periodically (eg. quarterly) and at setup to update list of securities/companies/fundamentals
python3 src/asxtrade.py --want-companies
python3 src/asxtrade.py --want-isin
python3 src/asxtrade.py --want-details
# daily: fetch prices from ASX - configuration in config.json. Run after trading close each trading day
python3 src/asxtrade.py --want-prices
# daily: update cached data for the specified month (1..12) - needed for website operation
python3 persist_dataframes.py --month 3 --year 2021 --status INCOMPLETE|FINAL --dbpassword '$PASSWORD'
This new data may not appear in the application until the cache entries expire (or alternatively you can restart the server).
Existing data ready to import into mongodb v4.4 can be fetched from github large file storage using mongorestore. This data covers the daily data from July 2020 thru March 2021, although ETF data covers a smaller period due to missing code.
| Feature | Thumbnail Picture |
|---|---|
| Portfolio watchlist | |
| Stock view | ![]() |
| Market sentiment | |
| Performance by sector | |
| Portfolio optimisation |
Tox is used to drive pytest to execute the unit test. Django manage.py test is not used. Github Actions is then used to invoke tox for CI/CD for the application and unit tests.
HTML unit test coverage reports can be produced using something like (from the root of the local repo):
$ export PYTHONPATH=`pwd`/src/viewer
$ pytest -c pytest.ini --cov-report html --cov-config=.coveragerc --cov=src .
$ ls htmlcov
# open htmlcov/index.html in your favourite browser
Use of the Django Debug Toolbar is strongly recommended, but it does have a known limitation which prevents usage during normal operation due to the use of pandas within asxtrade: see django-commons/django-debug-toolbar#1053 for details. For this reason, the MIDDLEWARE setting for the toolbar is commented out, except when needed.
