Metadata-Version: 2.4
Name: okama
Version: 2.0.1
Summary: Investment portfolio analyzing & optimization tools
License: MIT
License-File: LICENSE.txt
Keywords: finance,investments,efficient frontier,python,optimization
Author: Sergey Kikevich
Author-email: chilango74@gmail.com
Requires-Python: >=3.11,<4.0.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: arch (>=7.2.0)
Requires-Dist: joblib
Requires-Dist: matplotlib (>=3.5.1)
Requires-Dist: pandas (>=2.0.0)
Requires-Dist: pandas-stubs
Requires-Dist: pyarrow (>=13.0.0)
Requires-Dist: requests
Requires-Dist: scipy (>=1.9.0)
Requires-Dist: statsmodels (>=0.14.5)
Project-URL: Documentation, https://okama.readthedocs.io/en/master
Project-URL: Homepage, https://okama.io
Project-URL: Repository, https://github.com/mbk-dev/okama
Description-Content-Type: text/markdown


[![Documentation Status](https://img.shields.io/readthedocs/okama.svg?style=popout)](http://okama.readthedocs.io/)
[![Python](https://img.shields.io/pypi/pyversions/okama.svg)](https://www.python.org/)
[![PyPI Latest Release](https://img.shields.io/pypi/v/okama.svg)](https://pypi.org/project/okama/)
[![Downloads](https://static.pepy.tech/badge/okama)](https://pepy.tech/project/okama)
[![Coverage](https://coveralls.io/repos/github/mbk-dev/okama/badge.svg?branch=master)](https://coveralls.io/github/mbk-dev/okama?branch=master)
[![License](https://img.shields.io/pypi/l/okama.svg)](https://opensource.org/licenses/MIT)
[![Open In Collab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mbk-dev/okama/blob/master/examples/01%20howto.ipynb)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

# Okama

_okama_ is a library with investment portfolio analyzing & optimization tools. CFA recommendations are used in quantitative finance.

_okama_ goes with **free** «end of day» historical stock markets data and macroeconomic indicators through API.
>...entities should not be multiplied without necessity
>
> -- <cite>William of Ockham (c. 1287–1347)</cite>

## Table of contents

- [Okama main features](#okama-main-features)
- [Financial data and macroeconomic indicators](#financial-data-and-macroeconomic-indicators)
  - [End of day historical data](#end-of-day-historical-data)
  - [Macroeconomic indicators](#macroeconomic-indicators)
  - [Other historical data](#other-historical-data)
- [Installation](#installation)
- [Getting started](#getting-started)
- [Documentation](#documentation)
- [Financial Widgets](#financial-widgets)
- [RoadMap](#roadmap)
- [Contributing to okama](#contributing-to-okama)
- [Communication](#communication)

## Okama main features

- Investment portfolio constrained Markowitz Mean-Variance Analysis (MVA) and optimization
- Rebalanced portfolio optimization with constraints (multi-period Efficient Frontier)
- Advanced rebalancing strategies: Rebalancing-bands (threshold-based), Calendar-based or hybrid
- Investment portfolios with complex contributions / withdrawals cash flows (DCF)
- Monte Carlo Simulations for financial assets and investment portfolios
- Forecasting with popular theoretical distributions: normal, lognormal and Student's (T)
- Degrees of freedom optimization for Student's t-distribution to fit well at a given confidence level
- Testing distributions on historical data
- Popular risk metrics: VAR, CVaR, semi-deviation, variance and drawdowns
- Different financial ratios: CAPE10, Sharpe ratio, Sortino ratio, Diversification ratio 
- Dividend yield and other dividend indicators for stocks
- Backtesting and comparing historical performance of broad range of assets and indexes in multiple currencies
- Methods to track the performance of index funds (ETF) and compare them with benchmarks
- Main macroeconomic indicators: inflation, central banks rates
- Matplotlib visualization scripts for the Efficient Frontier, Transition map and assets risk / return performance

## Financial data and macroeconomic indicators

### End of day historical data

- Stocks and ETF for main world markets
- Mutual funds
- Commodities
- Stock indexes

### Currencies

- FX currencies
- Crypto currencies
- Central bank exchange rates

### Macroeconomic indicators
For many countries (China, USA, United Kingdom, European Union, Russia, Israel etc.):  

- Inflation
- Central bank rates
- CAPE10 (Shiller P/E) Cyclically adjusted price-to-earnings ratios

### Other historical data

- Real estate prices
- Top bank rates

## Installation

### Requirements

- Python **3.11** or newer
- Core dependencies: [pandas](https://pandas.pydata.org/), [numpy](https://numpy.org/), [scipy](https://scipy.org/) (plus `matplotlib`, `pyarrow`, `statsmodels`, `arch` and others). See [pyproject.toml](pyproject.toml) for the full list of dependencies and version constraints.

### Install from PyPI

`pip install okama`

### Install the latest development version from GitHub

```python
git clone https://github.com/mbk-dev/okama@dev
poetry install
```


## Getting started

### 1. Compare several assets from different stock markets. Get USD-adjusted performance

```python
import okama as ok

x = ok.AssetList(['SPY.US', 'BND.US', 'DBXD.XFRA'], ccy='USD')
x  # all examples are for Jupyter Notebook/iPython. For raw Python interpreter use 'print(x)' instead.

```
![](../images/images/readmi01.jpg?raw=true) 

Get the main parameters for the set:
```python
x.describe()
```
![](../images/images/readmi02.jpg?raw=true) 

Get the assets accumulated return, plot it and compare with the USD inflation:
```python
x.wealth_indexes.plot()
```
![](../images/images/readmi03.jpg?raw=true) 

### 2. Create a dividend stocks portfolio with base currency EUR

```python
weights = [0.3, 0.2, 0.2, 0.2, 0.1]
assets = ['T.US', 'XOM.US', 'FRE.XFRA', 'SNW.XFRA', 'LKOH.MOEX']
pf = ok.Portfolio(assets, weights=weights, ccy='EUR')
pf.table
```
![](../images/images/readmi04.jpg?raw=true) 

Plot the dividend yield of the portfolio (adjusted to the base currency).

```python
pf.dividend_yield.plot()
```
![](../images/images/readmi05.png?raw=true) 

### 3. Draw an Efficient Frontier for 2 popular ETF: SPY and GLD

```python
ls = ['SPY.US', 'GLD.US']
curr = 'USD'
last_date = '2020-10'
# Rebalancing periods is one year (default value)
frontier = ok.EfficientFrontier(ls, last_date=last_date, ccy=curr, rebalancing_strategy=ok.Rebalance(period='year'))
frontier.names
```
![](../images/images/readmi06.jpg?raw=true) 

Get the Efficient Frontier points for rebalanced portfolios and plot the chart with the assets risk/CAGR points:
```python
import matplotlib.pyplot as plt

points = frontier.ef_points

fig = plt.figure(figsize=(12,6))
fig.subplots_adjust(bottom=0.2, top=1.5)
frontier.plot_assets(kind='cagr')  # plots the assets points on the chart
ax = plt.gca()
ax.plot(points.Risk, points.CAGR) 
```
![](../images/images/readmi07.jpg?raw=true)   
<nowiki>*</nowiki> - *rebalancing period is one year*.

### 4. Get a Transition Map for allocations

```python
ls = ['SPY.US', 'GLD.US', 'BND.US']
ok.EfficientFrontier(ls, ccy='USD').plot_transition_map(x_axe='risk')
```
![](../images/images/readmi08.jpg?v23-11-2020,raw=true "Transition map")  

More examples are available in form of [Jupyter Notebooks](https://github.com/mbk-dev/okama/tree/master/examples).

## Documentation

The official documentation is hosted on readthedocs.org: [https://okama.readthedocs.io/](https://okama.readthedocs.io/)

## Financial Widgets
[okama-dash](https://github.com/mbk-dev/okama-dash) repository has interactive financial widgets (multi-page web application) 
build with _okama_ package and [Dash (plotly)](https://github.com/plotly/dash) framework. Working example is available at 
[okama.io](https://okama.io/).

![](https://github.com/mbk-dev/okama-dash/blob/images/images/main_page.jpg?raw=true) 

## RoadMap

The plan for _okama_ is to add more functions that will be useful to investors and asset managers.

- Add support for a series of investment portfolios (a financial plan comprising multiple investment strategies, each active until a specific date, after which it transitions to another).
- Add multidimensional Monte Carlo with Ledoit-Wolf shrinkage
- Add IRR to PortfolioDCF
- Add Omega ratio to EfficientFrontier and Portfolio classes.
- Add Black-Litterman asset allocation 
- Add different utility functions for optimizers: IRR, portfolio survival period, semi-deviation, VaR, CVaR, drawdowns etc.
- Add more functions based on suggestion of users.

## Contributing to okama

Contributions are *most welcome*. Have a look at the [Contribution Guide](https://github.com/mbk-dev/okama/blob/master/CONTRIBUTING.md) for more.  
Feel free to ask questions on [Discussuions](https://github.com/mbk-dev/okama/discussions).  
As contributors and maintainers to this project, you are expected to abide by okama' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/mbk-dev/okama/blob/master/CODE_OF_CONDUCT.md)

## Communication

For basic usage questions (e.g., "_Is XXX currency supported by okama?_") and for sharing ideas please use [GitHub Discussions](https://github.com/mbk-dev/okama/discussions/3).
Russian language community is available at [okama.io forums](https://community.okama.io).

## License

MIT

