Example #1
0
    def init_ui(self):
        self.setWindowTitle("策略执行回顾")
        self.resize(1100, 600)

        self.datetime_from = QtWidgets.QDateTimeEdit()
        self.datetime_to = QtWidgets.QDateTimeEdit()
        today = dt.date.today()
        self.datetime_from.setDateTime(
            dt.datetime(year=today.year, month=today.month, day=today.day))
        self.datetime_to.setDateTime(
            dt.datetime(year=today.year,
                        month=today.month,
                        day=today.day,
                        hour=23,
                        minute=59))
        # self.query_btn = QtWidgets.QPushButton("查询")
        self.skip_checkbox = QtWidgets.QCheckBox('AutoSkip')
        self.skip_checkbox.setToolTip('自动过滤未平仓订单')
        self.skip_checkbox.clicked.connect(self.update_strategy_data)
        self.datetime_from.editingFinished.connect(self.update_strategy_data)
        self.datetime_to.editingFinished.connect(self.update_strategy_data)
        # self.query_btn.clicked.connect(self.update_strategy_data)

        self.tab = QtWidgets.QTabWidget()
        self.strategy_monitor = StrategyMonitor(self.main_engine,
                                                self.event_engine)
        self.strategy_monitor.cellDoubleClicked.connect(self.show_trade_chart)
        # self.strategy_monitor.cellClicked.connect(self.check_strategies)
        self.strategy_monitor.resize(1000, 600)
        self.tab.addTab(self.strategy_monitor, '策略统计')

        self.trade = TradeChartDialog(self.main_engine, self.event_engine)

        time_hbox = QtWidgets.QHBoxLayout()
        time_hbox.addWidget(self.datetime_from, 3)
        time_hbox.addWidget(self.datetime_to, 3)
        time_hbox.addWidget(self.skip_checkbox, 1)
        # time_hbox.addWidget(self.query_btn, 1)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(time_hbox)
        vbox.addWidget(self.tab)
        self.setLayout(vbox)

        self.update_strategy_data()
Example #2
0
    def init_ui(self) -> None:
        """"""
        self.setWindowTitle("K线图表")

        self.tab: QtWidgets.QTabWidget = QtWidgets.QTabWidget()
        self.symbol_line: QtWidgets.QLineEdit = QtWidgets.QLineEdit()

        self.button = QtWidgets.QPushButton("新建图表")
        self.button.clicked.connect(self.new_chart)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(QtWidgets.QLabel("本地代码"))
        hbox.addWidget(self.symbol_line)
        hbox.addWidget(self.button)
        hbox.addStretch()

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox)
        vbox.addWidget(self.tab)

        self.setLayout(vbox)
Example #3
0
    def init_ui(self):
        """"""
        self.setWindowTitle("算法交易")

        # Left side control widgets
        self.template_combo = QtWidgets.QComboBox()
        self.template_combo.currentIndexChanged.connect(self.show_algo_widget)

        form = QtWidgets.QFormLayout()
        form.addRow("算法", self.template_combo)
        widget = QtWidgets.QWidget()
        widget.setLayout(form)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(widget)

        for algo_template in self.algo_engine.algo_templates.values():
            widget = AlgoWidget(self.algo_engine, algo_template)
            vbox.addWidget(widget)

            template_name = algo_template.__name__
            display_name = algo_template.display_name

            self.algo_widgets[template_name] = widget
            self.template_combo.addItem(display_name, template_name)

        vbox.addStretch()

        stop_all_button = QtWidgets.QPushButton("全部停止")
        stop_all_button.setFixedHeight(stop_all_button.sizeHint().height() * 2)
        stop_all_button.clicked.connect(self.algo_engine.stop_all)

        vbox.addWidget(stop_all_button)

        # Right side monitor widgets
        active_algo_monitor = ActiveAlgoMonitor(self.algo_engine,
                                                self.event_engine)
        inactive_algo_monitor = InactiveAlgoMonitor(self.algo_engine,
                                                    self.event_engine)
        tab1 = QtWidgets.QTabWidget()
        tab1.addTab(active_algo_monitor, "执行中")
        tab1.addTab(inactive_algo_monitor, "已结束")

        log_monitor = LogMonitor(self.event_engine)
        tab2 = QtWidgets.QTabWidget()
        tab2.addTab(log_monitor, "日志")

        setting_monitor = SettingMonitor(self.algo_engine, self.event_engine)
        setting_monitor.use_signal.connect(self.use_setting)
        tab3 = QtWidgets.QTabWidget()
        tab3.addTab(setting_monitor, "配置")

        grid = QtWidgets.QGridLayout()
        grid.addWidget(tab1, 0, 0, 1, 2)
        grid.addWidget(tab2, 1, 0)
        grid.addWidget(tab3, 1, 1)

        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addLayout(vbox)
        hbox2.addLayout(grid)
        self.setLayout(hbox2)

        self.show_algo_widget()
