Skip to main content

A comprehensive AI-based library for portfolio optimization

Project description

# Optiquantfolio

Optiquantfolio is a comprehensive library for portfolio optimization. It includes various models such as CAPM, Treynor Ratio, Minimum Variance Portfolio, Robust Optimization, Hierarchical Risk Parity, Genetic Algorithm, and Stochastic Control Models.

## Features

- **CAPM**: Calculate expected returns using the Capital Asset Pricing Model.
- **Treynor Ratio**: Measure the risk-adjusted return of a portfolio.
- **Minimum Variance Portfolio**: Optimize a portfolio to minimize variance.
- **Hierarchical Risk Parity**: Allocate assets using hierarchical clustering.
- **Genetic Algorithm**: Optimize portfolios using genetic algorithms.
- **Stochastic Control**: Optimize portfolios using stochastic control techniques.
- **Robust Optimization**: Perform robust portfolio optimization with uncertainty handling.

## Installation

To install Optiquantfolio, you can use pip:

```bash
pip install optiquantfolio

Usage

Here are some examples of how to use Optiquantfolio for different optimization methods:

CAPM

Input:

  • tickers: List of stock tickers (e.g., ['AAPL', 'MSFT']).
  • risk_free_rate: Risk-free rate (e.g., 0.01).
  • market_ticker: Market index ticker (e.g., '^GSPC').
  • start_date: Start date for data fetching (e.g., '2020-01-01').
  • end_date: End date for data fetching (e.g., '2023-01-01').

Output:

  • Expected return for the portfolio.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='CAPM', tickers=['AAPL', 'MSFT'], risk_free_rate=0.01, market_ticker='^GSPC', start_date='2020-01-01', end_date='2023-01-01')
print(result)

Treynor Ratio

Input:

  • portfolio_return: Return of the portfolio (e.g., 0.05).
  • risk_free_rate: Risk-free rate (e.g., 0.01).
  • portfolio_beta: Beta of the portfolio (e.g., 1.2).

Output:

  • Treynor ratio for the portfolio.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='Treynor', portfolio_return=0.05, risk_free_rate=0.01, portfolio_beta=1.2)
print(result)

Minimum Variance Portfolio

Input:

  • tickers: List of stock tickers (e.g., ['AAPL', 'MSFT', 'GOOG', 'AMZN']).
  • start_date: Start date for data fetching (e.g., '2020-01-01').
  • end_date: End date for data fetching (e.g., '2023-01-01').

Output:

  • Weights for the minimum variance portfolio.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='MVP', tickers=['AAPL', 'MSFT', 'GOOG', 'AMZN'], start_date='2020-01-01', end_date='2023-01-01')
print(result)

Hierarchical Risk Parity

Input:

  • tickers: List of stock tickers (e.g., ['AAPL', 'MSFT', 'GOOG', 'AMZN']).
  • start_date: Start date for data fetching (e.g., '2020-01-01').
  • end_date: End date for data fetching (e.g., '2023-01-01').

Output:

  • Cluster order for hierarchical risk parity.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='HRP', tickers=['AAPL', 'MSFT', 'GOOG', 'AMZN'], start_date='2020-01-01', end_date='2023-01-01')
print(result)

Genetic Algorithm

Input:

  • tickers: List of stock tickers (e.g., ['AAPL', 'MSFT', 'GOOG', 'AMZN']).
  • start_date: Start date for data fetching (e.g., '2020-01-01').
  • end_date: End date for data fetching (e.g., '2023-01-01').

Output:

  • Optimized weights for the portfolio.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='GA', tickers=['AAPL', 'MSFT', 'GOOG', 'AMZN'], start_date='2020-01-01', end_date='2023-01-01')
print(result)

Stochastic Control

Input:

  • tickers: List of stock tickers (e.g., ['AAPL', 'MSFT', 'GOOG', 'AMZN']).
  • start_date: Start date for data fetching (e.g., '2020-01-01').
  • end_date: End date for data fetching (e.g., '2023-01-01').

Output:

  • Optimized portfolio based on stochastic control techniques.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='Stochastic', tickers=['AAPL', 'MSFT', 'GOOG', 'AMZN'], start_date='2020-01-01', end_date='2023-01-01')
print(result)

Robust Optimization

Input:

  • tickers: List of stock tickers (e.g., ['AAPL', 'MSFT', 'GOOG', 'AMZN']).
  • start_date: Start date for data fetching (e.g., '2020-01-01').
  • end_date: End date for data fetching (e.g., '2023-01-01').

Output:

  • Optimized weights for the robust portfolio.
from optiquantfolio import optimize_portfolio

# Example usage
result = optimize_portfolio(method='Robust', tickers=['AAPL', 'MSFT', 'GOOG', 'AMZN'], start_date='2020-01-01', end_date='2023-01-01')
print(result)

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For more information, please contact Jotiraditya Banerjee.

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

optiquantfolio-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Optiquantfolio-0.1.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file optiquantfolio-0.1.1.tar.gz.

File metadata

  • Download URL: optiquantfolio-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.5

File hashes

Hashes for optiquantfolio-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9b0d0d0cc47e57228403d188a05761b24d208e2cf2407cc0dc1ce1c5c3c99356
MD5 ac576ccc426a5f5f44e841d3f549418d
BLAKE2b-256 0bb8aa9af7670f6d39dd5dcb6f120033b39fb140fe985dcec5ed52e8725b581f

See more details on using hashes here.

File details

Details for the file Optiquantfolio-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Optiquantfolio-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.5

File hashes

Hashes for Optiquantfolio-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d99853e2b079ae1453db216bee380649931c6331d2ec109d0157be08f20e4ae8
MD5 456ee09addc3b977f24825103eadb125
BLAKE2b-256 1ea423baa5a6f5c2a7081afa403b63eaa40ccf9fbbf215476e3554f3b9df1cb9

See more details on using hashes here.

Supported by

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