Giter Club home page Giter Club logo

portfolio-optimization's Introduction

Portfolio-Optimization

WIP repository

Purpose

The purpose of this project is to have an executable which gives the number of assets to buy from each company in order to build a portfolio.

Backtest

In the folder backtest a study regarding the reproduction of this strategy can be found.

Usage

Data obtention

First of all run

python data.py

It will scrap from wikipedia the components of IBEX35 to get their tickers.

**BEWARE: some tickers may change from time to time. This may lead to lack of data and maybe errors in the computation.

After that just run the file data.R as

Rscript data.R

It will downlaod IBEX35 prices since 2016-01-01. If you want to have older data just change the line in the R file

getSymbols(members$`Ticker symbol`, from="2016-01-01")

Example of execution and options

The program can be run as

python main.py --time=10 --quant=3000 --obj=maxsharpe --fee-abs=2 --fee-rel=0.004

and the output is something like:

Number of assets for each equity
------------------------------
------------------------------
AMS.MC.Adjusted    11
ELE.MC.Adjusted    41
GAS.MC.Adjusted    51
MEL.MC.Adjusted     9 


Optimized at buying prices:
------------------------------
------------------------------
AMS.MC.Adjusted    71.02
ELE.MC.Adjusted    20.10
GAS.MC.Adjusted    23.55
MEL.MC.Adjusted    11.65 


Info:
------------------------------
------------------------------
Investment quantity 3000.0
Amount invested 2911.22
Rest 88.78
-----
Expected return 0.0057
Expected volatility 0.0029
Expected Sharpe 1.9474
Mirrored gains 132.15
Mirrored returns 0.0462
-----
Total Fees paid 19.64
Absolute fees 8.0
Relative fees 11.64

If the data were not updated a warning would appear at the beginning of the output.

Options

The mandatory parameters to include in the execution are:

  • Time: range of time to consider when calculating returns and covariances, i.e. for the optimization process.
  • Initial Investment: the quantity to be converted into assets
  • Objective: the possibilities are
    • Maximize Sharpe Ratio $\frac{\mu -r_{f}}{\sigma}$
    • Minimum variance
    • Maximum return

As optional parameters

  • Absolute fees: fixed quantity per transaction
  • Relative fee: variable quantity as a percentage of the total amount invested
  • Save: saves the optimized portfolio quantites of each asset and the prices at which theoretically bought in a csv fro further performance studies.
  • At day: day at which calculate the portfolio (to reobtain past results).

Cases

In case a new member appears in the IBEX:

  • Run data_new.py
  • Delete ./csv/data/
  • Run from scratch data.R

If you want to see the gains in a period, execute: python gains.py, and the options are:

  • --init The initial date of the period (like this init=2018-07-13)
  • --end End date of the period

TODO:

  • Add option to carry accountability of assets buyed and price
    • Add option to compute gains in selected period.
    • Correct computation of fees having into account last portfolio configuration.
  • Scrap cmponents from a more reliable web pege.
  • Make the data file more robust to member changes.
  • Add recreator of accuntability in case members change
  • Add more markets: CAC 40, EUROSTOXX 50, S&P500
    • Possibility to mix them or not
  • Develop GUI for easeness of use.
  • Expand data sourcing to python datareader with Tiingo and Quandl

portfolio-optimization's People

Contributors

bcjuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

drroad laranea

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.