Example #4
0
    def init_ui(self) -> None:
        """"""
        self.setWindowTitle("波动率管理")

        tab = QtWidgets.QTabWidget()
        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(tab)
        self.setLayout(vbox)

        self.chain_symbols = list(self.portfolio.chains.keys())
        self.chain_symbols.sort()

        for chain_symbol in self.chain_symbols:
            chain = self.portfolio.get_chain(chain_symbol)

            table = QtWidgets.QTableWidget()
            table.setEditTriggers(table.NoEditTriggers)
            table.verticalHeader().setVisible(False)
            table.setColumnCount(4)
            table.setRowCount(len(chain.indexes))
            table.setHorizontalHeaderLabels(["行权价", "中值隐波", "定价隐波", "执行拟合"])
            table.horizontalHeader().setSectionResizeMode(
                QtWidgets.QHeaderView.Stretch)

            for row, index in enumerate(chain.indexes):
                index_cell = IndexCell(index)
                mid_impv_cell = MonitorCell("")

                set_func = partial(self.set_pricing_impv,
                                   chain_symbol=chain_symbol,
                                   index=index)
                pricing_impv_spin = VolatilityDoubleSpinBox()
                pricing_impv_spin.setAlignment(QtCore.Qt.AlignCenter)
                pricing_impv_spin.valueChanged.connect(set_func)

                check = QtWidgets.QCheckBox()

                check_hbox = QtWidgets.QHBoxLayout()
                check_hbox.setAlignment(QtCore.Qt.AlignCenter)
                check_hbox.addWidget(check)

                check_widget = QtWidgets.QWidget()
                check_widget.setLayout(check_hbox)

                table.setItem(row, 0, index_cell)
                table.setItem(row, 1, mid_impv_cell)
                table.setCellWidget(row, 2, pricing_impv_spin)
                table.setCellWidget(row, 3, check_widget)

                cells = {
                    "mid_impv": mid_impv_cell,
                    "pricing_impv": pricing_impv_spin,
                    "check": check
                }

                self.cells[(chain_symbol, index)] = cells

            reset_func = partial(self.reset_pricing_impv,
                                 chain_symbol=chain_symbol)
            button_reset = QtWidgets.QPushButton("重置")
            button_reset.clicked.connect(reset_func)

            fit_func = partial(self.fit_pricing_impv,
                               chain_symbol=chain_symbol)
            button_fit = QtWidgets.QPushButton("拟合")
            button_fit.clicked.connect(fit_func)

            increase_func = partial(self.increase_pricing_impv,
                                    chain_symbol=chain_symbol)
            button_increase = QtWidgets.QPushButton("+0.1%")
            button_increase.clicked.connect(increase_func)

            decrease_func = partial(self.decrease_pricing_impv,
                                    chain_symbol=chain_symbol)
            button_decrease = QtWidgets.QPushButton("-0.1%")
            button_decrease.clicked.connect(decrease_func)

            hbox = QtWidgets.QHBoxLayout()
            hbox.addWidget(button_reset)
            hbox.addWidget(button_fit)
            hbox.addWidget(button_increase)
            hbox.addWidget(button_decrease)

            vbox = QtWidgets.QVBoxLayout()
            vbox.addLayout(hbox)
            vbox.addWidget(table)

            chain_widget = QtWidgets.QWidget()
            chain_widget.setLayout(vbox)
            tab.addTab(chain_widget, chain_symbol)

            self.update_pricing_impv(chain_symbol)

            self.default_foreground = mid_impv_cell.foreground()
            self.default_background = mid_impv_cell.background()

            table.resizeRowsToContents()