Giter Site home page Giter Site logo

markowitz_mpt's Introduction

This model is made for learning puposes only and should not be used for investment or decision making.

Portfolio risk management

An application of the Markowitz efficient frontier model and the Modern Portfolio Theory

In this project I implement the almost complete automation of the portfolio optimization and risk using the Markowitz model.

Requirements:

python3 and pip correctly installed

Usage:

git clone https://github.com/Fnine99/Markowitz_mpt

cd Markowitz_mpt

pip install -r requirements.txt

python3 main.py

Content description:

Step 1) 5 years monthly price time series data fetching on the Twelve Data API

see data.py

Step 2) Various methods on each assets including:
-Monthly prices
-Monthly returns
-Arithmetic mean return
-Geometric mean return
-Monthly returns standard deviation

see assets.py

Step 3) Portfolio construction and Various portfolio methods including:
-Portfolio return
-Porfolio covariance_matrix
-Portfolio variance
-Portfolio standard deviation
-Portfolio correlation matrix
-Portfolio inverse covariance matrix

see portfolio.py

Step 4) Portfolio optimization with Scipy algorithms including finding the assets weights which:
-Minimize the portfolio return
-Maximize the portfolio return
-Minimize the portfolio variance
-Maximize the portfolio variance
-Maximize the portfolio Sharpe ratio

see optimize.py

Step 5) Efficient frontier construction and portfolios modelling including:
-Generate X number(1M) of portfolios
-From those generated portfolios locate the assets weights which:
>Minimize the portfolio variance
>Maximize the portfolio Sharpe ratio
-Plot step 4 and 5

see frontier.py

Results Example

Step 2:

Monthly Prices:

Monthly returns:


Step 3:



Portfolio Covariance Matrix:

Portfolio Correlation Matrix:

Portfolio Inverse Covariance Matrix:

Step 4:
Note that the portfolio with asset weight bounds of [0.000, 0.900] and with a risk-free rate of 0.045. Very interesting to see that, when generating 1M of portfolios, we can very precisely predict the optimized portfolios.
Screenshot 2023-04-03 at 5 20 00 PM
Screenshot 2023-04-03 at 5 20 16 PM

Screenshot 2023-04-03 at 5 20 38 PM

Screenshot 2023-04-03 at 5 20 48 PM
Step 5:







markowitz_mpt's People

Contributors

fnine99 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.