Skip to main content

optitrader is an opne-source Python package for portfolio optimization.

Project description

Build python Poetry codecov Open in Dev Containers Streamlit pre-commit Pydantic v1 jupyter FastAPI

optitrader

Description

optitrader is an open-source Python package for portfolio optimization and quantitative finance applications. It is meant to provide a comprehensive suite of tools to easily build a custom portfolio, analyze the optimization results and it also supports the trade execution by leveraging Alpaca's Trading API.

Using

Python package: to add and install this package as a dependency of your project, run poetry add optitrader.

Python CLI: to view this app's CLI commands once it's installed, run optitrader --help.

Rest API: to serve this application as a REST API, run docker compose up app and open localhost:8080 in your browser to see the documentation. Within the Dev Container, this is equivalent to running poe api.

Streamlit Dashboard: to use this application from a Streamlit dashboard, run optitrader dashboard. This is equivalent to running poe app and open localhost:8000 in your browser.

Example

Once the package has been installed you can use it as follows:

from optitrader import optitrader
from optitrader.optimization.objectives import CVaRObjectiveFunction
from optitrader.enums import UniverseName

optimal_ptf = Optitrader(
        objectives=[CVaRObjectiveFunction()],
        universe_name=UniverseName.POPULAR_STOCKS,
    ).solve()

# Optimal Portfolio:
Portfolio(
    weights={
        'AAPL': 0.18168,
        'BABA': 0.00369,
        'BRK.B': 0.15119,
        'META': 0.04067,
        'MSFT': 0.01936,
        'ORCL': 0.16028,
        'PFE': 0.00207,
        'TSLA': 0.01057,
        'V': 0.02516,
        'WMT': 0.40532
        }, 
    objective_values={
        'Conditional Value at Risk': 0.007560866163075728
        }
)

and you can use the available methods of the Portfolio class, such as pie_plot:

optimal_ptf.pie_plot()

pie plot result

Contributing

This project has been boostrapped using this cookiecutter template.

Prerequisites
1. Set up Git to use SSH
  1. Generate an SSH key and add the SSH key to your GitHub account.
  2. Configure SSH to automatically load your SSH keys:
    cat << EOF >> ~/.ssh/config
    Host *
      AddKeysToAgent yes
      IgnoreUnknown UseKeychain
      UseKeychain yes
    EOF
    
2. Install Docker
  1. Install Docker Desktop.
3. Install VS Code or PyCharm
  1. Install VS Code and VS Code's Dev Containers extension. Alternatively, install PyCharm.
  2. Optional: install a Nerd Font such as FiraCode Nerd Font and configure VS Code or configure PyCharm to use it.
Development environments

The following development environments are supported:

  1. ⭐️ GitHub Codespaces: click on Code and select Create codespace to start a Dev Container with GitHub Codespaces.
  2. ⭐️ Dev Container (with container volume): click on Open in Dev Containers to clone this repository in a container volume and create a Dev Container with VS Code.
  3. Dev Container: clone this repository, open it with VS Code, and run Ctrl/⌘ + + PDev Containers: Reopen in Container.
  4. PyCharm: clone this repository, open it with PyCharm, and configure Docker Compose as a remote interpreter with the dev service.
  5. Terminal: clone this repository, open it with your terminal, and run docker compose up --detach dev to start a Dev Container in the background, and then run docker compose exec dev zsh to open a shell prompt in the Dev Container.
Developing
  • This project follows the Conventional Commits standard to automate Semantic Versioning and Keep A Changelog with Commitizen.
  • Run poe from within the development environment to print a list of Poe the Poet tasks available to run on this project.
  • Run poetry add {package} from within the development environment to install a run time dependency and add it to pyproject.toml and poetry.lock. Add --group test or --group dev to install a CI or development dependency, respectively.
  • Run poetry update from within the development environment to upgrade all dependencies to the latest versions allowed by pyproject.toml.
  • Run cz bump to bump the package's version, update the CHANGELOG.md, and create a git tag.

Similar projects

optitrader is built by keeping in mind the availability of other great open-source repositories, such as:

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

optitrader-0.0.1.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

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

optitrader-0.0.1-py3-none-any.whl (70.3 kB view details)

Uploaded Python 3

File details

Details for the file optitrader-0.0.1.tar.gz.

File metadata

  • Download URL: optitrader-0.0.1.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.12 Linux/5.15.49-linuxkit

File hashes

Hashes for optitrader-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0b405922e99e4535b8569a2ce311330ab783139cd0ac67d591b0d2392db8c4b3
MD5 b9daae56a5ce02d17430300da07180c5
BLAKE2b-256 6d1d806cbfa6222e2437ab057aad5a54028d1d4607c6c7100c5b018f6606afb9

See more details on using hashes here.

File details

Details for the file optitrader-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: optitrader-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 70.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.12 Linux/5.15.49-linuxkit

File hashes

Hashes for optitrader-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8665d3e16686627a4b71c0f01f6cfd2cef5ce64136f2f22256db3cdd3a5ead3
MD5 bfc12cf61b4cd4df28a31114799cbb0f
BLAKE2b-256 1bdb3d67aa02869ef1f0bd7a6c11d51a300936eb9221993d91af66f51ed69e64

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