Ejemplo n.º 1
0
    def _init_menu_widgets(self):
        self.setObjectName('root')
        self.title = factories.atomic_widget_factory(component='title',
                                                     title=settings.APP_NAME)

        self.function_menu = factories.layout_factory(layout='vertical-box')
        self.function_menu.setObjectName('grand-child')
        self.function_title_container = factories.layout_factory(
            layout='horizontal-box')
        self.function_title = factories.atomic_widget_factory(
            component='heading', title='Functions')
        self.function_hide_button = factories.atomic_widget_factory(
            component='hide-button', title=None)

        self.widget_buttons = [
            factories.atomic_widget_factory(component='button',
                                            title=function['name'])
            for function in definitions.FUNC_WIDGETS.values()
        ]
        self.exit_button = factories.atomic_widget_factory(component='button',
                                                           title="Exit")

        self.function_widgets = [
            function['class']('great-grand-child', self)
            for function in definitions.FUNC_WIDGETS.values()
        ]

        self.display_pane = factories.layout_factory(layout='vertical-box')
        self.display_pane.setObjectName('grand-child')

        self.container_pane = factories.layout_factory(layout='horizontal-box')
        self.container_pane.setObjectName('child')

        self.setLayout(QtWidgets.QVBoxLayout())
Ejemplo n.º 2
0
    def calculate(self):
        if self.table_widget.table.isVisible():
            self.table_widget.table.clear()
            self.table_widget.table.hide()

        symbols = self.arg_widget.get_symbol_input()

        if len(symbols) > 1:
            self.table_widget.init_table(rows=symbols, columns=symbols)

            matrix = statistics.correlation_matrix(
                tickers=symbols,
                start_date=self.arg_widget.get_control_input('start_date'),
                end_date=self.arg_widget.get_control_input('end_date'))
            for i in range(0, len(symbols)):
                for j in range(i, len(symbols)):
                    item_upper = factories.atomic_widget_factory(
                        component='table-item',
                        title=helper.format_float_percent(matrix[i][j]))
                    item_lower = factories.atomic_widget_factory(
                        component='table-item',
                        title=helper.format_float_percent(matrix[j][i]))
                    self.table_widget.table.setItem(j, i, item_upper)
                    self.table_widget.table.setItem(i, j, item_lower)
        else:
            print('error handling goes here')

        self.table_widget.show_table()
        self.arg_widget.fire()
Ejemplo n.º 3
0
 def _init_widgets(self, widget_title: str) -> None:
     self.title_container = factories.layout_factory(
         layout='horizontal-box')
     self.title = factories.atomic_widget_factory(
         component='heading', title=widget_title)
     self.download_button = factories.atomic_widget_factory(
         component='download-button', title=None)
     self.figure = factories.atomic_widget_factory(
         component='figure', title=None)
     self.setLayout(QtWidgets.QVBoxLayout())
Ejemplo n.º 4
0
 def _init_widgets(self, widget_title: str) -> None:
     """Creates child widgets and their layouts"""
     self.title_container = factories.layout_factory(
         layout='horizontal-box')
     self.title = factories.atomic_widget_factory(
         component='heading', title=widget_title)
     self.download_button = factories.atomic_widget_factory(
         component='download-button', title=None)
     self.table = factories.atomic_widget_factory(
         component='table', title=None)
     self.setLayout(QtWidgets.QVBoxLayout())
Ejemplo n.º 5
0
    def _init_widgets(self, mode: str) -> None:
        """
        Creates child widgets by calling factory methods from `scrilla.gui.widgets.factories`. This method will iterate over `self.controls` and initialize the optional input widget accordingly. `self.optional_pane` and `self.required_pane`, the container widgets for the input elements, are initialized with a style tag on the same layer as the `scrilla.gui.widgets.components.ArgumentWidget`.
        """
        self.title = factories.atomic_widget_factory(
            component='subtitle', title='Function Input')
        self.optional_title = factories.atomic_widget_factory(
            component='label', title='Optional Arguments')
        self.error_message = factories.atomic_widget_factory(
            component='error', title="Error Message Goes Here")
        self.calculate_button = factories.atomic_widget_factory(
            component='calculate-button', title='Calculate')
        self.clear_button = factories.atomic_widget_factory(
            component='clear-button', title='Clear')

        if mode == SYMBOLS_LIST:
            self.required_title = factories.atomic_widget_factory(
                component='label', title='Required Arguments')
            self.symbol_hint = factories.atomic_widget_factory(
                component='text', title="Separate Tickers With Commas")
            self.required_pane = factories.layout_factory(
                layout='vertical-box')
            self.required_pane.setObjectName(self.layer)
            self.symbol_widget = factories.argument_widget_factory(
                component='symbols', title="Asset Tickers :", optional=False)
        elif mode == SYMBOLS_SINGLE:
            self.required_title = factories.atomic_widget_factory(
                component='label', title='Required Argument')
            self.symbol_hint = factories.atomic_widget_factory(
                component='text', title="Enter a Single Symbol")
            self.required_pane = factories.layout_factory(
                layout='vertical-box')
            self.required_pane.setObjectName(self.layer)
            self.symbol_widget = factories.argument_widget_factory(
                component='symbol', title="Symbol: ", optional=False)
        else:
            self.symbol_widget = None

        self.group_definitions = None
        for control in self.controls:
            if self.controls[control]:
                if self.controls[control]:
                    if definitions.ARG_DICT[control]["widget_type"] != "group":
                        self.control_widgets[control] = factories.argument_widget_factory(definitions.ARG_DICT[control]['widget_type'],
                                                                                          f'{definitions.ARG_DICT[control]["name"]} :',
                                                                                          optional=True)
                    else:
                        if self.group_definitions is None:
                            self.group_definitions = {}
                        self.group_definitions[definitions.ARG_DICT[control]
                                               ['name']] = definitions.ARG_DICT[control]
            else:
                self.control_widgets[control] = None

        self.optional_pane = factories.layout_factory(layout='vertical-box')
        self.optional_pane.setObjectName(self.layer)
        self.setLayout(QtWidgets.QVBoxLayout())
