Skip to main content

OptiFolio is a Python package for portfolio optimization.

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optifolio-0.5.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

optifolio-0.5.0-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file optifolio-0.5.0.tar.gz.

File metadata

  • Download URL: optifolio-0.5.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.2

File hashes

Hashes for optifolio-0.5.0.tar.gz
Algorithm Hash digest
SHA256 98fd0d8cb9664d890165192ff9a3472989f07b3031464d6a5d4c3232fae4f8ff
MD5 f88ac8262233806c560823f2bd3f808e
BLAKE2b-256 8943bc39f5bfc3b16b65eccd535c443351627da1ab987755bad57ceeb51776c5

See more details on using hashes here.

File details

Details for the file optifolio-0.5.0-py2.py3-none-any.whl.

File metadata

  • Download URL: optifolio-0.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.2

File hashes

Hashes for optifolio-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 878387fdaf0c0c48f0869811c7d5535c72ffbd1e0285ff1be23b01f9be0ea27c
MD5 860ccd2279875f0fa5ab5f6521df0219
BLAKE2b-256 92d21c3ed5637febb00f798be6a8a62021f5d192b155fe7b43309cc0d3d628f3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page