示例#1
0
    def initplotTick(self):
        """"""

        import pandas as pd

        class ValuesParser:
            def __init__(self, dataframe):
                self.Data = [
                    data['open'].tolist(), data['high'].tolist(),
                    data['low'].tolist(), data['close'].tolist(),
                    data['volume'].tolist()
                ]
                self.Times = data.index.tolist()

        data = pd.DataFrame.from_csv('rb1705_year.csv')[10000:11100]
        data = ValuesParser(data)

        global dataToNow
        #dataToNow = w.wst(code, "last", data.Times[-1], nowTime, "")
        dataToNow = []

        quotes = []
        for i in range(len(data.Times)):
            quotes.append([
                i, data.Data[0][i], data.Data[3][i], data.Data[2][i],
                data.Data[1][i]
            ])

        global chan
        #chan = Chan(data.Data[0], data.Data[1], data.Data[2],data.Data[3], data.Data[4], data.Times)
        chan = Chan([], [], [], [], [], [])

        print(len(data.Times))
        start = 1000
        for tick in range(0, start):
            chan.append(data.Data[0][tick], data.Data[1][tick],
                        data.Data[2][tick], data.Data[3][tick],
                        data.Data[4][tick], data.Times[tick])

        for tick in range(start, len(data.Times)):
            chan.append(data.Data[0][tick], data.Data[1][tick],
                        data.Data[2][tick], data.Data[3][tick],
                        data.Data[4][tick], data.Times[tick])
            chan.barsMerge()
            chan.findFenxing()
            chan.findBi()
            chan.findLines()
            chan.findZhongshus()
            chan.calculate_ta()
            chan.findBiZhongshus()
            chan.macdSeparate()
            chan.findTrendLines()
            chan.decisionBi()

        #chan.plotBuySell()
        chan.plotBeichi()
        #chan.plotBiZhongshu()
        #plt.show()
        print(len(chan.dingbeichi))

        #win = pg.GraphicsWindow()
        layout = QtGui.QVBoxLayout(self)
        win = pg.GraphicsLayoutWidget(self)
        layout.addWidget(win)
        self.setLayout(layout)

        #win = ApplicationWindow()
        win.setWindowTitle('行情+缠论')
        label = pg.LabelItem(justify="center")
        win.addItem(label)
        axis = self.DateAxis(data.Times, orientation='bottom')
        p1 = win.addPlot(row=1, col=0, axisItems={'bottom': axis})
        p2 = win.addPlot(row=2, col=0, axisItems={'bottom': axis})
        p2.setXLink(p1)
        p2.plot(x=list(range(len(data.Times))), y=chan.diff, pen='w')
        p2.plot(x=list(range(len(data.Times))), y=chan.dea, pen='y')
        hLine = pg.InfiniteLine(angle=0, movable=False)
        hLine.setPos(0)
        p2.addItem(hLine, ignoreBounds=True)
        macdPositive = []
        macdNegetive = []
        for i in chan.macd:
            if i >= 0:
                macdPositive.append(i)
                macdNegetive.append(0)
            else:
                macdPositive.append(0)
                macdNegetive.append(i)

        curve0 = p2.plot(x=list(range(len(data.Times))),
                         y=np.zeros(len(data.Times)))
        curve1 = p2.plot(x=list(range(len(data.Times))),
                         y=macdPositive,
                         pen='w')
        curve2 = p2.plot(x=list(range(len(data.Times))),
                         y=macdNegetive,
                         pen='w')
        itemFill1 = pg.FillBetweenItem(curve0, curve1, pg.mkBrush('r'))
        itemFill2 = pg.FillBetweenItem(curve0, curve2, pg.mkBrush('g'))
        p2.addItem(itemFill1)
        p2.addItem(itemFill2)

        #win.addItem(label)
        #text = pg.TextItem('test',anchor=(0,1))
        # p1.addItem(text)

        itemK = self.CandlestickItem()
        itemK.set_data(quotes)
        itemBi = self.BisItem()
        itemBi.set_data(chan.bis)
        itemLine = self.LinesItem()
        itemLine.set_data(chan.lines)
        itemZhongshu = self.ZhongshusItem()
        #itemZhongshu.set_data(chan.zhongshus)
        itemZhongshu.set_data(chan.biZhongshus)

        itemDiBeiChi = self.BeiChiItem()
        itemDiBeiChi.set_data(chan.dibeichi)
        itemDingBeiChi = self.BeiChiItem()
        itemDingBeiChi.set_data(chan.dingbeichiLine)
        itemTrendDiBeiChi = self.BeiChiItem()
        itemTrendDiBeiChi.set_data(chan.trendDibeichi)
        itemTrendDingBeiChi = self.BeiChiItem()
        itemTrendDingBeiChi.set_data(chan.trendDingbeichi)

        p1.plot()
        p1.addItem(itemK)
        p1.addItem(itemBi)
        p1.addItem(itemLine)
        p1.addItem(itemZhongshu)
        p1.addItem(itemDiBeiChi)
        p1.addItem(itemDingBeiChi)
        p1.addItem(itemTrendDiBeiChi)
        p1.addItem(itemTrendDingBeiChi)
        p1.showGrid(x=True, y=True)

        #p1.setWindowTitle('pyqtgraph example: customGraphicsItem')

        # cross hair
        vLine = pg.InfiniteLine(angle=90, movable=False)
        hLine = pg.InfiniteLine(angle=0, movable=False)
        p1.addItem(vLine, ignoreBounds=True)
        p1.addItem(hLine, ignoreBounds=True)

        vb1 = p1.vb
        vb2 = p2.vb

        def mouseMoved(evt):
            pos = evt[
                0]  # using signal proxy turns original arguments into a tuple
            print("..")
            if p1.sceneBoundingRect().contains(pos):
                mousePoint = vb1.mapSceneToView(pos)
                index = int(mousePoint.x())
                if index > 0 and index < len(quotes):
                    label.setText(
                        "<span style='font-size: 12pt'>date=%s,   <span style='color: red'>open=%0.01f</span>,   <span style='color: green'>close=%0.01f\n, high = %0.01f, low = %0.01f</span>"
                        % (data.Times[index].strftime('%Y%m%d,%H:%M'),
                           quotes[index][1], quotes[index][2],
                           quotes[index][3], quotes[index][4]))
                vLine.setPos(mousePoint.x())
                hLine.setPos(mousePoint.y())
            setYRange()

        def setYRange():
            r = vb1.viewRange()
            xmin = math.floor(r[0][0])
            xmax = math.ceil(r[0][1])

            #fix index <0 bug
            xmax = max(0, xmax - xmin)
            xmin = max(0, xmin)

            xmin = min(xmin, len(data.Times))
            xmax = min(xmax, len(data.Times))
            xmax = max(xmin, xmax)
            if (xmin == xmax):
                return

            highBound1 = max(data.Data[1][xmin:xmax])
            lowBound1 = min(data.Data[2][xmin:xmax])
            p1.setRange(yRange=(lowBound1, highBound1))
            highBound2 = max(chan.diff[xmin:xmax])
            lowBound2 = min(chan.diff[xmin:xmax])
            p2.setRange(yRange=(lowBound2, highBound2))

        #self.pw1 = win
        #self.vbl_1.addWidget(self.pw1)

        #self.setMouseTracking(True)

        proxy = pg.SignalProxy(p1.scene().sigMouseMoved,
                               rateLimit=60,
                               slot=mouseMoved)
        self.proxy = proxy
