InteractivePortfolioOptimizer

InteractivePortfolioOptimizer#

class sigtech.framework.ui.portfolio_optimizer.InteractivePortfolioOptimizer

Interactive tool for the construction of optimisation problems and the analysis of the results.

The constructor requires the current portfolio and the instrument returns.

Example of usage:

import pandas as pd
import numpy as np
from sigtech.framework.ui.portfolio_optimizer import InteractivePortfolioOptimizer
from sigtech.framework.internal.utils.pandas_helpers import concat

# Create the universe
constituents = sig.obj.get('SPX INDEX').constituents()
dt = constituents.iloc[-1]['trading_datetime']
universe = constituents[constituents['trading_datetime'] == dt]['internal_id'][:10].values.tolist()

# Create the portfolio
pf_ts = pd.Series(index=universe, data=np.linspace(0.1, 1, 10))
pf_ts = pf_ts / pf_ts.sum()

# Create the returns
def rand_returns(last_dt, n):
    return pd.Series(np.random.random(size=n) - .5,
                     index=pd.date_range(last_dt - dtm.timedelta(days=n-1), last_dt, freq='D'))
returns = {stock_id: rand_returns(dt, 100) for stock_id in universe}

int_port_opt = InteractivePortfolioOptimizer(pf_ts, concat(returns, axis=1))
problem = int_port_opt.optimization_problem