Skip to content

kristianbonnici/optifolio

Repository files navigation

Color fonts


PyPI Version License

OptiFolio is a package for portfolio optimization. For optimization, a SciPy optimizer is used, while results can be visualized with Bokeh plots.

The package can also be seamlessly integrated with Yahoo Finance API, using Pandas Data Reader.

Install

OptiFolio can be installed from PyPI:

pip install optifolio

Features

  • PortfolioOptimizer [object]: Optimize your portfolio based on Sharpe Ratio.
    • fit [method]: Fits daily stock data into the optimizer. Generates annual measures.
    • plot_efficient_frontier [method]: Generates a plot for efficient frontier, optimal portfolio, and individual stocks.
    • plot_weights [method]: Creates a pie chart that displays portfolio weights for each ticker.
    • plot_cumulative_return [method]: Generates a time series plot that displays portfolio performance over time.

The figures are generated with Bokeh, enabling easy implementation to modern web browsers.

Quick Start

1. Optimize Portfolio

from optifolio import PortfolioOptimizer

# Data from Yahoo Finance with Pandas Data Reader
import pandas_datareader.data as web
data = web.DataReader(['AMZN', 'AAPL', 'MSFT',
                       'NFLX', 'TSLA', 'BABA', 'JD'],
                       'yahoo',
                       start='2015/01/01',
                       end='2019/12/31')['Adj Close']

# Initiate the optimizer
model = PortfolioOptimizer()

# Optimize (w. max Sharpe Ratio)
model.fit(data, obj='sharpe')

2. Visualize Frontier

model.plot_efficient_frontier()

3. Visualize Portfolio Weights

model.plot_weights()

4. Visualize Cumulative Return

# Adding a benchmark to compare against
benchmark = web.DataReader(['^GSPC'],
                           'yahoo',
                           start='2015/01/01',
                           end='2019/12/31')['Adj Close']


model.plot_cumulative_return(benchmark_data=benchmark)

Author

Kristian Bonnici

🤝 Support

Contributions, issues, and feature requests are welcome!

Give a ⭐️ if you like this project!

About

A Python package for portfolio optimization.

Resources

License

Stars

Watchers

Forks

Packages

No packages published