def init_ui(self): """""" self.name_line = QtWidgets.QLineEdit() self.symbol_line = QtWidgets.QLineEdit() self.remove_combo = QtWidgets.QComboBox() for w in [ self.name_line, self.symbol_line, self.remove_combo ]: w.setFixedWidth(150) add_button = QtWidgets.QPushButton("创建策略") add_button.clicked.connect(self.add_strategy) remove_button = QtWidgets.QPushButton("移除策略") remove_button.clicked.connect(self.remove_strategy) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("策略名称")) hbox.addWidget(self.name_line) hbox.addWidget(QtWidgets.QLabel("交易合约")) hbox.addWidget(self.symbol_line) hbox.addWidget(add_button) hbox.addStretch() hbox.addWidget(self.remove_combo) hbox.addWidget(remove_button) self.setLayout(hbox)
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 init_ui(self): """""" self.name_combo = QtWidgets.QComboBox() self.direction_combo = QtWidgets.QComboBox() self.direction_combo.addItems( [Direction.LONG.value, Direction.SHORT.value]) self.offset_combo = QtWidgets.QComboBox() self.offset_combo.addItems([offset.value for offset in Offset]) double_validator = QtGui.QDoubleValidator() double_validator.setBottom(0) self.price_line = QtWidgets.QLineEdit() self.price_line.setValidator(double_validator) self.volume_line = QtWidgets.QLineEdit() self.volume_line.setValidator(double_validator) for w in [ self.name_combo, self.price_line, self.volume_line, self.direction_combo, self.offset_combo ]: w.setFixedWidth(150) send_button = QtWidgets.QPushButton("委托") send_button.clicked.connect(self.send_order) send_button.setFixedWidth(70) cancel_button = QtWidgets.QPushButton("全撤") cancel_button.clicked.connect(self.cancel_all) cancel_button.setFixedWidth(70) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("策略名称")) hbox.addWidget(self.name_combo) hbox.addWidget(QtWidgets.QLabel("方向")) hbox.addWidget(self.direction_combo) hbox.addWidget(QtWidgets.QLabel("开平")) hbox.addWidget(self.offset_combo) hbox.addWidget(QtWidgets.QLabel("价格")) hbox.addWidget(self.price_line) hbox.addWidget(QtWidgets.QLabel("数量")) hbox.addWidget(self.volume_line) hbox.addWidget(send_button) hbox.addWidget(cancel_button) hbox.addStretch() self.setLayout(hbox)
def init_ui(self): """""" self.setWindowTitle("OptionMaster") self.portfolio_combo = QtWidgets.QComboBox() self.portfolio_combo.setFixedWidth(150) self.update_portfolio_combo() self.portfolio_button = QtWidgets.QPushButton("配置") self.portfolio_button.clicked.connect(self.open_portfolio_dialog) self.market_button = QtWidgets.QPushButton("T型报价") self.greeks_button = QtWidgets.QPushButton("持仓希腊值") self.chain_button = QtWidgets.QPushButton("拟合升贴水") self.manual_button = QtWidgets.QPushButton("快速交易") for button in [ self.market_button, self.greeks_button, self.chain_button, self.manual_button ]: button.setEnabled(False) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("期权产品")) hbox.addWidget(self.portfolio_combo) hbox.addWidget(self.portfolio_button) hbox.addWidget(self.market_button) hbox.addWidget(self.greeks_button) hbox.addWidget(self.manual_button) hbox.addWidget(self.chain_button) self.setLayout(hbox)
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): """ Initialize line edits and form layout based on setting. """ self.setMaximumWidth(400) form = QtWidgets.QFormLayout() for field_name, field_value in self.default_setting.items(): field_type = type(field_value) if field_type == list: widget = QtWidgets.QComboBox() widget.addItems(field_value) else: widget = QtWidgets.QLineEdit() display_name = NAME_DISPLAY_MAP.get(field_name, field_name) form.addRow(display_name, widget) self.widgets[field_name] = (widget, field_type) start_algo_button = QtWidgets.QPushButton("启动算法") start_algo_button.clicked.connect(self.start_algo) form.addRow(start_algo_button) load_csv_button = QtWidgets.QPushButton("CSV启动") load_csv_button.clicked.connect(self.load_csv) form.addRow(load_csv_button) form.addRow(QtWidgets.QLabel("")) form.addRow(QtWidgets.QLabel("")) form.addRow(QtWidgets.QLabel("")) self.setting_name_line = QtWidgets.QLineEdit() form.addRow("配置名称", self.setting_name_line) save_setting_button = QtWidgets.QPushButton("保存配置") save_setting_button.clicked.connect(self.save_setting) form.addRow(save_setting_button) for button in [ start_algo_button, load_csv_button, save_setting_button ]: button.setFixedHeight(button.sizeHint().height() * 2) self.setLayout(form)
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 create_label(self, color: str = "", alignment: int = QtCore.Qt.AlignLeft): """ Create label with certain font color. """ label = QtWidgets.QLabel("-") if color: label.setStyleSheet(f"color:{color}") label.setAlignment(alignment) return label
def init_ui(self) -> None: """""" self.setWindowTitle("OptionMaster") self.portfolio_combo = QtWidgets.QComboBox() self.portfolio_combo.setFixedWidth(150) self.update_portfolio_combo() self.portfolio_button = QtWidgets.QPushButton("配置") self.portfolio_button.clicked.connect(self.open_portfolio_dialog) self.market_button = QtWidgets.QPushButton("T型报价") self.greeks_button = QtWidgets.QPushButton("持仓希腊值") self.chain_button = QtWidgets.QPushButton("升贴水监控") self.manual_button = QtWidgets.QPushButton("快速交易") self.volatility_button = QtWidgets.QPushButton("波动率曲线") self.hedge_button = QtWidgets.QPushButton("Delta对冲") self.scenario_button = QtWidgets.QPushButton("情景分析") self.eye_button = QtWidgets.QPushButton("电子眼") self.pricing_button = QtWidgets.QPushButton("波动率管理") for button in [ self.market_button, self.greeks_button, self.chain_button, self.manual_button, self.volatility_button, self.hedge_button, self.scenario_button, self.eye_button, self.pricing_button ]: button.setEnabled(False) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("期权产品")) hbox.addWidget(self.portfolio_combo) hbox.addWidget(self.portfolio_button) hbox.addWidget(self.market_button) hbox.addWidget(self.greeks_button) hbox.addWidget(self.manual_button) hbox.addWidget(self.chain_button) hbox.addWidget(self.volatility_button) hbox.addWidget(self.hedge_button) hbox.addWidget(self.scenario_button) hbox.addWidget(self.pricing_button) hbox.addWidget(self.eye_button) self.setLayout(hbox)
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) -> 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)
def init_ui(self): """""" self.setWindowTitle("CSV载入") self.setFixedWidth(300) self.setWindowFlags((self.windowFlags() | QtCore.Qt.CustomizeWindowHint) & ~QtCore.Qt.WindowMaximizeButtonHint) file_button = QtWidgets.QPushButton("选择文件") file_button.clicked.connect(self.select_file) load_button = QtWidgets.QPushButton("载入数据") load_button.clicked.connect(self.load_data) self.file_edit = QtWidgets.QLineEdit() self.symbol_edit = QtWidgets.QLineEdit() self.exchange_combo = QtWidgets.QComboBox() for i in Exchange: self.exchange_combo.addItem(str(i.name), i) 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.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) form = QtWidgets.QFormLayout() form.addRow(file_button, self.file_edit) form.addRow(QtWidgets.QLabel()) form.addRow(info_label) form.addRow("代码", self.symbol_edit) form.addRow("交易所", self.exchange_combo) form.addRow("周期", self.interval_combo) form.addRow(QtWidgets.QLabel()) form.addRow(head_label) form.addRow("时间戳", self.datetime_edit) form.addRow("开盘价", self.open_edit) form.addRow("最高价", self.high_edit) form.addRow("最低价", self.low_edit) form.addRow("收盘价", self.close_edit) form.addRow("成交量", self.volume_edit) form.addRow(QtWidgets.QLabel()) form.addRow(format_label) form.addRow("时间格式", self.format_edit) form.addRow(QtWidgets.QLabel()) form.addRow(load_button) self.setLayout(form)
def init_ui(self): """""" self.setWindowTitle("行情记录") self.resize(1000, 600) # Create widgets self.symbol_line = QtWidgets.QLineEdit() self.symbol_line.setFixedHeight(self.symbol_line.sizeHint().height() * 2) contracts = self.main_engine.get_all_contracts() self.vt_symbols = [contract.vt_symbol for contract in contracts] self.symbol_completer = QtWidgets.QCompleter(self.vt_symbols) self.symbol_completer.setFilterMode(QtCore.Qt.MatchContains) self.symbol_completer.setCompletionMode( self.symbol_completer.PopupCompletion) self.symbol_line.setCompleter(self.symbol_completer) add_bar_button = QtWidgets.QPushButton("添加") add_bar_button.clicked.connect(self.add_bar_recording) remove_bar_button = QtWidgets.QPushButton("移除") remove_bar_button.clicked.connect(self.remove_bar_recording) add_tick_button = QtWidgets.QPushButton("添加") add_tick_button.clicked.connect(self.add_tick_recording) remove_tick_button = QtWidgets.QPushButton("移除") remove_tick_button.clicked.connect(self.remove_tick_recording) self.bar_recording_edit = QtWidgets.QTextEdit() self.bar_recording_edit.setReadOnly(True) self.tick_recording_edit = QtWidgets.QTextEdit() self.tick_recording_edit.setReadOnly(True) self.log_edit = QtWidgets.QTextEdit() self.log_edit.setReadOnly(True) # Set layout grid = QtWidgets.QGridLayout() grid.addWidget(QtWidgets.QLabel("K线记录"), 0, 0) grid.addWidget(add_bar_button, 0, 1) grid.addWidget(remove_bar_button, 0, 2) grid.addWidget(QtWidgets.QLabel("Tick记录"), 1, 0) grid.addWidget(add_tick_button, 1, 1) grid.addWidget(remove_tick_button, 1, 2) hbox = QtWidgets.QHBoxLayout() hbox.addWidget(QtWidgets.QLabel("本地代码")) hbox.addWidget(self.symbol_line) hbox.addWidget(QtWidgets.QLabel(" ")) hbox.addLayout(grid) hbox.addStretch() grid2 = QtWidgets.QGridLayout() grid2.addWidget(QtWidgets.QLabel("K线记录列表"), 0, 0) grid2.addWidget(QtWidgets.QLabel("Tick记录列表"), 0, 1) grid2.addWidget(self.bar_recording_edit, 1, 0) grid2.addWidget(self.tick_recording_edit, 1, 1) grid2.addWidget(self.log_edit, 2, 0, 1, 2) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addLayout(grid2) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("回测K线图表") self.resize(1400, 800) # Create chart widget self.chart = ChartWidget() self.chart.add_plot("candle", hide_x_axis=True) self.chart.add_plot("volume", maximum_height=200) self.chart.add_item(CandleItem, "candle", "candle") self.chart.add_item(VolumeItem, "volume", "volume") self.chart.add_cursor() # Create help widget text1 = "红色虚线 —— 盈利交易" label1 = QtWidgets.QLabel(text1) label1.setStyleSheet("color:red") text2 = "绿色虚线 —— 亏损交易" label2 = QtWidgets.QLabel(text2) label2.setStyleSheet("color:#00FF00") text3 = "黄色向上箭头 —— 买入开仓 Buy" label3 = QtWidgets.QLabel(text3) label3.setStyleSheet("color:yellow") text4 = "黄色向下箭头 —— 卖出平仓 Sell" label4 = QtWidgets.QLabel(text4) label4.setStyleSheet("color:yellow") text5 = "紫红向下箭头 —— 卖出开仓 Short" label5 = QtWidgets.QLabel(text5) label5.setStyleSheet("color:magenta") text6 = "紫红向上箭头 —— 买入平仓 Cover" label6 = QtWidgets.QLabel(text6) label6.setStyleSheet("color:magenta") hbox1 = QtWidgets.QHBoxLayout() hbox1.addStretch() hbox1.addWidget(label1) hbox1.addStretch() hbox1.addWidget(label2) hbox1.addStretch() hbox2 = QtWidgets.QHBoxLayout() hbox2.addStretch() hbox2.addWidget(label3) hbox2.addStretch() hbox2.addWidget(label4) hbox2.addStretch() hbox3 = QtWidgets.QHBoxLayout() hbox3.addStretch() hbox3.addWidget(label5) hbox3.addStretch() hbox3.addWidget(label6) hbox3.addStretch() # Set layout vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.chart) vbox.addLayout(hbox1) vbox.addLayout(hbox2) vbox.addLayout(hbox3) self.setLayout(vbox)
def __init__(self, parent=None): """""" super().__init__() self.setWindowTitle("从CSV文件导入数据") self.setFixedWidth(300) self.setWindowFlags((self.windowFlags() | QtCore.Qt.CustomizeWindowHint) & ~QtCore.Qt.WindowMaximizeButtonHint) file_button = QtWidgets.QPushButton("选择文件") file_button.clicked.connect(self.select_file) load_button = QtWidgets.QPushButton("确定") load_button.clicked.connect(self.accept) self.file_edit = QtWidgets.QLineEdit() self.symbol_edit = QtWidgets.QLineEdit() self.exchange_combo = QtWidgets.QComboBox() for i in Exchange: self.exchange_combo.addItem(str(i.name), i) self.interval_combo = QtWidgets.QComboBox() for i in Interval: if i != Interval.TICK: 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("open_interest") 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) form = QtWidgets.QFormLayout() form.addRow(file_button, self.file_edit) form.addRow(QtWidgets.QLabel()) form.addRow(info_label) form.addRow("代码", self.symbol_edit) form.addRow("交易所", self.exchange_combo) form.addRow("周期", self.interval_combo) form.addRow(QtWidgets.QLabel()) form.addRow(head_label) form.addRow("时间戳", self.datetime_edit) form.addRow("开盘价", self.open_edit) form.addRow("最高价", self.high_edit) form.addRow("最低价", self.low_edit) form.addRow("收盘价", self.close_edit) form.addRow("成交量", self.volume_edit) form.addRow("持仓量", self.open_interest_edit) form.addRow(QtWidgets.QLabel()) form.addRow(format_label) form.addRow("时间格式", self.format_edit) form.addRow(QtWidgets.QLabel()) form.addRow(load_button) self.setLayout(form)
def init_ui(self): """""" self.setWindowTitle("行情记录") self.resize(1000, 600) # Create widgets self.symbol_line = QtWidgets.QLineEdit() self.interval_spin = QtWidgets.QSpinBox() self.interval_spin.setMinimum(1) self.interval_spin.setMaximum(60) self.interval_spin.setValue(self.recorder_engine.timer_interval) self.interval_spin.setSuffix("秒") self.interval_spin.valueChanged.connect(self.set_interval) contracts = self.main_engine.get_all_contracts() self.vt_symbols = [contract.vt_symbol for contract in contracts] self.symbol_completer = QtWidgets.QCompleter(self.vt_symbols) self.symbol_completer.setFilterMode(QtCore.Qt.MatchContains) self.symbol_completer.setCompletionMode( self.symbol_completer.PopupCompletion) self.symbol_line.setCompleter(self.symbol_completer) add_bar_button = QtWidgets.QPushButton("添加") add_bar_button.clicked.connect(self.add_bar_recording) remove_bar_button = QtWidgets.QPushButton("移除") remove_bar_button.clicked.connect(self.remove_bar_recording) add_tick_button = QtWidgets.QPushButton("添加") add_tick_button.clicked.connect(self.add_tick_recording) remove_tick_button = QtWidgets.QPushButton("移除") remove_tick_button.clicked.connect(self.remove_tick_recording) self.bar_recording_edit = QtWidgets.QTextEdit() self.bar_recording_edit.setReadOnly(True) self.tick_recording_edit = QtWidgets.QTextEdit() self.tick_recording_edit.setReadOnly(True) self.log_edit = QtWidgets.QTextEdit() self.log_edit.setReadOnly(True) # Set layout grid = QtWidgets.QGridLayout() grid.addWidget(QtWidgets.QLabel("K线记录"), 0, 0) grid.addWidget(add_bar_button, 0, 1) grid.addWidget(remove_bar_button, 0, 2) grid.addWidget(QtWidgets.QLabel("Tick记录"), 1, 0) grid.addWidget(add_tick_button, 1, 1) grid.addWidget(remove_tick_button, 1, 2) form = QtWidgets.QFormLayout() form.addRow("本地代码", self.symbol_line) form.addRow("写入间隔", self.interval_spin) hbox = QtWidgets.QHBoxLayout() hbox.addLayout(form) hbox.addWidget(QtWidgets.QLabel(" ")) hbox.addLayout(grid) hbox.addStretch() grid2 = QtWidgets.QGridLayout() grid2.addWidget(QtWidgets.QLabel("K线记录列表"), 0, 0) grid2.addWidget(QtWidgets.QLabel("Tick记录列表"), 0, 1) grid2.addWidget(self.bar_recording_edit, 1, 0) grid2.addWidget(self.tick_recording_edit, 1, 1) grid2.addWidget(self.log_edit, 2, 0, 1, 2) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox) vbox.addLayout(grid2) self.setLayout(vbox)
def init_ui(self): """""" self.setWindowTitle("CTA回测") # Setting Part self.class_combo = QtWidgets.QComboBox() # self.symbol_line = QtWidgets.QLineEdit("IF88.CFFEX") self.symbol_line = "" self.symbol_label = QtWidgets.QLabel() self.data_counts_label = QtWidgets.QLabel() ############################################# # fangyang add, 根据数据库内容进行选项显示 self.dbbardata_groupby_df = self.db_instance.get_groupby_data_from_sql_db() self.exchange_combo = QtWidgets.QComboBox() self.exchange_combo.addItems(self.dbbardata_groupby_df['exchange'].drop_duplicates().to_list()) self.exchange_combo.activated[str].connect(self.onExchangeActivated) self.symbol_combo = QtWidgets.QComboBox() self.symbol_combo.currentIndexChanged.connect(self.onSymbolActivated) self.interval_combo = QtWidgets.QComboBox() self.interval_combo.currentIndexChanged.connect(self.onIntervalActivated) ########################################## end_dt = datetime.now() # start_dt = end_dt - timedelta(days=3 * 365) # debug 临时更改 start_dt = end_dt - timedelta(days=100) # debug 临时更改 self.start_date_edit = QtWidgets.QDateEdit( QtCore.QDate( start_dt.year, start_dt.month, start_dt.day ) ) self.end_date_edit = QtWidgets.QDateEdit( QtCore.QDate.currentDate() ) self.rate_line = QtWidgets.QLineEdit("0.000025") self.slippage_line = QtWidgets.QLineEdit("1") self.size_line = QtWidgets.QLineEdit("10") self.pricetick_line = QtWidgets.QLineEdit("1") self.capital_line = QtWidgets.QLineEdit("1000000") self.inverse_combo = QtWidgets.QComboBox() self.inverse_combo.addItems(["正向", "反向"]) # fangyang add self.debug_combo = QtWidgets.QComboBox() self.debug_combo.addItems(["Thread 运行回测", "Debug 运行回测"]) backtesting_button = QtWidgets.QPushButton("开始回测") backtesting_button.clicked.connect(self.start_backtesting) rl_train_button = QtWidgets.QPushButton("开始RL训练") rl_train_button.clicked.connect(self.start_rl_train) optimization_button = QtWidgets.QPushButton("参数优化") optimization_button.clicked.connect(self.start_optimization) self.result_button = QtWidgets.QPushButton("优化结果") self.result_button.clicked.connect(self.show_optimization_result) self.result_button.setEnabled(False) downloading_button = QtWidgets.QPushButton("下载数据") downloading_button.clicked.connect(self.start_downloading) self.order_button = QtWidgets.QPushButton("委托记录") self.order_button.clicked.connect(self.show_backtesting_orders) self.order_button.setEnabled(False) self.trade_button = QtWidgets.QPushButton("成交记录") self.trade_button.clicked.connect(self.show_backtesting_trades) self.trade_button.setEnabled(False) self.daily_button = QtWidgets.QPushButton("每日盈亏") self.daily_button.clicked.connect(self.show_daily_results) self.daily_button.setEnabled(False) self.candle_button = QtWidgets.QPushButton("K线图表") self.candle_button.clicked.connect(self.show_candle_chart) self.candle_button.setEnabled(False) self.candle_button_web = QtWidgets.QPushButton("K线图表web") self.candle_button_web.clicked.connect(self.show_candle_chart_web) # self.candle_button_web.setEnabled(False) edit_button = QtWidgets.QPushButton("代码编辑") edit_button.clicked.connect(self.edit_strategy_code) reload_button = QtWidgets.QPushButton("策略重载") reload_button.clicked.connect(self.reload_strategy_class) # for button in [ # backtesting_button, # optimization_button, # downloading_button, # self.result_button, # self.order_button, # self.trade_button, # self.daily_button, # self.candle_button, # edit_button, # reload_button # ]: # button.setFixedHeight(button.sizeHint().height() * 2) form = QtWidgets.QFormLayout() form.addRow("交易策略", self.class_combo) form.addRow("交易所代码", self.exchange_combo) form.addRow("本地代码", self.symbol_combo) form.addRow("合约名称", self.symbol_label) form.addRow("K线周期", self.interval_combo) form.addRow("开始日期", self.start_date_edit) form.addRow("结束日期\n(+1天才能回测到最后这天)", self.end_date_edit) form.addRow("DB内总数据量", self.data_counts_label) form.addRow("手续费率", self.rate_line) form.addRow("交易滑点", self.slippage_line) form.addRow("合约乘数", self.size_line) form.addRow("价格跳动", self.pricetick_line) form.addRow("回测资金", self.capital_line) form.addRow("合约模式\n(数字货币用反向)", self.inverse_combo) form.addRow("回测模式", self.debug_combo) result_grid = QtWidgets.QGridLayout() result_grid.addWidget(self.trade_button, 0, 0) result_grid.addWidget(self.order_button, 0, 1) result_grid.addWidget(self.daily_button, 1, 0) result_grid.addWidget(self.candle_button, 1, 1) result_grid.addWidget(self.candle_button_web, 2, 1) left_vbox = QtWidgets.QVBoxLayout() left_vbox.addLayout(form) left_vbox.addWidget(backtesting_button) left_vbox.addWidget(rl_train_button) left_vbox.addWidget(downloading_button) left_vbox.addStretch() left_vbox.addLayout(result_grid) left_vbox.addStretch() left_vbox.addWidget(optimization_button) left_vbox.addWidget(self.result_button) left_vbox.addStretch() left_vbox.addWidget(edit_button) left_vbox.addWidget(reload_button) # Result part self.statistics_monitor = StatisticsMonitor() self.log_monitor = QtWidgets.QTextEdit() self.log_monitor.setMaximumHeight(400) self.chart = BacktesterChart() self.chart.setMinimumWidth(1000) self.trade_dialog = BacktestingResultDialog( self.main_engine, self.event_engine, "回测成交记录", BacktestingTradeMonitor ) self.order_dialog = BacktestingResultDialog( self.main_engine, self.event_engine, "回测委托记录", BacktestingOrderMonitor ) self.daily_dialog = BacktestingResultDialog( self.main_engine, self.event_engine, "回测每日盈亏", DailyResultMonitor ) # Candle Chart self.candle_dialog = CandleChartDialog() # Layout vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.statistics_monitor) vbox.addWidget(self.log_monitor) hbox = QtWidgets.QHBoxLayout() hbox.addLayout(left_vbox) hbox.addLayout(vbox) hbox.addWidget(self.chart) self.setLayout(hbox) # Code Editor self.editor = CodeEditor(self.main_engine, self.event_engine) # Load setting setting = load_json(self.setting_filename) if not setting: return self.class_combo.setCurrentIndex( self.class_combo.findText(setting["class_name"]) ) self.interval_combo.setCurrentIndex( self.interval_combo.findText(setting["interval"]) ) self.rate_line.setText(str(setting["rate"])) self.slippage_line.setText(str(setting["slippage"])) self.size_line.setText(str(setting["size"])) self.pricetick_line.setText(str(setting["pricetick"])) self.capital_line.setText(str(setting["capital"])) if not setting["inverse"]: self.inverse_combo.setCurrentIndex(0) else: self.inverse_combo.setCurrentIndex(1)
def init_ui(self) -> None: """""" self.setWindowTitle("投资组合") labels = [ "组合名称", "本地代码", "开盘仓位", "当前仓位", "交易盈亏", "持仓盈亏", "总盈亏", "多头成交", "空头成交" ] self.column_count = len(labels) self.tree = QtWidgets.QTreeWidget() self.tree.setColumnCount(self.column_count) self.tree.setHeaderLabels(labels) self.tree.header().setDefaultAlignment(QtCore.Qt.AlignCenter) self.tree.header().setStretchLastSection(False) delegate = TreeDelegate() self.tree.setItemDelegate(delegate) self.monitor = PortfolioTradeMonitor() expand_button = QtWidgets.QPushButton("全部展开") expand_button.clicked.connect(self.tree.expandAll) collapse_button = QtWidgets.QPushButton("全部折叠") collapse_button.clicked.connect(self.tree.collapseAll) resize_button = QtWidgets.QPushButton("调整列宽") resize_button.clicked.connect(self.resize_columns) interval_spin = QtWidgets.QSpinBox() interval_spin.setMinimum(1) interval_spin.setMaximum(60) interval_spin.setSuffix("秒") interval_spin.setValue(self.portfolio_engine.get_timer_interval()) interval_spin.valueChanged.connect( self.portfolio_engine.set_timer_interval) self.reference_combo = QtWidgets.QComboBox() self.reference_combo.setMinimumWidth(200) self.reference_combo.addItem("") self.reference_combo.currentIndexChanged.connect( self.set_reference_filter) hbox1 = QtWidgets.QHBoxLayout() hbox1.addWidget(expand_button) hbox1.addWidget(collapse_button) hbox1.addWidget(resize_button) hbox1.addStretch() hbox1.addWidget(QtWidgets.QLabel("刷新频率")) hbox1.addWidget(interval_spin) hbox1.addStretch() hbox1.addWidget(QtWidgets.QLabel("组合成交")) hbox1.addWidget(self.reference_combo) hbox2 = QtWidgets.QHBoxLayout() hbox2.addWidget(self.tree) hbox2.addWidget(self.monitor) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(hbox1) vbox.addLayout(hbox2) self.setLayout(vbox)
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("CSV loading ") self.setFixedWidth(300) self.setWindowFlags( (self.windowFlags() | QtCore.Qt.CustomizeWindowHint) & ~QtCore.Qt.WindowMaximizeButtonHint) file_button = QtWidgets.QPushButton(" select a document ") file_button.clicked.connect(self.select_file) load_button = QtWidgets.QPushButton(" loading data ") load_button.clicked.connect(self.load_data) self.file_edit = QtWidgets.QLineEdit() self.symbol_edit = QtWidgets.QLineEdit() self.exchange_combo = QtWidgets.QComboBox() for i in Exchange: self.exchange_combo.addItem(str(i.name), i) 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.format_edit = QtWidgets.QLineEdit("%Y-%m-%d %H:%M:%S") info_label = QtWidgets.QLabel(" contract information ") info_label.setAlignment(QtCore.Qt.AlignCenter) head_label = QtWidgets.QLabel(" header information ") head_label.setAlignment(QtCore.Qt.AlignCenter) format_label = QtWidgets.QLabel(" format information ") format_label.setAlignment(QtCore.Qt.AlignCenter) form = QtWidgets.QFormLayout() form.addRow(file_button, self.file_edit) form.addRow(QtWidgets.QLabel()) form.addRow(info_label) form.addRow(" code ", self.symbol_edit) form.addRow(" exchange ", self.exchange_combo) form.addRow(" cycle ", self.interval_combo) form.addRow(QtWidgets.QLabel()) form.addRow(head_label) form.addRow(" timestamp ", self.datetime_edit) form.addRow(" opening price ", self.open_edit) form.addRow(" highest price ", self.high_edit) form.addRow(" lowest ", self.low_edit) form.addRow(" closing price ", self.close_edit) form.addRow(" volume ", self.volume_edit) form.addRow(QtWidgets.QLabel()) form.addRow(format_label) form.addRow(" time format ", self.format_edit) form.addRow(QtWidgets.QLabel()) form.addRow(load_button) self.setLayout(form)