[Mod] add support for reverse contract in CtaBacktester
This commit is contained in:
parent
da33b01f7b
commit
01fed04246
@ -133,6 +133,7 @@ class BacktesterEngine(BaseEngine):
|
|||||||
size: int,
|
size: int,
|
||||||
pricetick: float,
|
pricetick: float,
|
||||||
capital: int,
|
capital: int,
|
||||||
|
inverse: bool,
|
||||||
setting: dict
|
setting: dict
|
||||||
):
|
):
|
||||||
""""""
|
""""""
|
||||||
@ -151,7 +152,8 @@ class BacktesterEngine(BaseEngine):
|
|||||||
slippage=slippage,
|
slippage=slippage,
|
||||||
size=size,
|
size=size,
|
||||||
pricetick=pricetick,
|
pricetick=pricetick,
|
||||||
capital=capital
|
capital=capital,
|
||||||
|
inverse=inverse
|
||||||
)
|
)
|
||||||
|
|
||||||
strategy_class = self.classes[class_name]
|
strategy_class = self.classes[class_name]
|
||||||
@ -184,6 +186,7 @@ class BacktesterEngine(BaseEngine):
|
|||||||
size: int,
|
size: int,
|
||||||
pricetick: float,
|
pricetick: float,
|
||||||
capital: int,
|
capital: int,
|
||||||
|
inverse: bool,
|
||||||
setting: dict
|
setting: dict
|
||||||
):
|
):
|
||||||
if self.thread:
|
if self.thread:
|
||||||
@ -204,6 +207,7 @@ class BacktesterEngine(BaseEngine):
|
|||||||
size,
|
size,
|
||||||
pricetick,
|
pricetick,
|
||||||
capital,
|
capital,
|
||||||
|
inverse,
|
||||||
setting
|
setting
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -240,6 +244,7 @@ class BacktesterEngine(BaseEngine):
|
|||||||
size: int,
|
size: int,
|
||||||
pricetick: float,
|
pricetick: float,
|
||||||
capital: int,
|
capital: int,
|
||||||
|
inverse: bool,
|
||||||
optimization_setting: OptimizationSetting,
|
optimization_setting: OptimizationSetting,
|
||||||
use_ga: bool
|
use_ga: bool
|
||||||
):
|
):
|
||||||
@ -263,7 +268,8 @@ class BacktesterEngine(BaseEngine):
|
|||||||
slippage=slippage,
|
slippage=slippage,
|
||||||
size=size,
|
size=size,
|
||||||
pricetick=pricetick,
|
pricetick=pricetick,
|
||||||
capital=capital
|
capital=capital,
|
||||||
|
inverse=inverse
|
||||||
)
|
)
|
||||||
|
|
||||||
strategy_class = self.classes[class_name]
|
strategy_class = self.classes[class_name]
|
||||||
@ -303,6 +309,7 @@ class BacktesterEngine(BaseEngine):
|
|||||||
size: int,
|
size: int,
|
||||||
pricetick: float,
|
pricetick: float,
|
||||||
capital: int,
|
capital: int,
|
||||||
|
inverse: bool,
|
||||||
optimization_setting: OptimizationSetting,
|
optimization_setting: OptimizationSetting,
|
||||||
use_ga: bool
|
use_ga: bool
|
||||||
):
|
):
|
||||||
@ -324,6 +331,7 @@ class BacktesterEngine(BaseEngine):
|
|||||||
size,
|
size,
|
||||||
pricetick,
|
pricetick,
|
||||||
capital,
|
capital,
|
||||||
|
inverse,
|
||||||
optimization_setting,
|
optimization_setting,
|
||||||
use_ga
|
use_ga
|
||||||
)
|
)
|
||||||
|
@ -84,6 +84,9 @@ class BacktesterManager(QtWidgets.QWidget):
|
|||||||
self.pricetick_line = QtWidgets.QLineEdit("0.2")
|
self.pricetick_line = QtWidgets.QLineEdit("0.2")
|
||||||
self.capital_line = QtWidgets.QLineEdit("1000000")
|
self.capital_line = QtWidgets.QLineEdit("1000000")
|
||||||
|
|
||||||
|
self.inverse_combo = QtWidgets.QComboBox()
|
||||||
|
self.inverse_combo.addItems(["正向", "反向"])
|
||||||
|
|
||||||
backtesting_button = QtWidgets.QPushButton("开始回测")
|
backtesting_button = QtWidgets.QPushButton("开始回测")
|
||||||
backtesting_button.clicked.connect(self.start_backtesting)
|
backtesting_button.clicked.connect(self.start_backtesting)
|
||||||
|
|
||||||
@ -136,6 +139,7 @@ class BacktesterManager(QtWidgets.QWidget):
|
|||||||
form.addRow("合约乘数", self.size_line)
|
form.addRow("合约乘数", self.size_line)
|
||||||
form.addRow("价格跳动", self.pricetick_line)
|
form.addRow("价格跳动", self.pricetick_line)
|
||||||
form.addRow("回测资金", self.capital_line)
|
form.addRow("回测资金", self.capital_line)
|
||||||
|
form.addRow("合约模式", self.inverse_combo)
|
||||||
|
|
||||||
left_vbox = QtWidgets.QVBoxLayout()
|
left_vbox = QtWidgets.QVBoxLayout()
|
||||||
left_vbox.addLayout(form)
|
left_vbox.addLayout(form)
|
||||||
@ -248,6 +252,11 @@ class BacktesterManager(QtWidgets.QWidget):
|
|||||||
pricetick = float(self.pricetick_line.text())
|
pricetick = float(self.pricetick_line.text())
|
||||||
capital = float(self.capital_line.text())
|
capital = float(self.capital_line.text())
|
||||||
|
|
||||||
|
if self.inverse_combo.currentText() == "正向":
|
||||||
|
inverse = False
|
||||||
|
else:
|
||||||
|
inverse = True
|
||||||
|
|
||||||
old_setting = self.settings[class_name]
|
old_setting = self.settings[class_name]
|
||||||
dialog = BacktestingSettingEditor(class_name, old_setting)
|
dialog = BacktestingSettingEditor(class_name, old_setting)
|
||||||
i = dialog.exec()
|
i = dialog.exec()
|
||||||
@ -268,6 +277,7 @@ class BacktesterManager(QtWidgets.QWidget):
|
|||||||
size,
|
size,
|
||||||
pricetick,
|
pricetick,
|
||||||
capital,
|
capital,
|
||||||
|
inverse,
|
||||||
new_setting
|
new_setting
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -298,6 +308,11 @@ class BacktesterManager(QtWidgets.QWidget):
|
|||||||
pricetick = float(self.pricetick_line.text())
|
pricetick = float(self.pricetick_line.text())
|
||||||
capital = float(self.capital_line.text())
|
capital = float(self.capital_line.text())
|
||||||
|
|
||||||
|
if self.inverse_combo.currentText() == "正向":
|
||||||
|
inverse = False
|
||||||
|
else:
|
||||||
|
inverse = True
|
||||||
|
|
||||||
parameters = self.settings[class_name]
|
parameters = self.settings[class_name]
|
||||||
dialog = OptimizationSettingEditor(class_name, parameters)
|
dialog = OptimizationSettingEditor(class_name, parameters)
|
||||||
i = dialog.exec()
|
i = dialog.exec()
|
||||||
@ -318,6 +333,7 @@ class BacktesterManager(QtWidgets.QWidget):
|
|||||||
size,
|
size,
|
||||||
pricetick,
|
pricetick,
|
||||||
capital,
|
capital,
|
||||||
|
inverse,
|
||||||
optimization_setting,
|
optimization_setting,
|
||||||
use_ga
|
use_ga
|
||||||
)
|
)
|
||||||
|
@ -1157,7 +1157,8 @@ def optimize(
|
|||||||
pricetick: float,
|
pricetick: float,
|
||||||
capital: int,
|
capital: int,
|
||||||
end: datetime,
|
end: datetime,
|
||||||
mode: BacktestingMode
|
mode: BacktestingMode,
|
||||||
|
inverse: bool
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Function for running in multiprocessing.pool
|
Function for running in multiprocessing.pool
|
||||||
@ -1174,7 +1175,8 @@ def optimize(
|
|||||||
pricetick=pricetick,
|
pricetick=pricetick,
|
||||||
capital=capital,
|
capital=capital,
|
||||||
end=end,
|
end=end,
|
||||||
mode=mode
|
mode=mode,
|
||||||
|
inverse=inverse
|
||||||
)
|
)
|
||||||
|
|
||||||
engine.add_strategy(strategy_class, setting)
|
engine.add_strategy(strategy_class, setting)
|
||||||
|
Loading…
Reference in New Issue
Block a user