[Add]新增波动率图表
This commit is contained in:
parent
796adc7673
commit
af31162849
@ -14,6 +14,16 @@
|
|||||||
"underlyingSymbol": "510050",
|
"underlyingSymbol": "510050",
|
||||||
"chainSymbol": "510050-1801",
|
"chainSymbol": "510050-1801",
|
||||||
"r": 0.03
|
"r": 0.03
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"underlyingSymbol": "510050",
|
||||||
|
"chainSymbol": "510050-1803",
|
||||||
|
"r": 0.03
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"underlyingSymbol": "510050",
|
||||||
|
"chainSymbol": "510050-1806",
|
||||||
|
"r": 0.03
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
126
vnpy/trader/app/optionMaster/uiOmVolatilityManager.py
Normal file
126
vnpy/trader/app/optionMaster/uiOmVolatilityManager.py
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
import pyqtgraph as pg
|
||||||
|
|
||||||
|
from vnpy.event import Event
|
||||||
|
from vnpy.trader.vtEvent import EVENT_TIMER
|
||||||
|
from .uiOmBase import *
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
class VolatilityChart(pg.GraphicsWindow):
|
||||||
|
"""持仓组合波动率图表"""
|
||||||
|
signal = QtCore.pyqtSignal(type(Event()))
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def __init__(self, omEngine, parent=None):
|
||||||
|
"""Constructor"""
|
||||||
|
super(VolatilityChart, self).__init__(parent)
|
||||||
|
|
||||||
|
self.omEngine = omEngine
|
||||||
|
self.portfolio = omEngine.portfolio
|
||||||
|
self.eventEngine = omEngine.eventEngine
|
||||||
|
|
||||||
|
self.updateCount = 0
|
||||||
|
self.updateTrigger = 2
|
||||||
|
|
||||||
|
self.bidCurveDict = {}
|
||||||
|
self.askCurveDict = {}
|
||||||
|
self.pricingCurveDict = {}
|
||||||
|
|
||||||
|
self.initUi()
|
||||||
|
self.registerEvent()
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def initUi(self):
|
||||||
|
"""初始化界面"""
|
||||||
|
portfolio = self.portfolio
|
||||||
|
|
||||||
|
self.setWindowTitle(u'波动率图表')
|
||||||
|
|
||||||
|
pg.setConfigOptions(antialias=True) #启用抗锯齿
|
||||||
|
|
||||||
|
# 创建绘图区以及线
|
||||||
|
for chain in portfolio.chainDict.values():
|
||||||
|
symbol = chain.symbol + CALL_SUFFIX
|
||||||
|
|
||||||
|
chart = self.addPlot(title=symbol)
|
||||||
|
chart.showGrid(x=True, y=True)
|
||||||
|
chart.setLabel('left', u'波动率') #设置左边标签
|
||||||
|
chart.setLabel('bottom', u'行权价') #设置底部标签
|
||||||
|
|
||||||
|
self.bidCurveDict[symbol] = chart.plot(pen='r', symbol='t', symbolSize=8, symbolBrush='r')
|
||||||
|
self.askCurveDict[symbol] = chart.plot(pen='g', symbolSize=8, symbolBrush='g')
|
||||||
|
self.pricingCurveDict[symbol] = chart.plot(pen='w', symbol = 's', symbolSize=8, symbolBrush='w')
|
||||||
|
|
||||||
|
self.nextRow()
|
||||||
|
|
||||||
|
for chain in portfolio.chainDict.values():
|
||||||
|
symbol = chain.symbol + PUT_SUFFIX
|
||||||
|
|
||||||
|
chart = self.addPlot(title=symbol)
|
||||||
|
chart.showGrid(x=True, y=True)
|
||||||
|
chart.setLabel('left', u'波动率')
|
||||||
|
chart.setLabel('bottom', u'行权价')
|
||||||
|
|
||||||
|
self.bidCurveDict[symbol] = chart.plot(pen='r', symbol='t', symbolSize=8, symbolBrush='r')
|
||||||
|
self.askCurveDict[symbol] = chart.plot(pen='g', symbolSize=8, symbolBrush='g')
|
||||||
|
self.pricingCurveDict[symbol] = chart.plot(pen='w', symbol = 's', symbolSize=8, symbolBrush='w')
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def registerEvent(self):
|
||||||
|
"""注册事件监听"""
|
||||||
|
self.signal.connect(self.processTimerEvent)
|
||||||
|
self.eventEngine.register(EVENT_TIMER, self.signal.emit)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def processTimerEvent(self, event):
|
||||||
|
"""处理定时事件"""
|
||||||
|
self.updateCount += 1
|
||||||
|
if self.updateCount >= self.updateTrigger:
|
||||||
|
self.updateCount = 0
|
||||||
|
self.updateChart()
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def updateChart(self):
|
||||||
|
"""更新图表"""
|
||||||
|
for chain in self.portfolio.chainDict.values():
|
||||||
|
strikeData = [option.k for option in chain.callDict.values()]
|
||||||
|
|
||||||
|
# 看涨
|
||||||
|
symbol = chain.symbol + CALL_SUFFIX
|
||||||
|
|
||||||
|
bidImpvData = []
|
||||||
|
askImpvData = []
|
||||||
|
pricingImpvData = []
|
||||||
|
|
||||||
|
for option in chain.callDict.values():
|
||||||
|
bidImpvData.append(option.bidImpv*100)
|
||||||
|
askImpvData.append(option.askImpv*100)
|
||||||
|
pricingImpvData.append(option.pricingImpv*100)
|
||||||
|
|
||||||
|
self.bidCurveDict[symbol].setData(y=bidImpvData, x=strikeData)
|
||||||
|
self.askCurveDict[symbol].setData(y=askImpvData, x=strikeData)
|
||||||
|
self.pricingCurveDict[symbol].setData(y=pricingImpvData, x=strikeData)
|
||||||
|
|
||||||
|
# 看跌
|
||||||
|
symbol = chain.symbol + PUT_SUFFIX
|
||||||
|
|
||||||
|
bidImpvData = []
|
||||||
|
askImpvData = []
|
||||||
|
pricingImpvData = []
|
||||||
|
|
||||||
|
for option in chain.putDict.values():
|
||||||
|
bidImpvData.append(option.bidImpv*100)
|
||||||
|
askImpvData.append(option.askImpv*100)
|
||||||
|
pricingImpvData.append(option.pricingImpv*100)
|
||||||
|
|
||||||
|
self.bidCurveDict[symbol].setData(y=bidImpvData, x=strikeData)
|
||||||
|
self.askCurveDict[symbol].setData(y=askImpvData, x=strikeData)
|
||||||
|
self.pricingCurveDict[symbol].setData(y=pricingImpvData, x=strikeData)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def closeEvent(self, event):
|
||||||
|
"""关闭"""
|
||||||
|
self.eventEngine.unregister(EVENT_TIMER, self.signal.emit)
|
||||||
|
|
@ -11,6 +11,7 @@ from .omBase import EVENT_OM_LOG
|
|||||||
from .uiOmBase import QtWidgets, QtCore
|
from .uiOmBase import QtWidgets, QtCore
|
||||||
from .uiOmManualTrader import ManualTrader
|
from .uiOmManualTrader import ManualTrader
|
||||||
from .uiOmGreeksMonitor import GreeksMonitor
|
from .uiOmGreeksMonitor import GreeksMonitor
|
||||||
|
from .uiOmVolatilityManager import VolatilityChart
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -59,6 +60,9 @@ class OmManager(QtWidgets.QWidget):
|
|||||||
self.buttonGreeksMonitor = QtWidgets.QPushButton(u'希腊值监控')
|
self.buttonGreeksMonitor = QtWidgets.QPushButton(u'希腊值监控')
|
||||||
self.buttonGreeksMonitor.clicked.connect(self.openGreeksMonitor)
|
self.buttonGreeksMonitor.clicked.connect(self.openGreeksMonitor)
|
||||||
|
|
||||||
|
self.buttonVolatilityChart = QtWidgets.QPushButton(u'波动率图表')
|
||||||
|
self.buttonVolatilityChart.clicked.connect(self.openVolatilityChart)
|
||||||
|
|
||||||
self.logMonitor = QtWidgets.QTextEdit()
|
self.logMonitor = QtWidgets.QTextEdit()
|
||||||
self.logMonitor.setReadOnly(True)
|
self.logMonitor.setReadOnly(True)
|
||||||
|
|
||||||
@ -67,6 +71,7 @@ class OmManager(QtWidgets.QWidget):
|
|||||||
hbox.addWidget(self.buttonInit)
|
hbox.addWidget(self.buttonInit)
|
||||||
hbox.addWidget(self.buttonManualTrader)
|
hbox.addWidget(self.buttonManualTrader)
|
||||||
hbox.addWidget(self.buttonGreeksMonitor)
|
hbox.addWidget(self.buttonGreeksMonitor)
|
||||||
|
hbox.addWidget(self.buttonVolatilityChart)
|
||||||
hbox.addStretch()
|
hbox.addStretch()
|
||||||
|
|
||||||
hbox2 = QtWidgets.QHBoxLayout()
|
hbox2 = QtWidgets.QHBoxLayout()
|
||||||
@ -125,13 +130,22 @@ class OmManager(QtWidgets.QWidget):
|
|||||||
self.widgetDict['greeksMonitor'] = GreeksMonitor(self.omEngine)
|
self.widgetDict['greeksMonitor'] = GreeksMonitor(self.omEngine)
|
||||||
self.widgetDict['greeksMonitor'].showMaximized()
|
self.widgetDict['greeksMonitor'].showMaximized()
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
def openVolatilityChart(self):
|
||||||
|
"""打开波动率图表组件"""
|
||||||
|
try:
|
||||||
|
self.widgetDict['volatilityChart'].showMaximized()
|
||||||
|
except KeyError:
|
||||||
|
self.widgetDict['volatilityChart'] = VolatilityChart(self.omEngine)
|
||||||
|
self.widgetDict['volatilityChart'].showMaximized()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def close(self):
|
def close(self):
|
||||||
"""关闭"""
|
"""关闭"""
|
||||||
for widget in self.widgetDict.values():
|
for widget in self.widgetDict.values():
|
||||||
widget.close()
|
widget.close()
|
||||||
|
|
||||||
super(OmManagerWidget, self).close()
|
super(OmManager, self).close()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def registerEvent(self):
|
def registerEvent(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user