Ejemplo n.º 6
0
    def optimize(self):
        if self.table_widget.table.isVisible():
            self.table_widget.table.clear()
            self.table_widget.table.hide()

        symbols = self.arg_widget.get_symbol_input()

        # TODO: better error checking
        if len(symbols) > 1:
            investment = self.arg_widget.get_control_input('investment')
            this_portfolio = Portfolio(
                tickers=symbols,
                start_date=self.arg_widget.get_control_input('start_date'),
                end_date=self.arg_widget.get_control_input('end_date'))
            allocation = optimizer.optimize_portfolio_variance(
                portfolio=this_portfolio,
                target_return=self.arg_widget.get_control_input('target'))
            self.title.setText(
                formats.format_allocation_profile_title(
                    allocation, this_portfolio))

            prices = services.get_daily_prices_latest(tickers=symbols)

            if investment is None:
                self.table_widget.init_table(rows=symbols,
                                             columns=['Allocation'])
            else:
                self.table_widget.init_table(rows=symbols,
                                             columns=['Allocation', 'Shares'])
                shares = this_portfolio.calculate_approximate_shares(
                    allocation, float(investment), prices)

            for i in range(len(symbols)):
                item = factories.atomic_widget_factory(
                    component='table-item',
                    title=helper.format_float_percent(allocation[i]))
                self.table_widget.table.setItem(i, 0, item)

                if investment is not None:
                    share_item = factories.atomic_widget_factory(
                        component='table-item', title=str(shares[i]))
                    self.table_widget.table.setItem(i, 1, share_item)

            # TODO: display amount vested per equity
            # TODO: display total portfolio return and volatility
            # TODO: display actual investment
            self.table_widget.show_table()
            self.arg_widget.fire()

        else:
            print('something went wrong')
Ejemplo n.º 7
0
 def show_file_dialog(self) -> None:
     file_path = factories.atomic_widget_factory(
         component='save-dialog', title=f'(*.{settings.IMG_EXT})')
     file_path.selectFile(f'{self.tmp_graph_key}.{settings.IMG_EXT}')
     filename = None
     if file_path.exec_() == QtWidgets.QDialog.Accepted:
         filename = file_path.selectedFiles()
     if filename is not None and len(filename) > 0:
         utilities.download_tmp_to_file(self.tmp_graph_key, filename[0])
Ejemplo n.º 8
0
    def _generate_splash(self):
        self.splash_container = factories.layout_factory(layout='vertical-box')
        self.source_button = factories.atomic_widget_factory(
            component='source-button', title=None)
        self.package_button = factories.atomic_widget_factory(
            component='package-button', title=None)
        self.documentation_button = factories.atomic_widget_factory(
            component='documentation-button', title=None)
        self.splash = factories.atomic_widget_factory(component='splash',
                                                      title=None)

        self.splash_button_panel = factories.layout_factory(
            layout='horizontal-box')

        self.splash_button_panel.layout().addStretch()
        self.splash_button_panel.layout().addWidget(self.source_button)
        self.splash_button_panel.layout().addWidget(self.package_button)
        self.splash_button_panel.layout().addWidget(self.documentation_button)
        self.splash_button_panel.layout().addStretch()
