From 2b8f9188661f59820196936dcf3dbbd6df853759 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 13 Feb 2018 14:53:53 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E8=B0=83=E6=95=B4OptionMaster=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E5=90=88=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/OptionMaster/etf_portfolio.json | 29 ++++++++++++++++++++++ vnpy/trader/app/optionMaster/omBase.py | 12 ++++++++- vnpy/trader/app/optionMaster/omEngine.py | 3 ++- vnpy/trader/app/optionMaster/uiOmWidget.py | 4 +-- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 examples/OptionMaster/etf_portfolio.json 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)