Modern Portfolio Theory (MPT) Python package
Project description
Okama
okama is a Python package developed for asset allocation and investment portfolio optimization tasks according to Modern Portfolio Theory (MPT).
The package is supplied with free «end of day» historical stock markets data and macroeconomic indicators through API.
...entities should not be multiplied without necessity
-- William of Ockham (c. 1287–1347)
Okama main features
- Investment portfolio constrained Markowitz Mean-Variance Analysis (MVA) and optimization
- Rebalanced portfolio optimization
- Monte Carlo Simulations for financial assets and investment portfolios
- Popular risk metrics: VAR, CVaR, semi-deviation, variance and drawdowns
- Forecasting models according to normal and lognormal distribution
- 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
- Currencies
- Stock indexes
Macroeconomic indicators
- Inflation
- Central bank rates
Other historical data
- Real estate prices
- Top bank rates
Installation
pip install okama
Getting started
1. Compare several assets from different stock markets. Get USD-adjusted performance
import okama as ok
x = ok.AssetList(['SPY.US', 'BND.US', 'DBXD.XETR'], ccy='USD')
print(x)
Get the main parameters for the set:
x.describe(tickers=False)
Get the assets accumulated return, plot it and compare with the USD inflation:
x.wealth_indexes.plot()
2. Create a dividend stocks portfolio with base currency EUR
import okama.portfolio
weights = [0.3, 0.2, 0.2, 0.2, 0.1]
assets = ['T.US', 'XOM.US', 'FRE.XETR', 'SNW.XETR', 'LKOH.MOEX']
pf = okama.portfolio.Portfolio(assets, weights=weights, ccy='EUR')
print(pf)
Plot the dividend yield for each group of assets (based on stock currency).
pf.dividend_yield.plot()
3. Draw an Efficient Frontier for 2 poular ETF: SPY and GLD
ls = ['SPY.US', 'GLD.US']
curr = 'USD'
frontier = ok.EfficientFrontierReb(ls, last_date='2020-10', ccy=curr, reb_period='year') # Rebalancing periods is one year (dafault value)
frontier.names
Get the Efficient Frontier points for rebalanced portfolios and plot the chart with the assets risk/CAGR points:
points = frontier.ef_points
fig = plt.figure(figsize=(12,6))
fig.subplots_adjust(bottom=0.2, top=1.5)
ok.Plots(ls, ccy=curr).plot_assets(kind='cagr') # plots the assets points on the chart
ax = plt.gca()
ax.plot(points.Risk, points.CAGR)
* - rebalancing period is one year.
4. Get a Transition Map for allocations
ls = ['SPY.US', 'GLD.US', 'BND.US']
map = ok.Plots(ls, ccy='USD').plot_transition_map(cagr=False)
More examples are available in Jupyter Notebooks.
Communication
For basic usage questions (e.g., "Is XXX currency supported by okama?") and for sharing ideas please use GitHub Discussions. Russian language community is available at okama.io forums.
Issues
We encourage you to report issues using the Github tracker. We welcome all kinds of issues, especially those related to correctness, documentation, performance, and feature requests.
Contributing to okama
All contributions, bug reports, bug fixes, documentation improvements, enhancements, frontend implementation and ideas are welcome.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.