diff --git a/examples/OptionMaster/etf_portfolio.json b/examples/OptionMaster/etf_portfolio.json new file mode 100644 index 00000000..8de8b975 --- /dev/null +++ b/examples/OptionMaster/etf_portfolio.json @@ -0,0 +1,29 @@ +{ + "name": "etf_portfolio", + "model": "bsCython", + "underlying": [ + "510050" + ], + "chain": [ + { + "underlyingSymbol": "510050", + "chainSymbol": "510050-1802", + "r": 0.04 + }, + { + "underlyingSymbol": "510050", + "chainSymbol": "510050-1803", + "r": 0.03 + }, + { + "underlyingSymbol": "510050", + "chainSymbol": "510050-1806", + "r": 0.03 + }, + { + "underlyingSymbol": "510050", + "chainSymbol": "510050-1809", + "r": 0.03 + } + ] +} \ No newline at end of file diff --git a/vnpy/trader/app/optionMaster/omBase.py b/vnpy/trader/app/optionMaster/omBase.py index d2fb2aec..942db8e8 100644 --- a/vnpy/trader/app/optionMaster/omBase.py +++ b/vnpy/trader/app/optionMaster/omBase.py @@ -118,6 +118,9 @@ class OmUnderlying(OmInstrument): """Constructor""" super(OmUnderlying, self).__init__(contract, detail) + # 标的类型 + self.productClass = contract.productClass + # 以该合约为标的物的期权链字典 self.chainDict = OrderedDict() @@ -393,11 +396,15 @@ class OmChain(object): for n, call in enumerate(callList): put = putList[n] + # 如果标的为期货,则不进行调整 + if call.underlying.productClass == PRODUCT_FUTURES: + return + # 如果有任意中间价为0,则忽略该PCP if (not call.underlying.midPrice or not put.midPrice or not call.midPrice or - not call.k, + not call.k or not call.t): continue @@ -406,6 +413,9 @@ class OmChain(object): l.append(r) # 求平均值来计算拟合折现率 + if not l: + return + self.r = sum(l)/len(l) for option in self.optionDict.values(): option.setR(r) diff --git a/vnpy/trader/app/optionMaster/omEngine.py b/vnpy/trader/app/optionMaster/omEngine.py index 008997a6..7d17ec85 100644 --- a/vnpy/trader/app/optionMaster/omEngine.py +++ b/vnpy/trader/app/optionMaster/omEngine.py @@ -105,8 +105,9 @@ class OmEngine(object): if self.portfolio: return False - f = file(fileName) + f = open(fileName) setting = json.load(f) + f.close() # 读取定价模型 model = MODEL_DICT.get(setting['model'], None) diff --git a/vnpy/trader/app/optionMaster/uiOmWidget.py b/vnpy/trader/app/optionMaster/uiOmWidget.py index b857bacb..ea770808 100644 --- a/vnpy/trader/app/optionMaster/uiOmWidget.py +++ b/vnpy/trader/app/optionMaster/uiOmWidget.py @@ -42,7 +42,7 @@ class OmManager(QtWidgets.QWidget): # 读取配置文件 settingFileList = [] - path = os.path.abspath(os.path.dirname(__file__)) + path = os.getcwd() for root, subdirs, files in os.walk(path): for name in files: if '_portfolio.json' in name: @@ -112,7 +112,7 @@ class OmManager(QtWidgets.QWidget): #---------------------------------------------------------------------- def initOmEngine(self): """初始化引擎""" - path = os.path.abspath(os.path.dirname(__file__)) + path = os.getcwd() fileName = unicode(self.comboSettingFile.currentText()) fileName = os.path.join(path, fileName) result = self.omEngine.initEngine(fileName)