okama


Nameokama JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://okama.io
SummaryInvestment portfolio analyzing & optimization tools
upload_time2024-02-28 07:41:00
maintainer
docs_urlNone
authorSergey Kikevich
requires_python>=3.9,<4.0.0
licenseMIT
keywords finance investments efficient frontier python optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            
[![Documentation Status](https://img.shields.io/readthedocs/okama.svg?style=popout)](http://okama.readthedocs.io/)
[![Python](https://img.shields.io/badge/python-v3-brightgreen.svg)](https://www.python.org/)
[![PyPI Latest Release](https://img.shields.io/pypi/v/okama.svg)](https://pypi.org/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)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# 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)
- Investment portfolios with contributions / withdrawals cash flows (DCF)
- Monte Carlo Simulations for financial assets and investment portfolios
- Popular risk metrics: VAR, CVaR, semi-deviation, variance and drawdowns
- Different financial ratios: CAPE10, Sharpe ratio, Sortino ratio, Diversification ratio 
- Forecasting models according to normal, lognormal and other popular distributions
- Testing distribution on historical data
- 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

`pip install okama`

The latest development version can be installed directly from GitHub:
`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.EfficientFrontierReb(ls, last_date=last_date, ccy=curr, rebalancing_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']
map = 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 Omega ratio to EfficientFrontier, EfficientFrontierReb and Portfolio classes.
- Make complex withdrawals / contributions strategies in Portfolio class.
- Make complex portfolio rebalancing strategies.
- Add Black-Litterman asset allocation 
- Accelerate optimization for multi-period Efficient Frontier: minimize_risk and maximize_risk methods of EfficientFrontierReb class.
- Make a single EfficientFrontier class for all optimizations: single-period or multu-period with rebalancing period as a parameter.
- 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

            

Raw data

            {
    "_id": null,
    "home_page": "https://okama.io",
    "name": "okama",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0.0",
    "maintainer_email": "",
    "keywords": "finance,investments,efficient frontier,python,optimization",
    "author": "Sergey Kikevich",
    "author_email": "chilango74@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ef/b1/846373bc3e3aa68058c8bab22dad54acd2b0752453eb2ec7e0eb3e748883/okama-1.4.0.tar.gz",
    "platform": null,
    "description": "\n[![Documentation Status](https://img.shields.io/readthedocs/okama.svg?style=popout)](http://okama.readthedocs.io/)\n[![Python](https://img.shields.io/badge/python-v3-brightgreen.svg)](https://www.python.org/)\n[![PyPI Latest Release](https://img.shields.io/pypi/v/okama.svg)](https://pypi.org/project/okama/)\n[![Coverage](https://coveralls.io/repos/github/mbk-dev/okama/badge.svg?branch=master)](https://coveralls.io/github/mbk-dev/okama?branch=master)\n[![License](https://img.shields.io/pypi/l/okama.svg)](https://opensource.org/licenses/MIT)\n[![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)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n# Okama\n\n_okama_ is a library with investment portfolio analyzing & optimization tools. CFA recommendations are used in quantitative finance.\n\n_okama_ goes with **free** \u00abend of day\u00bb historical stock markets data and macroeconomic indicators through API.\n>...entities should not be multiplied without necessity\n>\n> -- <cite>William of Ockham (c. 1287\u20131347)</cite>\n\n## Table of contents\n\n- [Okama main features](#okama-main-features)\n- [Financial data and macroeconomic indicators](#financial-data-and-macroeconomic-indicators)\n  - [End of day historical data](#end-of-day-historical-data)\n  - [Macroeconomic indicators](#macroeconomic-indicators)\n  - [Other historical data](#other-historical-data)\n- [Installation](#installation)\n- [Getting started](#getting-started)\n- [Documentation](#documentation)\n- [Financial Widgets](#financial-widgets)\n- [RoadMap](#roadmap)\n- [Contributing to okama](#contributing-to-okama)\n- [Communication](#communication)\n\n## Okama main features\n\n- Investment portfolio constrained Markowitz Mean-Variance Analysis (MVA) and optimization\n- Rebalanced portfolio optimization with constraints (multi-period Efficient Frontier)\n- Investment portfolios with contributions / withdrawals cash flows (DCF)\n- Monte Carlo Simulations for financial assets and investment portfolios\n- Popular risk metrics: VAR, CVaR, semi-deviation, variance and drawdowns\n- Different financial ratios: CAPE10, Sharpe ratio, Sortino ratio, Diversification ratio \n- Forecasting models according to normal, lognormal and other popular distributions\n- Testing distribution on historical data\n- Dividend yield and other dividend indicators for stocks\n- Backtesting and comparing historical performance of broad range of assets and indexes in multiple currencies\n- Methods to track the performance of index funds (ETF) and compare them with benchmarks\n- Main macroeconomic indicators: inflation, central banks rates\n- Matplotlib visualization scripts for the Efficient Frontier, Transition map and assets risk / return performance\n\n## Financial data and macroeconomic indicators\n\n### End of day historical data\n\n- Stocks and ETF for main world markets\n- Mutual funds\n- Commodities\n- Stock indexes\n\n### Currencies\n\n- FX currencies\n- Crypto currencies\n- Central bank exchange rates\n\n### Macroeconomic indicators\nFor many countries (China, USA, United Kingdom, European Union, Russia, Israel etc.):  \n\n- Inflation\n- Central bank rates\n- CAPE10 (Shiller P/E) Cyclically adjusted price-to-earnings ratios\n\n### Other historical data\n\n- Real estate prices\n- Top bank rates\n\n## Installation\n\n`pip install okama`\n\nThe latest development version can be installed directly from GitHub:\n`git clone https://github.com/mbk-dev/okama@dev`\n\n`poetry install`\n\n\n## Getting started\n\n### 1. Compare several assets from different stock markets. Get USD-adjusted performance\n\n```python\nimport okama as ok\n\nx = ok.AssetList(['SPY.US', 'BND.US', 'DBXD.XFRA'], ccy='USD')\nx  # all examples are for Jupyter Notebook/iPython. For raw Python interpreter use 'print(x)' instead.\n\n```\n![](../images/images/readmi01.jpg?raw=true) \n\nGet the main parameters for the set:\n```python\nx.describe()\n```\n![](../images/images/readmi02.jpg?raw=true) \n\nGet the assets accumulated return, plot it and compare with the USD inflation:\n```python\nx.wealth_indexes.plot()\n```\n![](../images/images/readmi03.jpg?raw=true) \n\n### 2. Create a dividend stocks portfolio with base currency EUR\n\n```python\nweights = [0.3, 0.2, 0.2, 0.2, 0.1]\nassets = ['T.US', 'XOM.US', 'FRE.XFRA', 'SNW.XFRA', 'LKOH.MOEX']\npf = ok.Portfolio(assets, weights=weights, ccy='EUR')\npf.table\n```\n![](../images/images/readmi04.jpg?raw=true) \n\nPlot the dividend yield of the portfolio (adjusted to the base currency).\n\n```python\npf.dividend_yield.plot()\n```\n![](../images/images/readmi05.png?raw=true) \n\n### 3. Draw an Efficient Frontier for 2 popular ETF: SPY and GLD\n```python\nls = ['SPY.US', 'GLD.US']\ncurr = 'USD'\nlast_date='2020-10'\n# Rebalancing periods is one year (default value)\nfrontier = ok.EfficientFrontierReb(ls, last_date=last_date, ccy=curr, rebalancing_period='year')\nfrontier.names\n```\n![](../images/images/readmi06.jpg?raw=true) \n\nGet the Efficient Frontier points for rebalanced portfolios and plot the chart with the assets risk/CAGR points:\n```python\nimport matplotlib.pyplot as plt\n\npoints = frontier.ef_points\n\nfig = plt.figure(figsize=(12,6))\nfig.subplots_adjust(bottom=0.2, top=1.5)\nfrontier.plot_assets(kind='cagr')  # plots the assets points on the chart\nax = plt.gca()\nax.plot(points.Risk, points.CAGR) \n```\n![](../images/images/readmi07.jpg?raw=true)   \n<nowiki>*</nowiki> - *rebalancing period is one year*.\n\n### 4. Get a Transition Map for allocations\n```python\nls = ['SPY.US', 'GLD.US', 'BND.US']\nmap = ok.EfficientFrontier(ls, ccy='USD').plot_transition_map(x_axe='risk')\n```\n![](../images/images/readmi08.jpg?v23-11-2020,raw=true \"Transition map\")  \n\nMore examples are available in form of [Jupyter Notebooks](https://github.com/mbk-dev/okama/tree/master/examples).\n\n## Documentation\n\nThe official documentation is hosted on readthedocs.org: [https://okama.readthedocs.io/](https://okama.readthedocs.io/)\n\n## Financial Widgets\n[okama-dash](https://github.com/mbk-dev/okama-dash) repository has interactive financial widgets (multi-page web application) \nbuild with _okama_ package and [Dash (plotly)](https://github.com/plotly/dash) framework. Working example is available at \n[okama.io](https://okama.io/).\n\n![](https://github.com/mbk-dev/okama-dash/blob/images/images/main_page.jpg?raw=true) \n\n## RoadMap\n\nThe plan for _okama_ is to add more functions that will be useful to investors and asset managers.\n\n- Add Omega ratio to EfficientFrontier, EfficientFrontierReb and Portfolio classes.\n- Make complex withdrawals / contributions strategies in Portfolio class.\n- Make complex portfolio rebalancing strategies.\n- Add Black-Litterman asset allocation \n- Accelerate optimization for multi-period Efficient Frontier: minimize_risk and maximize_risk methods of EfficientFrontierReb class.\n- Make a single EfficientFrontier class for all optimizations: single-period or multu-period with rebalancing period as a parameter.\n- Add different utility functions for optimizers: IRR, portfolio survival period, semi-deviation, VaR, CVaR, drawdowns etc.\n- Add more functions based on suggestion of users.\n\n## Contributing to okama\n\nContributions are *most welcome*. Have a look at the [Contribution Guide](https://github.com/mbk-dev/okama/blob/master/CONTRIBUTING.md) for more.  \nFeel free to ask questions on [Discussuions](https://github.com/mbk-dev/okama/discussions).  \nAs 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)\n\n## Communication\n\nFor 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).\nRussian language community is available at [okama.io forums](https://community.okama.io).\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Investment portfolio analyzing & optimization tools",
    "version": "1.4.0",
    "project_urls": {
        "Documentation": "https://okama.readthedocs.io/en/master",
        "Homepage": "https://okama.io",
        "Repository": "https://github.com/mbk-dev/okama"
    },
    "split_keywords": [
        "finance",
        "investments",
        "efficient frontier",
        "python",
        "optimization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc62fa007a65ffa0faae59d6f5dd30e223fee71b8e2ff06ab985e9b1d4755360",
                "md5": "e561b93b20b2c3e9091e9a8ea0297161",
                "sha256": "62d947572912d6cbd8c1e4dbabd35b98428a9cacfe604f675ebce00e53705b9c"
            },
            "downloads": -1,
            "filename": "okama-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e561b93b20b2c3e9091e9a8ea0297161",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0.0",
            "size": 79546,
            "upload_time": "2024-02-28T07:40:57",
            "upload_time_iso_8601": "2024-02-28T07:40:57.751900Z",
            "url": "https://files.pythonhosted.org/packages/cc/62/fa007a65ffa0faae59d6f5dd30e223fee71b8e2ff06ab985e9b1d4755360/okama-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efb1846373bc3e3aa68058c8bab22dad54acd2b0752453eb2ec7e0eb3e748883",
                "md5": "fef752c20b9f6c1ee88a3b84b17ee5a2",
                "sha256": "b9ea35351a1909b43b32df192ea4632e3439c3011059578f2b14cc364b563ef9"
            },
            "downloads": -1,
            "filename": "okama-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fef752c20b9f6c1ee88a3b84b17ee5a2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0.0",
            "size": 71124,
            "upload_time": "2024-02-28T07:41:00",
            "upload_time_iso_8601": "2024-02-28T07:41:00.006754Z",
            "url": "https://files.pythonhosted.org/packages/ef/b1/846373bc3e3aa68058c8bab22dad54acd2b0752453eb2ec7e0eb3e748883/okama-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-28 07:41:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mbk-dev",
    "github_project": "okama",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "okama"
}
        
Elapsed time: 0.21537s