%load_ext autoreload
%autoreload 2
from import_src import *
import numpy as np
from collections import OrderedDict
from src.data.shares import SHARES_DATA
from src.data.portfolio import import_portfolio
from src.efficient_frontier import calculate_efficient_frontier
portfolio = import_portfolio("../data/portfolio.yaml")
portfolio_funds = portfolio.shares[0] if isinstance(portfolio.shares, list) else portfolio.shares
shares = OrderedDict([x for x in SHARES_DATA.items() if x[0] in portfolio_funds.funds])
from_year = 1992
ef = calculate_efficient_frontier(shares=shares, from_year=from_year)
sharpe = np.array([x.sharpe_ratio for x in ef.points])
print('Max Sharpe ratio:', sharpe.max())
Max Sharpe ratio: 1.025568992256552
from src.distribution import calc_distributions_data
from src.display.efficient_frontier import display_efficient_frontier
index_sharpe_max = sharpe.argmax()
portfolio_data = calc_distributions_data(
distribs=[portfolio],
init_amount=1000,
from_year=from_year,
)
display_efficient_frontier(ef, portfolio_data)
from collections import OrderedDict
from src.display.distribution import display_distributions
from src.domain.distribution import *
from src.domain.efficient_frontier import *
from src.efficient_frontier import get_max_return_points_by_volatility_limits, get_point_distribution
keys = list(shares.keys())
vol_limits = [8, 9, 10, 11, 12]
max_by_vol_dict = get_max_return_points_by_volatility_limits(ef, vol_limits)
names = ["Portfolio", *[f'Vol. <{x}%' for x in vol_limits]]
distributions = [portfolio, *[get_point_distribution(x, keys) for x in max_by_vol_dict.values()]]
display_distributions(distributions, names=names)
Portfolio | Vol. <8% | Vol. <9% | Vol. <10% | Vol. <11% | Vol. <12% | |
---|---|---|---|---|---|---|
VTI | 17.5% | 0.21% | 30.42% | 6.37% | 4.16% | 26.3% |
VTV | 10.0% | 9.16% | 19.42% | 4.17% | 13.9% | 8.24% |
VNQ (REIT) | 7.5% | 3.3% | 0.1% | 1.52% | 3.89% | 1.77% |
IJS | 20.0% | 19.48% | 1.97% | 29.49% | 26.3% | 19.94% |
EAFE | 10.0% | 13.98% | 3.57% | 5.94% | 1.14% | 0.11% |
EAFE Small-Cap | 10.0% | 3.12% | 3.25% | 13.76% | 20.38% | 21.6% |
BND | 25.0% | 50.75% | 41.27% | 38.75% | 30.23% | 22.04% |
- | - | - | - | - | - | - |
Mean ret. | 9.12 | 7.96 | 8.54 | 9.13 | 9.5 | 9.99 |
Std | 11.21 | 7.86 | 8.64 | 9.9 | 11.0 | 11.84 |