def init_ui(self): """""" self.setWindowTitle("CTA live trading") # Create widgets self.class_combo = QtWidgets.QComboBox() add_button = QtWidgets.QPushButton("Add strategy") add_button.clicked.connect(self.add_strategy) init_button = QtWidgets.QPushButton("Prepare All") init_button.clicked.connect(self.cta_engine.init_all_strategies) start_button = QtWidgets.QPushButton("Start All") start_button.clicked.connect(self.cta_engine.start_all_strategies) stop_button = QtWidgets.QPushButton("Stop All") stop_button.clicked.connect(self.cta_engine.stop_all_strategies) clear_button = QtWidgets.QPushButton("Clear log") clear_button.clicked.connect(self.clear_log) self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) self.log_monitor = LogMonitor(self.main_engine, self.event_engine) self.stop_order_monitor = StopOrderMonitor( self.main_engine, self.event_engine ) # Set layout hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(self.class_combo) hbox1.addWidget(add_button) hbox1.addStretch() hbox1.addWidget(init_button) hbox1.addWidget(start_button) hbox1.addWidget(stop_button) hbox1.addWidget(clear_button) grid = QtWidgets.QGridLayout() grid.addWidget(scroll_area, 0, 0, 2, 1) grid.addWidget(self.stop_order_monitor, 0, 1) grid.addWidget(self.log_monitor, 1, 1) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(grid) self.setLayout(vbox)
def init_ui(self) -> None: """""" self.setWindowTitle("组合策略") # Create widgets self.class_combo = QtWidgets.QComboBox() add_button = QtWidgets.QPushButton("添加策略") add_button.clicked.connect(self.add_strategy) init_button = QtWidgets.QPushButton("全部初始化") init_button.clicked.connect(self.strategy_engine.init_all_strategies) start_button = QtWidgets.QPushButton("全部启动") start_button.clicked.connect(self.strategy_engine.start_all_strategies) stop_button = QtWidgets.QPushButton("全部停止") stop_button.clicked.connect(self.strategy_engine.stop_all_strategies) clear_button = QtWidgets.QPushButton("清空日志") clear_button.clicked.connect(self.clear_log) self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) self.log_monitor = LogMonitor(self.main_engine, self.event_engine) # Set layout hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(self.class_combo) hbox1.addWidget(add_button) hbox1.addStretch() hbox1.addWidget(init_button) hbox1.addWidget(start_button) hbox1.addWidget(stop_button) hbox1.addWidget(clear_button) hbox2 = QtWidgets.QHBoxLayout() hbox2.addWidget(scroll_area) hbox2.addWidget(self.log_monitor) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(hbox2) self.setLayout(vbox)
def init_ui(self): """""" self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(scroll_area) self.setLayout(vbox)
def init_ui(self): """""" form = QtWidgets.QFormLayout() # Add vt_symbol and name edit if add new strategy if self.class_name: self.setWindowTitle(f"添加策略:{self.class_name}") button_text = "添加" parameters = {"strategy_name": "", "vt_symbol": ""} parameters.update(self.parameters) else: self.setWindowTitle(f"参数编辑:{self.strategy_name}") button_text = "确定" parameters = self.parameters for name, value in parameters.items(): type_ = type(value) edit = QtWidgets.QLineEdit(str(value)) if type_ is int: validator = QtGui.QIntValidator() edit.setValidator(validator) elif type_ is float: validator = QtGui.QDoubleValidator() edit.setValidator(validator) form.addRow(f"{name} {type_}", edit) self.edits[name] = (edit, type_) button = QtWidgets.QPushButton(button_text) button.clicked.connect(self.accept) form.addRow(button) widget = QtWidgets.QWidget() widget.setLayout(form) scroll = QtWidgets.QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(widget) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(scroll) self.setLayout(vbox)
def init_ui(self): """""" QLabel = QtWidgets.QLabel self.target_combo = QtWidgets.QComboBox() self.target_combo.addItems(list(self.DISPLAY_NAME_MAP.keys())) grid = QtWidgets.QGridLayout() grid.addWidget(QLabel("目标"), 0, 0) grid.addWidget(self.target_combo, 0, 1, 1, 3) grid.addWidget(QLabel("参数"), 1, 0) grid.addWidget(QLabel("开始"), 1, 1) grid.addWidget(QLabel("步进"), 1, 2) grid.addWidget(QLabel("结束"), 1, 3) # Add vt_symbol and name edit if add new strategy self.setWindowTitle(f"优化参数配置:{self.class_name}") validator = QtGui.QDoubleValidator() row = 2 for name, value in self.parameters.items(): type_ = type(value) if type_ not in [int, float]: continue start_edit = QtWidgets.QLineEdit(str(value)) step_edit = QtWidgets.QLineEdit(str(1)) end_edit = QtWidgets.QLineEdit(str(value)) for edit in [start_edit, step_edit, end_edit]: edit.setValidator(validator) grid.addWidget(QLabel(name), row, 0) grid.addWidget(start_edit, row, 1) grid.addWidget(step_edit, row, 2) grid.addWidget(end_edit, row, 3) self.edits[name] = { "type": type_, "start": start_edit, "step": step_edit, "end": end_edit } row += 1 parallel_button = QtWidgets.QPushButton("多进程优化") parallel_button.clicked.connect(self.generate_parallel_setting) grid.addWidget(parallel_button, row, 0, 1, 4) row += 1 ga_button = QtWidgets.QPushButton("遗传算法优化") ga_button.clicked.connect(self.generate_ga_setting) grid.addWidget(ga_button, row, 0, 1, 4) widget = QtWidgets.QWidget() widget.setLayout(grid) scroll = QtWidgets.QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(widget) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(scroll) self.setLayout(vbox)
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()
def init_ui(self) -> None: """""" self.setWindowTitle("市场雷达") self.radar_monitor = RadarMonitor(self.radar_engine) self.signal_monitor = SignalMonitor(self.radar_engine) self.log_monitor = QtWidgets.QTextEdit() self.log_monitor.setReadOnly(True) self.name_line = QtWidgets.QLineEdit() self.formula_line = QtWidgets.QLineEdit() self.a_line = QtWidgets.QLineEdit() self.b_line = QtWidgets.QLineEdit() self.c_line = QtWidgets.QLineEdit() self.d_line = QtWidgets.QLineEdit() self.e_line = QtWidgets.QLineEdit() self.ndigits_spin = QtWidgets.QSpinBox() self.ndigits_spin.setMinimum(0) self.ndigits_spin.setValue(2) add_button = QtWidgets.QPushButton("添加") add_button.clicked.connect(self.add_rule) add_button.setFixedHeight(add_button.sizeHint().height() * 2) edit_button = QtWidgets.QPushButton("修改") edit_button.clicked.connect(self.edit_rule) edit_button.setFixedHeight(edit_button.sizeHint().height() * 2) load_button = QtWidgets.QPushButton("导入CSV") load_button.clicked.connect(self.load_csv) form = QtWidgets.QFormLayout() form.addRow("名称", self.name_line) form.addRow("公式", self.formula_line) form.addRow("A", self.a_line) form.addRow("B", self.b_line) form.addRow("C", self.c_line) form.addRow("D", self.d_line) form.addRow("E", self.e_line) form.addRow("小数", self.ndigits_spin) form.addRow(add_button) form.addRow(edit_button) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addStretch() vbox.addWidget(load_button) left_widget = QtWidgets.QWidget() left_widget.setLayout(vbox) left_widget.setFixedWidth(300) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(left_widget) hbox.addWidget(self.signal_monitor) hbox.addWidget(self.log_monitor) vbox2 = QtWidgets.QVBoxLayout() vbox2.addWidget(self.radar_monitor) vbox2.addLayout(hbox) self.setLayout(vbox2)
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()
def init_ui(self): """""" self.setWindowTitle("pytdx载入") # self.setFixedWidth(600) self.setWindowFlags((self.windowFlags() | QtCore.Qt.CustomizeWindowHint) & ~QtCore.Qt.WindowMaximizeButtonHint) hbox_layout = QtWidgets.QHBoxLayout() load_button = QtWidgets.QPushButton("载入数据.to_db") load_button.clicked.connect(self.load_data) to_csv_button = QtWidgets.QPushButton("载入数据.to_csv") to_csv_button.clicked.connect(self.load_data) self.symbol_type = QtWidgets.QLineEdit("L8") self.symbol_combo = QtWidgets.QComboBox() self.exchange_combo = QtWidgets.QComboBox() for i in Exchange: self.exchange_combo.addItem(str(i.name), i) self.exchange_combo.activated[str].connect(self.onExchangeActivated) self.interval_combo = QtWidgets.QComboBox() for i in Interval: self.interval_combo.addItem(str(i.name), i) self.datetime_edit = QtWidgets.QLineEdit("Datetime") self.open_edit = QtWidgets.QLineEdit("Open") self.high_edit = QtWidgets.QLineEdit("High") self.low_edit = QtWidgets.QLineEdit("Low") self.close_edit = QtWidgets.QLineEdit("Close") self.volume_edit = QtWidgets.QLineEdit("Volume") self.open_interest_edit = QtWidgets.QLineEdit("OpenInterest") self.format_edit = QtWidgets.QLineEdit("%Y-%m-%d %H:%M:%S") info_label = QtWidgets.QLabel("合约信息") info_label.setAlignment(QtCore.Qt.AlignCenter) head_label = QtWidgets.QLabel("表头信息") head_label.setAlignment(QtCore.Qt.AlignCenter) format_label = QtWidgets.QLabel("格式信息") format_label.setAlignment(QtCore.Qt.AlignCenter) save_progress_label = QtWidgets.QLabel("保存进度信息") save_progress_label.setAlignment(QtCore.Qt.AlignCenter) save_progress_bar = QtWidgets.QProgressBar() save_progress_bar.setAlignment(QtCore.Qt.AlignCenter) self.progress_bar_dict['save_progress_bar'] = save_progress_bar form_left = QtWidgets.QFormLayout() form_left.addRow(QtWidgets.QLabel()) form_left.addRow(info_label) form_left.addRow("交易所", self.exchange_combo) form_left.addRow("代码", self.symbol_combo) form_left.addRow("类型\n(L8主连/L9指数/2006)", self.symbol_type) form_left.addRow("周期", self.interval_combo) form_left.addRow(QtWidgets.QLabel()) form_left.addRow(head_label) form_left.addRow("时间戳", self.datetime_edit) form_left.addRow("开盘价", self.open_edit) form_left.addRow("最高价", self.high_edit) form_left.addRow("最低价", self.low_edit) form_left.addRow("收盘价", self.close_edit) form_left.addRow("成交量", self.volume_edit) form_left.addRow("持仓量", self.open_interest_edit) form_left.addRow(QtWidgets.QLabel()) form_left.addRow(format_label) form_left.addRow("时间格式", self.format_edit) form_left.addRow(QtWidgets.QLabel()) form_left.addRow(save_progress_label) form_left.addRow(save_progress_bar) form_left.addRow(load_button) form_left.addRow(to_csv_button) form_left_widget = QtWidgets.QWidget() form_left_widget.setLayout(form_left) form_right_layout = QtWidgets.QFormLayout() # form_right_layout.addRow(QtWidgets.QLabel()) # form_right_layout.addRow(info_label) # form_right_layout.addRow("交易所", self.exchange_combo) # form_right_layout.addRow("代码", self.symbol_combo) # form_right_layout.addRow("类型\n(L8主连/L9指数/2006)", self.symbol_type) # form_right_layout.addRow("周期", self.interval_combo) # form_right_layout.addRow(QtWidgets.QLabel()) # form_right_layout.addRow(head_label) # form_right_layout.addRow("时间戳", self.datetime_edit) # form_right_layout.addRow("开盘价", self.open_edit) # form_right_layout.addRow("最高价", self.high_edit) # form_right_layout.addRow("最低价", self.low_edit) # form_right_layout.addRow("收盘价", self.close_edit) # form_right_layout.addRow("成交量", self.volume_edit) # form_right_layout.addRow("持仓量", self.open_interest_edit) form_right_widget = QtWidgets.QWidget() form_right_widget.setLayout(form_right_layout) hbox_layout.addStretch(1) hbox_layout.addWidget(form_left_widget) hbox_layout.addWidget(form_right_widget) self.setLayout(hbox_layout)
def init_ui(self): """""" self.setWindowTitle("CTA策略") # Create widgets self.class_combo = QtWidgets.QComboBox() add_button = QtWidgets.QPushButton("添加策略") add_button.clicked.connect(self.add_strategy) init_button = QtWidgets.QPushButton("全部初始化") init_button.clicked.connect(self.cta_engine.init_all_strategies) start_button = QtWidgets.QPushButton("全部启动") start_button.clicked.connect(self.cta_engine.start_all_strategies) recover_button = QtWidgets.QPushButton("全部恢复") recover_button.clicked.connect(self.cta_engine.recover_all_strategies) cover_pos_button = QtWidgets.QPushButton("全部平仓") cover_pos_button.clicked.connect( self.cta_engine.close_all_strategies_pos) stop_button = QtWidgets.QPushButton("全部停止") stop_button.clicked.connect(self.cta_engine.stop_all_strategies) clear_button = QtWidgets.QPushButton("清空日志") clear_button.clicked.connect(self.clear_log) self.scroll_layout = QtWidgets.QVBoxLayout() self.scroll_layout.addStretch() scroll_widget = QtWidgets.QWidget() scroll_widget.setLayout(self.scroll_layout) scroll_area = QtWidgets.QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(scroll_widget) self.log_monitor = LogMonitor(self.main_engine, self.event_engine) self.stop_order_monitor = StopOrderMonitor(self.main_engine, self.event_engine) # Set layout hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(self.class_combo) hbox1.addWidget(add_button) hbox1.addStretch() hbox1.addWidget(init_button) hbox1.addWidget(start_button) hbox1.addWidget(recover_button) hbox1.addWidget(cover_pos_button) hbox1.addWidget(stop_button) hbox1.addWidget(clear_button) grid = QtWidgets.QGridLayout() grid.addWidget(scroll_area, 0, 0, 2, 1) grid.addWidget(self.stop_order_monitor, 0, 1) grid.addWidget(self.log_monitor, 1, 1) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(grid) self.setLayout(vbox)