Skip to content

Latest commit

 

History

History
154 lines (103 loc) · 7.99 KB

README.md

File metadata and controls

154 lines (103 loc) · 7.99 KB

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Robo-Advisor using BERT sentiments from Twitter feeds for enhanced Portfolio Optimisation with Genetic Algorithm

Automatic goal-oriented portfolio allocation and rebalancing using a variety of classic and machine learning algorithms, as well as our so-called Sentimental All-Weather (SAW) and Sentimental Modern Portfolio Optimisation (SMPT) portfolios


View Heroku demo · Report Bug · Request Feature

About

We propose a hybrid approach to portfolio managemnt, using traditional portfolio optimisation approaches as a baseline and augmenting portfolio performance using sentiments derived from Twitter. The usage of traditional portfolio optimisation as a backbone is advantageous as it is mostly familiar to investors and fund managers alike, and is easier to explain. By using Twitter sentiments as an insight into overall investor sentiments, we will also be pro-active towards potential market dips and spikes, and be able to increase our cumulative returns. An overview of the proposed approach, and the out-of-sample performance are shown below.

Overall Approach

Overall Approach

An end-to-end robo-advisor system is developed using Django, leveraging Django Edge v2.2. The list of portfolios is easily configurable from a spreadsheet, and includes SPDR sector ETFs, and All-Weather ETFs, SAW and SMPT portfolios. The overall user and system flows are shown below. As a prototype robo-advisor, it will only have the following core functionalities:

  • Basic user management - sign up and log in,
  • Summary page showing current account balance, earnings, portfolio as- set value, etc,
  • Add and withdraw funds (virtual funds, no actual interface with real money),
  • Portfolio management - Compare, buy and sell portfolios.

Django User and System Flows

For more details, please refer to the complete paper here.

This repository can also be used to facilitate the experimentation of different portfolio algorithms. Refer to example Jupyter notebooks

Getting Started

Installation

  • Before cloning the repository, make sure you have git-lfs installed on your environment. The instructions to do so can be found here

  • If using Windows, install GNU Make to utilise make commands in the repo.

  • Then clone this repo:

git clone https://github.com/eleow/roboadvisorSystem.git
  • For frontend code, install prerequisites in "requirements.txt"
  • For backend code, install prerequisites in "\SystemCode\backend\requirements.txt"
  • Note: zipline uses pandas==0.22.0 (Ignore warning about conflicts)

Usage

Robo-advisor system can be started by running the front-end Django server. Start the front-end by typing the following in your Anaconda environment, in the root directory of the repo

make front

Alternatively, if 'make' is not installed, then you can type the following

cd /d SystemCode/frontend/smartportfolioWeb/src
python manage.py runserver

Examples

Example usage of most backend functionalities can be found in the Jupyter Notebooks, Examples

Examples for Sentiment Analysis

Sentiment analysis example is found in the Jupyter Notebook, Sentiments

Tweets are obtained via "Twitter-Get-Old-Tweets-Scraper" using Jupyter Notebook, GetTwitterData.ipynb. Note that after retrieving a certain number of tweets (14000++), Twitter will block the request with "Sorry, die Anzahl deiner Anfragen ist begrenzt" which means "Sorry, the number of your requests is limited". Then just adjust argument "--until" with the earliest date where it failed and rerun the script after waiting for a while or with a different IP address, and save to a new file.

Examples for Portfolio Optimisation

Portfolio optimisation examples are found in the Jupyter Notebook, Portfolios.

Plot Markowitz bullet

Plotting the Markowitz bullet is a simple one-liner (using default settings) by just providing prices, which is a pandas DataFrame containing adjusted closing prices of the asset (each row is a date and each column is a ticker/id)

from utils import generate_markowitz_bullet
generate_markowitz_bullet(prices)

This will generate the following:

  • Markowitz Efficient Frontier, represented by a dotted line
  • Optimum portfolio based on maximum Sharpe ratio (red star)
  • Optimum portfolio based on minimum volatility (green star)
  • Random portfolios, plotted with color map applied based on Sharpe ratio

Markowitz Bullet

License

Distributed under the MIT License

Acknowledgements

Backtesting is performed using the Pythonic algorithmic trading library, Zipline

Markowitz optimisation and Hierarchical Risk Parity implementations are provided by PyPortfolioOpt

Genetic Algorithm implementation is provided by Distributed Evolutionary Algorithms in Python (DEAP)

Aesthetic style of plotting Markowitz bullet is borrowed from article by Ricky Kim

The front-end UI for the robo advisor system is built using the Django Web Framework

Robot icon made by photo3idea_studio from www.flaticon.com