def plot_assets(self, kind: str = "cagr", pct_values=False):
        if len(self.all_tickers) < 2:
            QMessageBox.critical(
                self, "Ошибка",
                "Невозможно построить график меньше чем с 2 активами",
                QMessageBox.Ok)
            return
        tickers = [ticker + '.US' for ticker in self.all_tickers]
        portfolio = ok.Plots(tickers, ccy='USD')
        risks = portfolio.risk_annual
        returns = portfolio.get_cagr().loc[portfolio.symbols]
        m = 100 if pct_values else 1
        figure_assets = go.Figure()
        asset_labels = portfolio.symbols
        for label, x, y in zip(asset_labels, risks, returns):
            figure_assets.add_trace(
                go.Scatter(x=[x * m],
                           y=[y * m],
                           mode="markers+text",
                           text=label[:-3],
                           marker=dict(size=10),
                           showlegend=False,
                           textposition="top center"))

        efficient = ok.EfficientFrontier(tickers)
        ef = efficient.ef_points
        figure_assets.add_trace(
            go.Scatter(x=ef.Risk,
                       y=ef.CAGR,
                       line=dict(width=3, dash='dash'),
                       name="Граница эффективности",
                       marker=dict(color='black')))
        figure_assets.update_layout(title='Доходность и риск каждого актива',
                                    xaxis_title='Риск',
                                    yaxis_title='Доходность')
        self.ui.browser_page_4.setHtml(
            figure_assets.to_html(include_plotlyjs='cdn'))
        self.ui.stackedWidget_2.setCurrentWidget(self.ui.browser_page_4)
 def plot_transition_map(self):
     if len(self.all_tickers) < 2:
         QMessageBox.critical(
             self, "Ошибка",
             "Невозможно построить график меньше чем с 2 активами",
             QMessageBox.Ok)
         return
     tickers = [ticker + '.US' for ticker in self.all_tickers]
     portfolio = ok.EfficientFrontier(tickers)
     ef = portfolio.ef_points
     fig_transition_map = go.Figure()
     for ticker in tickers:
         fig_transition_map.add_trace(
             go.Scatter(x=ef.Risk,
                        y=ef[ticker],
                        mode='lines',
                        name=ticker[:-3]))
     fig_transition_map.update_layout(title='Weights of stocks',
                                      xaxis_title='Risk (Volatility)',
                                      yaxis_title='Weights')
     self.ui.browser_page_4.setHtml(
         fig_transition_map.to_html(include_plotlyjs='cdn'))
     self.ui.stackedWidget_2.setCurrentWidget(self.ui.browser_page_4)
     pass
Beispiel #3
0
def test_init_efficient_frontier():
    with pytest.raises(Exception,
                       match=r'The number of symbols cannot be less than two'):
        ok.EfficientFrontier(symbols=['MCFTR.INDX'])
Beispiel #4
0
def init_efficient_frontier_bounds(init_efficient_frontier_values):
    bounds = ((0.0, 0.5), (0.0, 1.))
    return ok.EfficientFrontier(**init_efficient_frontier_values,
                                bounds=bounds)
Beispiel #5
0
def init_efficient_frontier(init_efficient_frontier_values):
    return ok.EfficientFrontier(**init_efficient_frontier_values)
Beispiel #6
0
def test_init_efficient_frontier_failing():
    with pytest.raises(ValueError,
                       match=r'The number of symbols cannot be less than two'):
        ok.EfficientFrontier(assets=['MCFTR.INDX'])