DEV Community

Cover image for Open-source in finance. Okama project
Sergey Kikevich
Sergey Kikevich

Posted on

Open-source in finance. Okama project

There is an interesting paradox in fintech projects. It is hardly possible to find an area where more investments come. Therefore, the most advanced technologies are concentrated here: blockchain, AI, big data, etc. On the other hand, in the financial area one can found few well-developed open-source projects. There are such advanced commercial software products as the Bloomberg Terminal, special programming languages that were developed specifically for finance. But on GitHub you can count on the fingers popular open-source financial projects. The availability of financial data also lags other areas. Of course, there is an excellent World Bank open database. No less good is the FRED project of the US Federal Reserve. But such projects are unique and not very common. It is difficult to obtain up-to-date macroeconomic data. The historical market data is available only in paid subscriptions. In the 21st century almost every big company supports open-source projects, makes data available with open APIs... even Microsoft has changed its mind regarding open-source. But in finance, everything remains like it was in the 90s. Why is it so? Perhaps fintech projects are too focused on making quick money. For them, mythical unicorns are more important, and there is simply not enough time for topics like sustainable development.

It seems to me that in financial projects, as well as in any other field, it is time to accept that a competitive edge is not about having some β€œsecret” software and exclusive access to closed databases. The expertise and experience of the person who uses these software products should be the main value. And it is high time to make the data as open and free as possible.

okama project

Our small project is an attempt to bring together all the commonly used financial algorithms for time series and provide them for free along with historical data. We were selecting approaches basing on CFA program for Quantitative Finance. Considering the popularity of the Modern Portfolio Theory and asset allocation, we started with this topic. okama is an open-source package for Python.

Portfolios in okama can include securities with different domestic currencies. All portfolio properties are adjusted to the base currency.

After installing the package (pip install okama) and importing it (import okama as ok) stocks/bonds ETF portfolio one can easily create:

ok.Portfolio(['SPY.US', 'BND.US'])
Enter fullscreen mode Exit fullscreen mode

bonds-stocks portfolio

If not specified all the securities weights are equal. However, it easy to create 60/40 allocation using weights argument:

ok.Portfolio(['SPY.US', 'BND.US'], weights=[.60, .40])
Enter fullscreen mode Exit fullscreen mode

investment portfolio with assets weights

By default, the base currency is USD for portfolio. All risk and return parameteters are calculated in base currency. But you can create portfolios with several popular currencies (EUR, GBP, ILS, RUB etc.) and have all the metrics adjusted.

Let’s add a popular European ETF and set EUR as a base currency of portfolio:

pf = ok.Portfolio(
    ['SPY.US', 'BND.US', 'DBXD.XFRA'], 
    weights=[.40, .30, .30], 
    ccy='EUR'
)
Enter fullscreen mode Exit fullscreen mode

A list of security names, tickers and weights are available in a single table:

pf.table
Enter fullscreen mode Exit fullscreen mode

portfolio assets names and weights

The accumulated return for the portfolio vs inflation:

pf.wealth_index.plot()
Enter fullscreen mode Exit fullscreen mode

accumulated return for the portfolio vs inflation

Summary table with key indicators:

pf.describe()
Enter fullscreen mode Exit fullscreen mode

portfolio summary table with key indicators

Other okama examples are available in Jupyter Notebook format.

The main features of okama:

  • Investment portfolio constrained Markowitz Mean-Variance Analysis (MVA) and optimization
  • Rebalanced portfolio optimization with constraints (multi-period Efficient Frontier)
  • Monte Carlo Simulations for financial assets and investment portfolios
  • Popular risk metrics: VAR, CVaR, semi-deviation, variance and drawdowns
  • Financial ratios: Beta, Sharpe, Sortino etc.
  • 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

Working on the package we were inspired by Portfolio Visualizer project. The idea was to create open-source version with the similar functionality and free international historical data.
okama GitHub page: https://github.com/mbk-dev/okama
Documentation on Read The Docs: https://okama.readthedocs.io

Top comments (0)