Skip to content

Latest commit

 

History

History
113 lines (82 loc) · 5.79 KB

README.md

File metadata and controls

113 lines (82 loc) · 5.79 KB

Implement Simple Stock Investment Dashboard with python


Purpose

This is a practice project for learning development of web application in Python after finished some Deep Learning courses with Jupyter Notebook. I am interest in investment. Vincent's blog and GitHub project about using python to build investment tool to analyze and predict stock's reasonable price based on predicted future value is a good starting point for practicd. I start to build 1st version , mainly refer to Vincent's project. ( You can go to Vincent Tatan's blog and GitHub project to get more information. )

After 1st version , I migrate web framework , redesign UI , improve performance, add technical analysis charts , try to make this tool more easy to use. ]

This application implement simplified model to predict expected stock price according to fillowing indicators :

  1. Annual_growth
    • npf.rate(4, 0 , - 1st_year_eps , 5th_year_eps ) , npf is numpy financial package
  2. PE Ratio
    • yearly mean stock price / EPS , and select minimum of recent 5 year
  3. EPS after 2 years later , Future EPS
    • npf.fv( Annual_growth, 2 years , 0, 5th_year_eps)
  4. Future Value
    • Future EPS x PR Ratio
  5. Present Value
    • npf.pv( Dicount Rate , 2 years, 0, Future Value)
  6. Expected Reasonable Price Range , add on +/- margin rate
    • Present Value x ( 1 +/- Margin Rate )

The real stock market is so complicate so these business rules are obviously not enough. It's only POC.

So, don't use this application for real market decision ! ! !

Some experts have already developed models and software to solve financial market challenges, like the true story introduced in this book "The Man Who Solved the Market". Though the book touch lightly on tech details, many resource around similar topic are available on Web and GitHub. I have found some links :

Lots of domain knowledge and skills are required to build similar system.

The Wall Street Journal (2021-01-18) :
Quant hedge fund tells clients that drop of 20% to 30% was partly due to increased volatility.

Wow, even the best model won't always beat the market ...


Warning :

This application has not been rigorously tested and its domain rules are very simple which are hard to cover the complexity of real stock market. There may be also incorrect data introduced by some not found bugs or data sources .

This application is not mature enough and risky to be your decision tool in real stock market !


Screenshots :


Develop tools and main packages

  1. Visual Studio Code
  2. Python 3.8
  3. pipenv
  4. Web framework : from Dash migrate to Django
  5. Django Rest Framework
  6. Stock chart : from cufflinks.quant_figure change to HighCharts Stock
  7. jQuery : through ajax update information and stock chart
  8. pandas datareader : to get stock price history
  9. BeautifulSoup : parse web page
  10. gunicorn web server
  11. dj-static for static file process in gunicorn
  12. Web UI apply Bootstrap 4.x with responsive design
  13. Fontawesome : icon
  14. 2 Slider components :

Run and Deploy

  1. No requirement for database
  2. Stock price and financial data are retrieved from other web site or service in real time, if data sources are blocked or data specs are changed that will cause service error
  3. Stock information will be cached in memory for 12 hr after first accessed
  4. Demo site is deploy to Google Cloud Run, it may need a few seconds to start application if it already auto shutdown after long idle.
  5. It may take a few seconds to refresh stock information if it's the first access of selected stock in last 12 hours

Run in development mode

  1. config/settings.py will read OS environment variable to set logger level, set 'LOGGER_LOG_LEVLE=DEBUG' will enable debug mode
  2. python manage.py runserver

Run in gunicorn

  1. python manage.py collectstatic // this will copy css js image ... files to staticfiles folder
  2. gunicorn --bind 0.0.0.0:change_to_prefered_port config.wsgi:application

Deploy to Google Cloud Run

  1. Apply for Google Cloud Service account
  2. Install Google Cloud SDK for python, follow instruction on official document
  3. Install Google Cloud extend module for Visual Studio Code
  4. Use Cloud Run to deploy application in Visual Studio Code

What's new or fixed issues:

2024-01-03

  1. Refactor codes to follow pylint and mypy rules
  2. Fixed issue: Error occured when retrieve stock data from yahoo

2024-01-15

  1. Add Copilot usage guidelines and improve logging in investment_suggestion_view
  2. Refactor dashboard.js to asynchronously update charts when stock is selected.

2024-01-16

  1. Refactor code to prevent from invoking duplicated requests to access same stock data from outside website

2024-08-08

  1. Close the demo site. In an era of AI rising, the methods and tools for software development are so different. We can do better design and work more efficiency and learn more quickly through AI tools' help. This project becomes less helpful for learning reference, so does the demo site. This project's demo site is closed now to leave resource fo more effective usage.