[Mod]调整OptionMaster的组合配置文件加载目录

This commit is contained in:
vn.py 2018-02-13 14:53:53 +08:00
parent a18b2a2b0d
commit 2b8f918866
4 changed files with 44 additions and 4 deletions

View File

@ -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
}
]
}

View File

@ -118,6 +118,9 @@ class OmUnderlying(OmInstrument):
"""Constructor""" """Constructor"""
super(OmUnderlying, self).__init__(contract, detail) super(OmUnderlying, self).__init__(contract, detail)
# 标的类型
self.productClass = contract.productClass
# 以该合约为标的物的期权链字典 # 以该合约为标的物的期权链字典
self.chainDict = OrderedDict() self.chainDict = OrderedDict()
@ -393,11 +396,15 @@ class OmChain(object):
for n, call in enumerate(callList): for n, call in enumerate(callList):
put = putList[n] put = putList[n]
# 如果标的为期货,则不进行调整
if call.underlying.productClass == PRODUCT_FUTURES:
return
# 如果有任意中间价为0则忽略该PCP # 如果有任意中间价为0则忽略该PCP
if (not call.underlying.midPrice or if (not call.underlying.midPrice or
not put.midPrice or not put.midPrice or
not call.midPrice or not call.midPrice or
not call.k, not call.k or
not call.t): not call.t):
continue continue
@ -406,6 +413,9 @@ class OmChain(object):
l.append(r) l.append(r)
# 求平均值来计算拟合折现率 # 求平均值来计算拟合折现率
if not l:
return
self.r = sum(l)/len(l) self.r = sum(l)/len(l)
for option in self.optionDict.values(): for option in self.optionDict.values():
option.setR(r) option.setR(r)

View File

@ -105,8 +105,9 @@ class OmEngine(object):
if self.portfolio: if self.portfolio:
return False return False
f = file(fileName) f = open(fileName)
setting = json.load(f) setting = json.load(f)
f.close()
# 读取定价模型 # 读取定价模型
model = MODEL_DICT.get(setting['model'], None) model = MODEL_DICT.get(setting['model'], None)

View File

@ -42,7 +42,7 @@ class OmManager(QtWidgets.QWidget):
# 读取配置文件 # 读取配置文件
settingFileList = [] settingFileList = []
path = os.path.abspath(os.path.dirname(__file__)) path = os.getcwd()
for root, subdirs, files in os.walk(path): for root, subdirs, files in os.walk(path):
for name in files: for name in files:
if '_portfolio.json' in name: if '_portfolio.json' in name:
@ -112,7 +112,7 @@ class OmManager(QtWidgets.QWidget):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def initOmEngine(self): def initOmEngine(self):
"""初始化引擎""" """初始化引擎"""
path = os.path.abspath(os.path.dirname(__file__)) path = os.getcwd()
fileName = unicode(self.comboSettingFile.currentText()) fileName = unicode(self.comboSettingFile.currentText())
fileName = os.path.join(path, fileName) fileName = os.path.join(path, fileName)
result = self.omEngine.initEngine(fileName) result = self.omEngine.initEngine(fileName)