示例#2
0
文件: qt.py 项目: bigdig/chanlun-1
for tick in range(start, len(data.Times)):
    chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick],
                data.Data[3][tick], data.Data[4][tick], data.Times[tick])
    chan.barsMerge()
    chan.findFenxing()
    chan.findBi()
    chan.findLines()
    chan.findZhongshus()
    chan.calculate_ta()
    chan.findBiZhongshus()
    chan.macdSeparate()
    chan.findTrendLines()
    chan.decisionBi()

#chan.plotBuySell()
chan.plotBeichi()
plt.show()
print(len(chan.dingbeichi))

# app = QtGui.QApplication([])
# win = pg.GraphicsWindow()
# win.setWindowTitle('行情+缠论')
# label = pg.LabelItem(justify = "center")
# win.addItem(label)
# axis = DateAxis(data.Times,orientation='bottom')
# p1 = win.addPlot(row=1, col=0,axisItems = {'bottom':axis})
# p2 = win.addPlot(row=2, col=0,axisItems = {'bottom':axis})
# p2.setXLink(p1)
# p2.plot(x = list(range(len(data.Times))),y = chan.diff,pen = 'w')
# p2.plot(x = list(range(len(data.Times))),y = chan.dea,pen = 'y')
# hLine = pg.InfiniteLine(angle=0, movable=False)