NYUFRE / FRE_Platform

FRE Platform is a framework for students to learn end-to-end development of financial applications. The platform has a 3-tier architecture. The front-end is a Web interface, which support user registration, login/logout and all the user interactions for financial modeling, portfolio management and auto-trading simulation. The middle-tier handles real-time and historical market data feeds and database management. It supports portfolio management, and financial modeling, as well as simulated manual and auto trading. The backend is a server which builds a simulated market for trading. FRE Platform is run as a virtual environment or in a Docker container.
MIT License
5 stars 0 forks source link

Refactor project to shorten app.py #203

Closed shawn-yin128 closed 2 years ago

shawn-yin128 commented 2 years ago

Refactor Idea:

Previous problem:

Before, we write all service logic for a specifc RESTful API in the app.py so that we have so many codes in app.py

Optimization Idea:

  1. build this project with a MVC structure
  2. remove all service logic from the app.py, make app.py a pure dispatcher to map RESTful APIs to corresponding function
  3. move all service logic that was originally in app.py into seperate files based on API name and use those function as controllers
  4. our previous system source codes can be treated as services layer

Structure after refactor:

FRE_Platform
|
|-- app.py
|
|-- system/
|   |
|   |-- controllers/
|   |   |-- ai_modeling/
|   |   |-- alpha_test/
|   |   |-- asset_pricing/
|   |   |-- earning_impact/
|   |   |-- high_frequency_trading/
|   |   |-- keltner_channel/
|   |   |-- manual_trading/
|   |   |-- market_data/
|   |   |-- pair_ai_trading/
|   |   |-- portfolio_optimization/
|   |   |-- prediction_portfolio_optimization/
|   |   |-- simulated_trading/
|   |   |-- statistical_arbitrage/
|   |   |-- stock_selection/
|   |   |-- technical_indicator/
|   |   |-- user_service/
|   |   |__ root.py
|   |
|   |-- database/
|   |
|   |-- services/(previous system)
|   |
|   |-- static/
|   |
|   |-- templates/
|       |
|       |-- csv/

Additional change:

Previously, we use global parameters in some features and it could work because our service logic is in the app.py so we do not need to care about passing parameters.

But in the new structure, I use a list to store all global parameters and because python is passing by reference for non-changeable data structure, so that we can modify those parameters and pass to other functions.

# global parameters
top_stocks_list = []
database.create_table(table_list)
add_admin_user()

final_df = pd.DataFrame()

pb_portfolio = None

df_pb_opt = None

global_param_list = [top_stocks_list, final_df, pb_portfolio, df_pb_opt]

st290 commented 2 years ago

Server notifies app.py once its loading data is done. You could try to remove the server log and monitor it.

By the way, reboot your computer before doing it. As the server is running as a daemon, it is possible still running. In this way, you will not be able to start 2nd server.

shawn-yin128 commented 2 years ago

Server bug fixed