Ejemplo n.º 9
0
 def show_file_dialog(self) -> None:
     file_path = factories.atomic_widget_factory(
         component='save-dialog', title=f'(*.{settings.FILE_EXT})')
     file_path.selectFile(f'table.{settings.FILE_EXT}')
     filename = None
     if file_path.exec_() == QtWidgets.QDialog.Accepted:
         filename = file_path.selectedFiles()
     if filename is not None and len(filename) > 0:
         if settings.FILE_EXT == 'json':
             utilities.download_table_to_json(self.table, filename[0])
Ejemplo n.º 10
0
 def _init_widgets(self):
     self.arg_widget = components.ArgumentWidget(
         calculate_function=self.calculate,
         clear_function=self.clear,
         controls=self.controls,
         layer=utilities.get_next_layer(self.objectName()))
     self.title = factories.atomic_widget_factory(
         component='heading', title='Distribution of Returns')
     self.tab_container = factories.layout_factory(layout='vertical-box')
     self.tab_widget = QtWidgets.QTabWidget()
     self.setLayout(QtWidgets.QHBoxLayout())
Ejemplo n.º 11
0
 def _init_widgets(self):
     self.title = factories.atomic_widget_factory(component='heading',
                                                  title=None)
     self.table_widget = components.TableWidget(
         widget_title="Optimization Results",
         layer=utilities.get_next_layer(self.objectName()))
     self.arg_widget = components.ArgumentWidget(
         calculate_function=self.optimize,
         clear_function=self.clear,
         controls=self.controls,
         layer=utilities.get_next_layer(self.objectName()))
     self.setLayout(QtWidgets.QHBoxLayout())
Ejemplo n.º 12
0
    def _init_widgets(self, widget_title: str, tmp_graph_key: str) -> None:
        """Creates child widgets and their layouts"""
        self.title = factories.atomic_widget_factory(
            component='subtitle', title=widget_title)

        self.table_widget = TableWidget(layer=self.objectName())
        self.graph_widget = GraphWidget(
            tmp_graph_key=tmp_graph_key, layer=self.objectName())

        self.tab_widget = QtWidgets.QTabWidget()

        self.setLayout(QtWidgets.QVBoxLayout())
Ejemplo n.º 13
0
    def calculate(self):
        if self.composite_widget.graph_widget.figure.isVisible():
            self.composite_widget.graph_widget.figure.hide()

        symbols = self.arg_widget.get_symbol_input()

        self.composite_widget.table_widget.init_table(
            rows=symbols,
            columns=['Return', 'Volatility', 'Sharpe', 'Beta', 'Equity Cost'])

        profiles = {}
        for i, symbol in enumerate(symbols):
            profiles[symbol] = statistics.calculate_risk_return(
                ticker=symbol,
                start_date=self.arg_widget.get_control_input('start_date'),
                end_date=self.arg_widget.get_control_input('end_date'))
            profiles[symbol][keys.keys['APP']['PROFILE']
                             ['SHARPE']] = markets.sharpe_ratio(symbol)
            profiles[symbol][keys.keys['APP']['PROFILE']
                             ['BETA']] = markets.market_beta(symbol)
            profiles[symbol][keys.keys['APP']['PROFILE']
                             ['EQUITY']] = markets.cost_of_equity(symbol)

            formatted_profile = formats.format_profile(profiles[symbol])

            for j, statistic in enumerate(formatted_profile.keys()):
                table_item = factories.atomic_widget_factory(
                    component='table-item', title=formatted_profile[statistic])
                self.composite_widget.table_widget.table.setItem(
                    i, j, table_item)

        plotter.plot_profiles(
            symbols=symbols,
            profiles=profiles,
            show=False,
            savefile=
            f'{settings.TEMP_DIR}/{keys.keys["GUI"]["TEMP"]["PROFILE"]}')

        self.composite_widget.graph_widget.set_pixmap()
        self.composite_widget.table_widget.show_table()
        self.arg_widget.fire()
Ejemplo n.º 14
0
    def _generate_menu_bar(self):
        self.menu_bar = factories.atomic_widget_factory(component='menu-bar',
                                                        title=None)
        self.menus = []

        for j, menu in enumerate(definitions.MENUBAR_WIDGET):
            self.menus.append(self.menu_bar.addMenu(menu))
            for i, action in enumerate(definitions.MENUBAR_WIDGET[menu]):
                q_action = QtGui.QAction(action['name'], self)
                q_action.setShortcut(action['shortcut'])
                if menu == 'Functions':
                    q_action.triggered.connect(
                        (lambda i: lambda: self._show_widget(i))(i))
                elif menu == 'Account':
                    pass
                elif menu == 'View':
                    if action['name'] == 'Function Menu':
                        q_action.triggered.connect(
                            lambda: self.function_menu.setVisible(
                                (not self.function_menu.isVisible())))
                    elif action['name'] == 'Splash Menu':
                        q_action.triggered.connect(self._clear)

                self.menus[j].addAction(q_action)