Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    def init_ui(self) -> None:
        """"""
        self.setWindowTitle("移仓助手")

        old_symbols = []
        for vt_symbol, strategies in self.cta_engine.symbol_strategy_map.items(
        ):
            if strategies:
                old_symbols.append(vt_symbol)
        self.old_symbol_combo = QtWidgets.QComboBox()
        self.old_symbol_combo.addItems(old_symbols)

        self.new_symbol_line = QtWidgets.QLineEdit()

        self.payup_spin = QtWidgets.QSpinBox()
        self.payup_spin.setMinimum(5)

        self.log_edit = QtWidgets.QTextEdit()
        self.log_edit.setReadOnly(True)
        self.log_edit.setMinimumWidth(500)

        button = QtWidgets.QPushButton("移仓")
        button.clicked.connect(self.roll_all)
        button.setFixedHeight(button.sizeHint().height() * 2)

        form = QtWidgets.QFormLayout()
        form.addRow("移仓合约", self.old_symbol_combo)
        form.addRow("目标合约", self.new_symbol_line)
        form.addRow("委托超价", self.payup_spin)
        form.addRow(button)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addLayout(form)
        hbox.addWidget(self.log_edit)
        self.setLayout(hbox)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    def init_ui(self):
        """"""
        self.setWindowTitle("价差交易")

        self.algo_dialog = SpreadAlgoWidget(self.spread_engine)
        algo_group = self.create_group("交易", self.algo_dialog)
        algo_group.setMaximumWidth(300)

        self.data_monitor = SpreadDataMonitor(self.main_engine,
                                              self.event_engine)
        self.log_monitor = SpreadLogMonitor(self.main_engine,
                                            self.event_engine)
        self.algo_monitor = SpreadAlgoMonitor(self.spread_engine)

        self.strategy_monitor = SpreadStrategyMonitor(self.spread_engine)

        grid = QtWidgets.QGridLayout()
        grid.addWidget(self.create_group("价差", self.data_monitor), 0, 0)
        grid.addWidget(self.create_group("日志", self.log_monitor), 1, 0)
        grid.addWidget(self.create_group("算法", self.algo_monitor), 0, 1)
        grid.addWidget(self.create_group("策略", self.strategy_monitor), 1, 1)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(algo_group)
        hbox.addLayout(grid)

        self.setLayout(hbox)
Example #13
0
    def init_ui(self):
        """"""
        self.setWindowTitle(" spread trading ")

        self.algo_dialog = SpreadAlgoWidget(self.spread_engine)
        algo_group = self.create_group(" transaction ", self.algo_dialog)
        algo_group.setMaximumWidth(300)

        self.data_monitor = SpreadDataMonitor(self.main_engine,
                                              self.event_engine)
        self.log_monitor = SpreadLogMonitor(self.main_engine,
                                            self.event_engine)
        self.algo_monitor = SpreadAlgoMonitor(self.spread_engine)

        self.strategy_monitor = SpreadStrategyMonitor(self.spread_engine)

        grid = QtWidgets.QGridLayout()
        grid.addWidget(self.create_group(" spread ", self.data_monitor), 0, 0)
        grid.addWidget(self.create_group(" journal ", self.log_monitor), 1, 0)
        grid.addWidget(self.create_group(" algorithm ", self.algo_monitor), 0,
                       1)
        grid.addWidget(self.create_group(" tactics ", self.strategy_monitor),
                       1, 1)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(algo_group)
        hbox.addLayout(grid)

        self.setLayout(hbox)
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
    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)
Example #17
0
    def init_ui(self) -> None:
        """"""
        self.setWindowTitle("OptionMasterExt")

        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.init_button = QtWidgets.QPushButton("初始化")
        self.init_button.clicked.connect(self.init_engine)

        self.volatility_button = QtWidgets.QPushButton("波动率交易")
        self.hedge_button = QtWidgets.QPushButton("Delta对冲")

        for button in [
            self.volatility_button,
            self.hedge_button,
        ]:
            button.setEnabled(False)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(self.portfolio_combo)
        hbox.addWidget(self.portfolio_button)
        hbox.addWidget(self.init_button)
        hbox.addWidget(self.volatility_button)
        hbox.addWidget(self.hedge_button)

        self.setLayout(hbox)
Example #18
0
    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)
Example #19
0
    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)
Example #20
0
    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)
Example #21
0
    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)
Example #22
0
    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)
Example #23
0
    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)
Example #24
0
    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)
Example #25
0
    def init_ui(self) -> None:
        """"""
        self.setWindowTitle("Data Management")

        self.init_tree()
        self.init_table()
        self.init_child()

        refresh_button = QtWidgets.QPushButton("Refresh")
        refresh_button.clicked.connect(self.refresh_tree)

        import_button = QtWidgets.QPushButton("Import Data")
        import_button.clicked.connect(self.import_data)

        update_button = QtWidgets.QPushButton("Update Data")
        update_button.clicked.connect(self.update_data)

        download_button = QtWidgets.QPushButton("Download Data")
        download_button.clicked.connect(self.download_data)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(refresh_button)
        hbox1.addStretch()
        hbox1.addWidget(import_button)
        hbox1.addWidget(update_button)
        hbox1.addWidget(download_button)

        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(self.tree)
        hbox2.addWidget(self.table)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)

        self.setLayout(vbox)
Example #26
0
    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)
Example #27
0
    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)
Example #28
0
    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)
Example #29
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 #30
0
    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)