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("市场雷达") self.radar_monitor = RadarMonitor(self.radar_engine) self.log_monitor = QtWidgets.QTextEdit() self.log_monitor.setReadOnly(True) self.log_monitor.setMaximumHeight(300) 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) edit_button = QtWidgets.QPushButton("修改") edit_button.clicked.connect(self.edit_rule) 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.addWidget(self.log_monitor) vbox.addWidget(load_button) hbox = QtWidgets.QHBoxLayout() hbox.addLayout(form) hbox.addStretch() hbox.addLayout(vbox) vbox2 = QtWidgets.QVBoxLayout() vbox2.addWidget(self.radar_monitor) vbox2.addLayout(hbox) self.setLayout(vbox2)
def init_ui(self) -> None: self.setWindowTitle("Delta对冲") self.setMaximumSize(1440, 800) self.hedge_monitor = HedgeMonitor(self.option_engine) self.strategy_order_monitor = StrategyOrderMonitor( self.main_engine, self.event_engine) self.log_monitor = QtWidgets.QTextEdit() self.log_monitor.setReadOnly(True) self.log_monitor.setMaximumWidth(300) start_hedge_button = QtWidgets.QPushButton("全部启动") start_hedge_button.clicked.connect(self.start_for_all) stop_hedge_button = QtWidgets.QPushButton("全部停止") stop_hedge_button.clicked.connect(self.stop_for_all) self.offset_percent = OffsetPercentSpinBox() self.hedge_percent = HedgePercentSpinBox() offset_percent_btn = QtWidgets.QPushButton("设置") offset_percent_btn.clicked.connect(self.set_offset_percent) hedge_percent_btn = QtWidgets.QPushButton("设置") hedge_percent_btn.clicked.connect(self.set_hedge_percent) QLabel = QtWidgets.QLabel grid = QtWidgets.QGridLayout() grid.addWidget(QLabel("偏移比例"), 0, 0) grid.addWidget(self.offset_percent, 0, 1) grid.addWidget(offset_percent_btn, 0, 2) grid.addWidget(QLabel("对冲比例"), 1, 0) grid.addWidget(self.hedge_percent, 1, 1) grid.addWidget(hedge_percent_btn, 1, 2) left_vbox = QtWidgets.QVBoxLayout() left_vbox.addWidget(self.hedge_monitor) left_vbox.addWidget(self.strategy_order_monitor) ctrl_btn_hbox = QtWidgets.QHBoxLayout() ctrl_btn_hbox.addWidget(start_hedge_button) ctrl_btn_hbox.addWidget(stop_hedge_button) right_vbox = QtWidgets.QVBoxLayout() right_vbox.addLayout(ctrl_btn_hbox) right_vbox.addLayout(grid) right_vbox.addWidget(self.log_monitor) hbox = QtWidgets.QHBoxLayout() hbox.addLayout(left_vbox) hbox.addLayout(right_vbox) self.setLayout(hbox)
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.setWindowTitle("K线图表") self.resize(1400, 800) self.chart = MarketDataChartWidget() self.contract_combo = QtWidgets.QComboBox() self.contracts = { c.vt_symbol: c for c in self.main_engine.get_all_contracts() } self.contract_combo.addItems(self.contracts.keys()) self.contract_combo.setCurrentIndex(-1) self.contract_combo.currentTextChanged.connect(self.change_contract) self.interval_combo = QtWidgets.QComboBox() self.interval_combo.addItems([Interval.MINUTE.value]) self.indicator_combo = QtWidgets.QComboBox() self.indicator_combo.addItems( [n for n in self.chart.indicators.keys()]) self.indicator_combo.currentTextChanged.connect( self.chart.change_indicator) self.previous_btn = QtWidgets.QPushButton("←") self.previous_btn.released.connect( partial(self.update_previous_bar, 300)) form = QtWidgets.QFormLayout() form.addRow("合约", self.contract_combo) form.addRow("周期", self.interval_combo) form.addRow("指标", self.indicator_combo) form.addRow(self.previous_btn) self.tick_info = InfoWidget() # Set layout box = QtWidgets.QHBoxLayout() vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addWidget(self.chart) infoBox = QtWidgets.QVBoxLayout() infoBox.addStretch(1) infoBox.addLayout(self.tick_info) infoBox.addStretch(5) box.addLayout(vbox) box.addLayout(infoBox) box.setStretchFactor(vbox, 8) box.setStretchFactor(infoBox, 1) self.setLayout(box)
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): """""" self.setWindowTitle("策略K线图表") # Create chart widget self.chart = MarketDataChartWidget() self.indicator_combo = QtWidgets.QComboBox() self.indicator_combo.addItems(self.chart.indicators.keys()) self.indicator_combo.currentTextChanged.connect( self.chart.change_indicator) self.interval_combo = QtWidgets.QComboBox() for i in Interval: self.interval_combo.addItem(i.value, i) self.interval_combo.setCurrentText(Interval.MINUTE.value) self.forward_btn = QtWidgets.QPushButton('←') self.interval_combo.currentIndexChanged.connect(self.change_interval) self.forward_btn.clicked.connect(self.forward) self.chart.signal_new_bar_request.connect(self.update_backward_bars) # Set layout hbox = QtWidgets.QHBoxLayout() hbox.addWidget(self.indicator_combo) hbox.addWidget(self.interval_combo) hbox.addWidget(self.forward_btn) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget(self.chart) self.setLayout(vbox)
def init_ui(self): """""" from vnpy.app.realtime_monitor.ui.baseQtItems import MarketDataChartWidget self.setWindowTitle(self.title) self.resize(1300, 800) vbox = QtWidgets.QVBoxLayout() klineWidget = MarketDataChartWidget() klineWidget.update_all(self.marketData, self.tradeData, []) if not self.record_df.empty: record = self.record_df.asof( klineWidget.dt_ix_map.keys()).fillna(0) ixs = [] for _dt in record.index: ixs.append(klineWidget.dt_ix_map[_dt]) record.index = ixs candle = klineWidget.get_plot('candle') for n, s in record.items(): c = pg.PlotCurveItem() candle.addItem(c) h = sha256() h.update(n.encode()) c.setData(s.index.values, s.values, pen=pg.Color(int(h.hexdigest(), base=16))) vbox.addWidget(klineWidget) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle(f"{self.daily_trade_result.name}交易明细") self.resize(1100, 500) table = QtWidgets.QTableWidget() fields = self.trade_values[0].__dataclass_fields__ table.setColumnCount(len(fields)) table.setRowCount(len(self.trade_values)) table.setHorizontalHeaderLabels(fields.keys()) table.verticalHeader().setVisible(False) for r, tradeData in enumerate(self.trade_values): for c, k in enumerate(fields.keys()): v = getattr(tradeData, k) if isinstance(v, Enum): v = v.value cell = QtWidgets.QTableWidgetItem(str(v)) cell.setFlags(QtCore.Qt.ItemIsEnabled) cell.setTextAlignment(QtCore.Qt.AlignCenter) table.setItem(r, c, cell) table.doubleClicked.connect(self.visulize) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(table) self.setLayout(vbox)
def init_ui(self) -> None: """ Init widget ui components. """ self.setWindowTitle("Excel RTD") self.resize(600, 600) module_path = Path(__file__).parent.parent client_path = module_path.joinpath("vnpy_rtd.py") self.client_line = QtWidgets.QLineEdit(str(client_path)) self.client_line.setReadOnly(True) copy_button = QtWidgets.QPushButton("复制") copy_button.clicked.connect(self.copy_client_path) self.log_monitor = QtWidgets.QTextEdit() self.log_monitor.setReadOnly(True) self.port_label = QtWidgets.QLabel( "使用Socket端口:请求回应9001、广播推送9002" ) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(self.client_line) hbox.addWidget(copy_button) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget(self.log_monitor) vbox.addWidget(self.port_label) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("参数优化结果") self.resize(1100, 500) table = QtWidgets.QTableWidget() table.setColumnCount(2) table.setRowCount(len(self.result_values)) table.setHorizontalHeaderLabels(["参数", self.target_display]) table.setEditTriggers(table.NoEditTriggers) table.verticalHeader().setVisible(False) table.horizontalHeader().setSectionResizeMode( 0, QtWidgets.QHeaderView.ResizeToContents ) table.horizontalHeader().setSectionResizeMode( 1, QtWidgets.QHeaderView.Stretch ) for n, tp in enumerate(self.result_values): setting, target_value, _ = tp setting_cell = QtWidgets.QTableWidgetItem(str(setting)) target_cell = QtWidgets.QTableWidgetItem(str(target_value)) setting_cell.setTextAlignment(QtCore.Qt.AlignCenter) target_cell.setTextAlignment(QtCore.Qt.AlignCenter) table.setItem(n, 0, setting_cell) table.setItem(n, 1, target_cell) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(table) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("投资组合") strategy_monitor = PortfolioStrategyMonitor( self.main_engine, self.event_engine) order_monitor = PortfolioOrderMonitor( self.main_engine, self.event_engine) trade_monitor = PortfolioTradeMonitor( self.main_engine, self.event_engine) self.trading_widget = StrategyTradingWidget(self.portfolio_engine) self.management_widget = StrategyManagementWidget( self.portfolio_engine, self.trading_widget, strategy_monitor ) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.management_widget) vbox.addWidget(self.create_group("策略", strategy_monitor)) vbox.addWidget(self.trading_widget) vbox.addWidget(self.create_group("委托", order_monitor)) vbox.addWidget(self.create_group("成交", trade_monitor)) self.setLayout(vbox)
def init_ui(self): self.setWindowTitle("锁仓单平仓") self.setMinimumWidth(300) self.symbol_combo = ComboBox() self.symbol_combo.pop_show.connect(self.refresh_symbol_list) self.symbol_combo.activated[str].connect(self.set_close_symbol) validator = QtGui.QIntValidator() self.close_pos_line = QtWidgets.QLineEdit() self.close_pos_line.setValidator(validator) button_close = QtWidgets.QPushButton("平仓") button_close.clicked.connect(self.close_hedged_pos) for btn in [button_close]: btn.setFixedHeight(btn.sizeHint().height() * 1.5) form = QtWidgets.QFormLayout() form.addRow("合约代码", self.symbol_combo) form.addRow("平仓手数", self.close_pos_line) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(button_close) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addLayout(hbox) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("回测每日明细") self.resize(1300, 800) table = QtWidgets.QTableWidget() table.setColumnCount(18) table.setRowCount(len(self.daily_df)) table.setHorizontalHeaderLabels(self.daily_df.columns) table.setVerticalHeaderLabels(str(i) for i in self.daily_df.index) table.verticalHeader().setVisible(True) for r, (d, s) in enumerate(self.daily_df.iterrows()): for c, (t, v) in enumerate(s.items()): if t == 'trades': cell = QtWidgets.QTableWidgetItem("交易明细") cell.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) else: cell = QtWidgets.QTableWidgetItem(str(v)) cell.setFlags(QtCore.Qt.ItemIsEnabled) cell.setTextAlignment(QtCore.Qt.AlignCenter) table.setItem(r, c, cell) table.itemDoubleClicked.connect(self.show_trade_data) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(table) self.setLayout(vbox)
def init_ui(self) -> None: """""" self.setWindowTitle("数据管理") self.init_tree() self.init_table() refresh_button = QtWidgets.QPushButton("刷新") refresh_button.clicked.connect(self.refresh_tree) import_button = QtWidgets.QPushButton("导入数据") import_button.clicked.connect(self.import_data) hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(refresh_button) hbox1.addStretch() hbox1.addWidget(import_button) hbox2 = QtWidgets.QHBoxLayout() hbox2.addWidget(self.tree) hbox2.addWidget(self.table) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(hbox2) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("函数编辑器") self.editor_box = EditorBox(self) self.function_box = McFunctionBox(self) hbox_1 = QtWidgets.QHBoxLayout() hbox_1.addLayout(self.editor_box) hbox_1.addLayout(self.function_box) # setStretch(int index, int stretch) # setStretch的第一个参数为索引,第二个参数为宽度 # 第一列的宽度为3,第二列的宽度为1 hbox_1.setStretch(0, 2) hbox_1.setStretch(1, 1) self.log_monitor_box = LogMonitorBox(self) self.strategy_box = SavedStrategyBox(self) hbox_2 = QtWidgets.QHBoxLayout() hbox_2.addLayout(self.log_monitor_box) hbox_2.addLayout(self.strategy_box) hbox_2.setStretch(0, 2) hbox_2.setStretch(1, 1) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox_1) vbox.addLayout(hbox_2) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("脚本策略") start_button = QtWidgets.QPushButton("启动") start_button.clicked.connect(self.start_script) stop_button = QtWidgets.QPushButton("停止") stop_button.clicked.connect(self.stop_script) select_button = QtWidgets.QPushButton("打开") select_button.clicked.connect(self.select_script) self.strategy_line = QtWidgets.QLineEdit() self.log_monitor = QtWidgets.QTextEdit() self.log_monitor.setReadOnly(True) clear_button = QtWidgets.QPushButton("清空") clear_button.clicked.connect(self.log_monitor.clear) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(self.strategy_line) hbox.addWidget(select_button) hbox.addWidget(start_button) hbox.addWidget(stop_button) hbox.addStretch() hbox.addWidget(clear_button) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget(self.log_monitor) self.setLayout(vbox)
def init_ui(self): """""" self.setFixedHeight(300) self.setFrameShape(self.Box) self.setLineWidth(1) init_button = QtWidgets.QPushButton("初始化") init_button.clicked.connect(self.init_strategy) start_button = QtWidgets.QPushButton("启动") start_button.clicked.connect(self.start_strategy) recover_button = QtWidgets.QPushButton("恢复") recover_button.clicked.connect(self.recover_strategy) cover_pos_button = QtWidgets.QPushButton("平仓") cover_pos_button.clicked.connect(self.close_strategy_pos) stop_button = QtWidgets.QPushButton("停止") stop_button.clicked.connect(self.stop_strategy) edit_button = QtWidgets.QPushButton("编辑") edit_button.clicked.connect(self.edit_strategy) modify_button = QtWidgets.QPushButton("修改") modify_button.clicked.connect(self.modify_strategy) remove_button = QtWidgets.QPushButton("移除") remove_button.clicked.connect(self.remove_strategy) strategy_name = self._data["strategy_name"] vt_symbol = self._data["vt_symbol"] class_name = self._data["class_name"] author = self._data["author"] label_text = ( f"{strategy_name} - {vt_symbol} ({class_name} by {author})") label = QtWidgets.QLabel(label_text) label.setAlignment(QtCore.Qt.AlignCenter) self.parameters_monitor = DataMonitor(self._data["parameters"]) self.variables_monitor = DataMonitor(self._data["variables"]) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(init_button) hbox.addWidget(start_button) hbox.addWidget(recover_button) hbox.addWidget(cover_pos_button) hbox.addWidget(stop_button) hbox.addWidget(edit_button) hbox.addWidget(remove_button) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(label) vbox.addLayout(hbox) vbox.addWidget(self.parameters_monitor) vbox.addWidget(self.variables_monitor) self.setLayout(vbox)
def init_ui(self): # 函数加载器 loader = FunctionLoader() # 得到并拼凑 function.xlsx 文件路径 running_path = Path(sys.argv[0]).parent function_file = running_path.joinpath("function.xlsx") # 加载函数描述文件 loader.load_excel(function_file) # 得到实际内容 self.function_dict = loader.contents self.function_names = loader.names # 实例化列表视图 # 头部标题 title = QtWidgets.QTextEdit() title.setPlainText("函数列表") title.setAlignment(QtCore.Qt.AlignCenter) title.setReadOnly(True) title_box = QtWidgets.QVBoxLayout() title_box.addWidget(title) # 初始化列表视图 list_view = QtWidgets.QListView() # 修改双击触发器为空 list_view.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) # 实例化列表模型,添加数据 list_model = QtCore.QStringListModel() # 设置模型列表视图,加载数据列表 list_model.setStringList(self.function_names) # 设置列表视图的模型 list_view.setModel(list_model) # 连接鼠标单击信号到 set_function_textarea 函数 list_view.clicked.connect(self.set_function_textarea) # 连接鼠标双击信号到具体事件 list_view.doubleClicked.connect(self.doubleClickedEvent) # 设置函数列表和函数内容窗口 func_content = QtWidgets.QHBoxLayout() func_list_box = QtWidgets.QHBoxLayout() func_list_box.addWidget(list_view) self.function_textarea = QtWidgets.QTextEdit() self.function_textarea.setReadOnly(True) # 设置启动的初始值 detail_text = self.get_function_detail(0) self.function_textarea.setPlainText(detail_text) detail_box = QtWidgets.QHBoxLayout() detail_box.addWidget(self.function_textarea) func_content.addLayout(func_list_box) func_content.addLayout(detail_box) func_content.setStretch(0, 2) func_content.setStretch(1, 5) self.addLayout(title_box) self.addLayout(func_content) self.setStretch(0, 1) self.setStretch(1, 19)
def init_ui(self) -> None: """""" self.setWindowTitle("情景分析") # Create widgets self.price_change_spin = QtWidgets.QSpinBox() self.price_change_spin.setSuffix("%") self.price_change_spin.setMinimum(2) self.price_change_spin.setValue(10) self.impv_change_spin = QtWidgets.QSpinBox() self.impv_change_spin.setSuffix("%") self.impv_change_spin.setMinimum(2) self.impv_change_spin.setValue(10) self.time_change_spin = QtWidgets.QSpinBox() self.time_change_spin.setSuffix("日") self.time_change_spin.setMinimum(0) self.time_change_spin.setValue(1) self.target_combo = QtWidgets.QComboBox() self.target_combo.addItems(["盈亏", "Delta", "Gamma", "Theta", "Vega"]) button = QtWidgets.QPushButton("执行分析") button.clicked.connect(self.run_analysis) # Create charts fig = Figure() canvas = FigureCanvas(fig) self.ax = fig.gca(projection="3d") self.ax.set_xlabel("价格涨跌 %") self.ax.set_ylabel("波动率涨跌 %") self.ax.set_zlabel("盈亏") # Set layout hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(QtWidgets.QLabel("目标数据")) hbox1.addWidget(self.target_combo) hbox1.addWidget(QtWidgets.QLabel("时间衰减")) hbox1.addWidget(self.time_change_spin) hbox1.addStretch() hbox2 = QtWidgets.QHBoxLayout() hbox2.addWidget(QtWidgets.QLabel("价格变动")) hbox2.addWidget(self.price_change_spin) hbox2.addWidget(QtWidgets.QLabel("波动率变动")) hbox2.addWidget(self.impv_change_spin) hbox2.addStretch() hbox2.addWidget(button) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(hbox2) vbox.addWidget(canvas) self.setLayout(vbox)
def create_group(self, title: str, widget: QtWidgets.QWidget): """""" group = QtWidgets.QGroupBox() vbox = QtWidgets.QVBoxLayout() vbox.addWidget(widget) group.setLayout(vbox) group.setTitle(title) return group
def init_ui(self): """""" self.setWindowTitle("策略K线图表") self.resize(1400, 800) # Create chart widget self.pnlChart = pg.PlotCurveItem() # Set layout vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.pnlChart) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle(self.title) self.resize(1100, 600) self.table = self.table_class(self.main_engine, self.event_engine) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.table) self.setLayout(vbox)
def init_ui(self): # 实例化列表视图 title = QtWidgets.QTextEdit() title.setPlainText("已存策略") title.setAlignment(QtCore.Qt.AlignCenter) title.setReadOnly(True) title_box = QtWidgets.QVBoxLayout() title_box.addWidget(title) self.strategy_list_view = ListView() # 实例化列表模型,添加数据 self.strategy_list_model = QtCore.QStringListModel() # item 单击事件 self.strategy_list_view.clicked.connect(self.set_script_textarea) # item 双击事件 self.strategy_list_view.doubleClicked.connect( self.double_clicked_event) # 取消双击触发器 self.strategy_list_view.setEditTriggers( QtWidgets.QAbstractItemView.NoEditTriggers) # 连接删除动作 self.strategy_list_view.connect_delete_action(self.delete_action) # 连接重命名动作 self.strategy_list_view.connect_rename_action(self.rename_action) # 初始化策略列表 self.update_list() # 设置列表和内容窗口 file_content = QtWidgets.QHBoxLayout() file_list_box = QtWidgets.QHBoxLayout() file_list_box.addWidget(self.strategy_list_view) self.script_textarea = QtWidgets.QTextEdit() self.script_textarea.setReadOnly(True) # 设置启动的初始值 script_content = self.get_script_content(0) self.script_textarea.setPlainText(script_content) detail_box = QtWidgets.QHBoxLayout() detail_box.addWidget(self.script_textarea) file_content.addLayout(file_list_box) file_content.addLayout(detail_box) file_content.setStretch(0, 2) file_content.setStretch(1, 5) self.addLayout(title_box) self.addLayout(file_content) self.setStretch(0, 1) self.setStretch(1, 19)
def init_ui(self): self.setWindowTitle("同步仓位") self.setMinimumWidth(300) # Select symbol widget self.sync_symbol_combo = ComboBox() self.sync_symbol_combo.pop_show.connect(self.refresh_symbol_list) self.sync_symbol_combo.activated[str].connect(self.set_sync_symbol) # Sync action button self.sync_open_button = QtWidgets.QPushButton("单合约开仓同步") self.sync_open_button.clicked.connect(self.sync_open) self.sync_close_button = QtWidgets.QPushButton("单合约平仓同步") self.sync_close_button.clicked.connect(self.sync_close) self.sync_button = QtWidgets.QPushButton("单合约开平同步") self.sync_button.clicked.connect(self.sync_open_and_close) self.sync_all_button = QtWidgets.QPushButton("所有持仓同步") self.sync_all_button.clicked.connect(self.sync_all) self.sync_net_button = QtWidgets.QPushButton("日内交易同步") self.sync_net_button.clicked.connect(lambda: self.sync_net_delta(is_sync_baisc=False)) self.sync_basic_button = QtWidgets.QPushButton("日内底仓同步") self.sync_basic_button.clicked.connect(lambda: self.sync_net_delta(is_sync_baisc=True)) for btn in [self.sync_open_button, self.sync_close_button, self.sync_button, self.sync_all_button, self.sync_net_button, self.sync_basic_button]: btn.setFixedHeight(btn.sizeHint().height() * 1.5) # Set layout form_sync = QtWidgets.QFormLayout() form_sync.addRow("同步合约", self.sync_symbol_combo) form_sync.addRow(self.sync_open_button) form_sync.addRow(self.sync_close_button) form_sync.addRow(self.sync_button) form_sync.addRow(self.sync_all_button) form_sync.addRow(self.sync_net_button) form_sync.addRow(self.sync_basic_button) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form_sync) self.setLayout(vbox)
def init_ui(self): """""" self.setFixedHeight(300) self.setFrameShape(self.Box) self.setLineWidth(1) init_button = QtWidgets.QPushButton(" initialization ") init_button.clicked.connect(self.init_strategy) start_button = QtWidgets.QPushButton(" start up ") start_button.clicked.connect(self.start_strategy) stop_button = QtWidgets.QPushButton(" stop ") stop_button.clicked.connect(self.stop_strategy) edit_button = QtWidgets.QPushButton(" edit ") edit_button.clicked.connect(self.edit_strategy) remove_button = QtWidgets.QPushButton(" remove ") remove_button.clicked.connect(self.remove_strategy) strategy_name = self._data["strategy_name"] spread_name = self._data["spread_name"] class_name = self._data["class_name"] author = self._data["author"] label_text = ( f"{strategy_name} - {spread_name} ({class_name} by {author})") label = QtWidgets.QLabel(label_text) label.setAlignment(QtCore.Qt.AlignCenter) self.parameters_monitor = StrategyDataMonitor(self._data["parameters"]) self.variables_monitor = StrategyDataMonitor(self._data["variables"]) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(init_button) hbox.addWidget(start_button) hbox.addWidget(stop_button) hbox.addWidget(edit_button) hbox.addWidget(remove_button) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(label) vbox.addLayout(hbox) vbox.addWidget(self.parameters_monitor) vbox.addWidget(self.variables_monitor) self.setLayout(vbox)
def init_ui(self): """""" self.setFixedHeight(300) self.setFrameShape(self.Box) self.setLineWidth(1) self.init_button = QtWidgets.QPushButton("初始化") self.init_button.clicked.connect(self.init_strategy) self.start_button = QtWidgets.QPushButton("启动") self.start_button.clicked.connect(self.start_strategy) self.start_button.setEnabled(False) self.stop_button = QtWidgets.QPushButton("停止") self.stop_button.clicked.connect(self.stop_strategy) self.stop_button.setEnabled(False) self.edit_button = QtWidgets.QPushButton("编辑") self.edit_button.clicked.connect(self.edit_strategy) self.remove_button = QtWidgets.QPushButton("移除") self.remove_button.clicked.connect(self.remove_strategy) strategy_name = self._data["strategy_name"] class_name = self._data["class_name"] author = self._data["author"] label_text = (f"{strategy_name} - ({class_name} by {author})") label = QtWidgets.QLabel(label_text) label.setAlignment(QtCore.Qt.AlignCenter) self.parameters_monitor = DataMonitor(self._data["parameters"]) self.variables_monitor = DataMonitor(self._data["variables"]) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(self.init_button) hbox.addWidget(self.start_button) hbox.addWidget(self.stop_button) hbox.addWidget(self.edit_button) hbox.addWidget(self.remove_button) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(label) vbox.addLayout(hbox) vbox.addWidget(self.parameters_monitor) vbox.addWidget(self.variables_monitor) self.setLayout(vbox)
def init_ui(self): self.setWindowTitle("修改仓位") self.setMinimumWidth(300) self.symbol_combo = ComboBox() self.symbol_combo.pop_show.connect(self.refresh_symbol_list) self.symbol_combo.activated[str].connect(self.set_modify_symbol) validator = QtGui.QIntValidator() # self.long_pos_line = QtWidgets.QLineEdit() # self.long_pos_line.setValidator(validator) # self.short_pos_line = QtWidgets.QLineEdit() # self.short_pos_line.setValidator(validator) self.basic_delta_line = QtWidgets.QLineEdit() self.basic_delta_line.setValidator(validator) self.traded_net_line = QtWidgets.QLineEdit() self.traded_net_line.setValidator(validator) self.lost_follow_line = QtWidgets.QLineEdit() self.lost_follow_line.setValidator(validator) button_modify = QtWidgets.QPushButton("修改") button_modify.clicked.connect(self.modify) for btn in [button_modify]: btn.setFixedHeight(btn.sizeHint().height() * 1.5) form = QtWidgets.QFormLayout() form.addRow("合约代码", self.symbol_combo) # form.addRow("目标户多仓", self.long_pos_line) # form.addRow("目标户空仓", self.short_pos_line) form.addRow("底仓差", self.basic_delta_line) form.addRow("交易净仓", self.traded_net_line) form.addRow("丢失净仓", self.lost_follow_line) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(button_modify) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(form) vbox.addLayout(hbox) self.setLayout(vbox)
def init_ui(self): # 编辑器的多行文本框 # self.editor_textarea = QtWidgets.QTextEdit() self.editor_textarea = MyLangEditor() # self.editor_textarea = CodeEditor() # 设置editor背景颜色 # self.editor_textarea.setStyleSheet("background:white") self.editor_textarea.textChanged.connect(self.handle_text_changed) # self.highlighter = PythonHighlighter(self.editor_textarea.document()) editor_textarea_box = QtWidgets.QVBoxLayout() editor_textarea_box.addWidget(self.editor_textarea) save_button = QtWidgets.QPushButton("保存") save_button.clicked.connect(self.save_script) save_as_button = QtWidgets.QPushButton("另存为") save_as_button.clicked.connect(self.save_script_as) interprete_button = QtWidgets.QPushButton("编译") interprete_button.clicked.connect(self.interprete) start_button = QtWidgets.QPushButton("启动") start_button.clicked.connect(self.start_script) stop_button = QtWidgets.QPushButton("停止") stop_button.clicked.connect(self.stop_script) clear_button = QtWidgets.QPushButton("清空编辑器") clear_button.clicked.connect(self.editor_textarea.clear) button_box = QtWidgets.QHBoxLayout() button_box.addWidget(save_button) button_box.addWidget(save_as_button) button_box.addWidget(interprete_button) button_box.addWidget(start_button) button_box.addWidget(stop_button) button_box.addStretch() button_box.addWidget(clear_button) strategy_name_box = QtWidgets.QHBoxLayout() self.current_strategy_name = QtWidgets.QTextEdit() self.current_strategy_name.setReadOnly(True) self.current_strategy_name.setPlainText("策略名称:未保存策略") strategy_name_box.addWidget(self.current_strategy_name) self.addLayout(button_box) self.addLayout(strategy_name_box) self.addLayout(editor_textarea_box) self.setStretch(0, 1) self.setStretch(1, 1) self.setStretch(2, 18)
def init_ui(self): """""" self.setWindowTitle("参数优化结果") self.resize(1100, 500) # Creat table to show result table = QtWidgets.QTableWidget() table.setColumnCount(2) table.setRowCount(len(self.result_values)) table.setHorizontalHeaderLabels(["参数", self.target_display]) table.setEditTriggers(table.NoEditTriggers) table.verticalHeader().setVisible(False) table.horizontalHeader().setSectionResizeMode( 0, QtWidgets.QHeaderView.ResizeToContents ) table.horizontalHeader().setSectionResizeMode( 1, QtWidgets.QHeaderView.Stretch ) for n, tp in enumerate(self.result_values): setting, target_value, _ = tp setting_cell = QtWidgets.QTableWidgetItem(str(setting)) target_cell = QtWidgets.QTableWidgetItem(f"{target_value:.2f}") setting_cell.setTextAlignment(QtCore.Qt.AlignCenter) target_cell.setTextAlignment(QtCore.Qt.AlignCenter) table.setItem(n, 0, setting_cell) table.setItem(n, 1, target_cell) # Create layout button = QtWidgets.QPushButton("保存") button.clicked.connect(self.save_csv) hbox = QtWidgets.QHBoxLayout() hbox.addStretch() hbox.addWidget(button) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(table) vbox.addLayout(hbox) self.setLayout(vbox)