This tool should be viewed as a statistical model of the stock market rather than investment advice. Use the Portfolio Allocation Optimizer completely at your own risk. None of the creators or hosts of this software assume any responsibility for financial loss or other damages resulting from its use.
This portfolio optimizer is an Angular 2.0 web application that takes a list of stocks in your portfolio (or a hypothetical portfolio) and returns the optimal allocations for each stock. A backend Python SimpleHTTP server runs the data analysis and serves it up to the frontend Angular application.
We choose to optimize the portfolio's Sharpe ratio. Sharpe ratio is a metric for risk-adjusted returns, so it penalizes portfolios that contain stocks with high volatility. Other metrics could be used and may be added in the future.
We use Yahoo Finance data from Quandl. Admittedly, there are better data sources, but Quandl is a great compromise for its ease of use, price (free), and accuracy.
- Clone this repo using
git clone https://github.com/mwytock0812/portfolio_optimizer.git
. - Build the Anaconda environment.
- Install Anaconda. If you would like a lighter installation, follow the instructions to install Miniconda instead.
cd
into the application root,./portfolio_optimizer/
- Use
conda env create -f ./backend/environment.yml
to install the Python dependencies for the backend. This will create aconda
environment calledstocks
. - Activate the
stocks
environment usingsource activate stocks
on Linux/OS X oractivate stocks
on Windows. You can deactivate the conda environment usingsource deactivate
on Linux/OS X ordeactivate
on Windows.
- With the
stocks
environment activated, runpython app.py
from./portfolio_optimizer/backend
. - Navigate to http://localhost:8000 to verify that you see the "Success!" message.
- By default, the server runs on port 8000, you can specify the port by including a command line flag:
python app.py --port=5678
.
- Assuming you've already cloned the repo, navigate to its root,
./portfolio_optiizer
. - Install Node.js and npm.
- Install the Angular 2 command line interface:
npm install -g angular-cli
. - Run
npm install
to install node dependencies. - Run
ng server
to begin serving the application on http://localhost:4200.
cd
into./portfolio_optimizer/backend
, activate the conda environment, and finally runpython app.py
. See Setup The Backend Data Service for more details on these steps.- Open a new shell session,
cd
into./portfolio_optimizer/backend
, and activate the conda environment. - Run
python -m tornado.testing test.optimizer_test
to test the optimizer module. - Run
python -m tornado.testing test.app_test
to test the backend app itself.