DEV Community

Sergey Kikevich
Sergey Kikevich

Posted on

Okama.io: an open-source portfolio-analysis platform — a tour of the tools

On Habr we've written several times about okama, an open-source portfolio-analysis library for Python. But the project has long had a "face" for people who don't write code, too — the okama.io website: a set of free, interactive tools for backtesting portfolios and for analyzing and comparing individual assets, with forecasting. We originally built it as a bit of "fun" and a demo of what the okama library can do. Over time, though, okama.io grew into a project in its own right, used both in Russia and abroad.

The whole site is open-source. It's an application called okama-dash built on Dash (Plotly): the entire product — financial logic, data processing and the interface — is written in Python and released under the MIT license. Under the hood it runs on the same okama library that's also available from code. (The site usually lags a little behind the library, since a non-trivial interface takes time to build, but today that gap is small.)

The data is free end-of-day historical quotes and macro indicators: the NYSE, NASDAQ, MOEX, LSE and other exchanges, plus indices, crypto and fiat currencies, commodities, rates and inflation.

One feature runs through every tool: the entire state of a widget is encoded in the URL. Build a portfolio, adjust the parameters — and you can send the link to anyone, and they'll open the exact same calculation.

The

What follows is a short tour of the site, section by section.

Efficient Frontier

Open in okama.io →

For a given set of assets, the tool builds the efficient frontier: for every level of risk it finds the portfolio with the maximum achievable return. The chart shows the assets themselves (in risk/return coordinates), the cloud of achievable portfolios, and the frontier curve — you can't rise above it. The cloud can be generated randomly (Monte Carlo) or by stepping through a grid of weights; there's also a transition map (how the composition of the optimal portfolio changes along the frontier) and arithmetic- vs geometric-mean modes.

The efficient frontier on okama.io: assets, the cloud of achievable portfolios and the frontier curve

Compare Assets

Open in okama.io →

This section compares several assets against one another over a common historical period. Available views: wealth-index (balance) charts (growth of the invested amount), cumulative and annual return, rolling CAGR, and a correlation matrix. Below the chart is a metrics table: CAGR over various periods, risk (standard deviation), CVAR, maximum drawdowns, the Sharpe ratio and dividend yield.

The example below shows the wealth index of three assets since 2005: the S&P 500 (SPY.US), gold (GLD.US) and the Nasdaq-100 (QQQ.US).

Compare Assets on okama.io: the wealth index of SPY.US, GLD.US and QQQ.US over a common period

Compare with Benchmark

Open in okama.io →

Here assets are compared not with each other but against a benchmark — an index or another asset. It computes tracking difference (cumulative and annualized), tracking error, beta and correlation — over an expanding or rolling window.

Example: the tracking quality of two S&P 500 ETFs — VOO.US (Vanguard) and SPY.US (SPDR) — against the S&P 500 Total Return index. Both funds track the index almost exactly, but VOO.US follows it noticeably more tightly: its annualized lag is about −0.36% versus −0.84% for SPY.US (over the common period since late 2010).

Compare with Benchmark on okama.io: the annualized tracking difference of VOO.US and SPY.US against the S&P 500 Total Return index

Investment Portfolio

Open in okama.io →

The richest section. From assets with given weights it builds a portfolio for which you can: choose a rebalancing strategy; set cash flows — regular contributions and withdrawals (including inflation indexation, percentage-of-balance withdrawals, and dynamic rules); run a Monte Carlo forecast; and find the maximum safe withdrawal for a given horizon. It computes the wealth index, return, drawdowns and a distribution test.

Example — a classic 60/40 portfolio (60% stocks, SPY.US; 40% bonds, AGG.US). The portfolio's line runs between stocks and bonds: a lower return than pure equities, but noticeably smoother — CAGR 8.1%, risk 10.1%, maximum drawdown −32% versus −51% for the S&P 500 alone.

A handy feature of this section: you can carry the portfolio you've built into the neighboring sections (Efficient Frontier, Benchmark, Compare) and analyze it there.

Investment Portfolio on okama.io: the wealth index of a 60/40 portfolio (SPY.US + AGG.US) against its components

Database

Open in okama.io →

A search across okama's entire database: stocks, ETFs, mutual funds, indices, currencies (including crypto), commodities and rates. The database is split into namespaces — exchanges and data types: US (US exchanges), MOEX (Moscow Exchange), LSE (London), XETR/XFRA (Germany), CC (crypto), COMM (commodities), INDX (indices), INFL (inflation), RE (real estate) and others. For each instrument you see the ticker, name, country, exchange, currency, type and ISIN.

The example below is a search for "AAPL" in the US namespace.

Database on okama.io: searching for

Macro

Open in okama.io →

A section of macroeconomic data for various countries, with interactive charts:

  • Inflation — annual, rolling, cumulative and monthly, by country, with the option to overlay central-bank key rates;
  • Central-bank rates — key rates and a real-rate calculation (inflation-adjusted);
  • CAPE10 — the Shiller ratio for 25 countries: a current snapshot and the historical dynamics.

The chart shows rolling 12-month inflation for several countries.

Macro on okama.io: rolling 12-month inflation by country

From simple widgets to a professional tool

okama.io started as a set of very simple widgets: compute a return, draw a chart. Over time it has grown — and today it's a fairly sophisticated tool. The efficient frontier, CVAR, tracking error, cash-flow strategies, distribution backtests and Monte Carlo forecasts — behind each of these calculations is serious financial mathematics, grounded in professional standards used across the industry (for example, the CFA curriculum).

Links

Questions, bug reports and pull requests are welcome — it's an open project.

Top comments (0)