Exemplo n.º 1
0
    def __peakbottom(self,stockCode):
        cursor=self.connection.cursor()
        cursor.execute("select date,oprice,high,low,cprice,volume from "+self.table+" where stockCode=%s and date>=%s and date<=%s",[stockCode,self.fromDate,self.toDate])
        result = cursor.fetchall()

        ohlc=[]
        adr=0
        for row in result:
            # no,open,high,low,close,volume,date,peakbottom
            ohlc.append([adr,row[1],row[2],row[3],row[4],row[5],row[0],0,])
            adr=adr+1

        if len(ohlc)==0:
            return None

        cursor.close()
        open=np.asarray(ohlc)[:,1]
        high=np.asarray(ohlc)[:,2]
        low=np.asarray(ohlc)[:,3]
        close=np.asarray(ohlc)[:,4]
        try:
            #pivots = peak_valley_pivots(open,high,low,close, self.zigzag_upper, self.zigzag_lower)
            pivots = calc_peakbottom(open,high,low,close,self.pb_term)
            adr=0
            for p in pivots:
                ohlc[adr][self.PB_ADR]=p
                adr=adr+1
            return(ohlc)
        except:
            print "peak_valley_pivots ERROR"
            return None
Exemplo n.º 2
0
    def chart(self,stockCode):
        cursor=self.connection.cursor()
        cursor.execute("select date,oprice,high,low,cprice,volume from ST_priceHistAdj where stockCode=%s and date>=%s and date<=%s",[stockCode,self.fromDate,self.toDate])
        result = cursor.fetchall()

        ohlc=[]
        fdate=[]  # float
        ddate=[]  # datetime
        adr=1
        for row in result:
            tmp=adr
            ohlc.append((adr,row[1],row[2],row[3],row[4],row[5]))
            ddate.append(row[0])
            fdate.append(adr)
            adr=adr+1
        cursor.close()
        open=np.asarray(ohlc)[:,1]
        high=np.asarray(ohlc)[:,2]
        low=np.asarray(ohlc)[:,3]
        close=np.asarray(ohlc)[:,4]
        step=int(len(close)/5)
        # graph上のfloat型の日付と、表示文字列を紐付けている
        plt.xticks(fdate[::step],[x.strftime('%Y-%m-%d') for x in ddate][::step])

        ax = plt.subplot()
        candlestick_ohlc(ax,ohlc)

        # 5 日単純移動平均を求める
        #sma5 = ta.SMA(close, timeperiod=5)
        #plt.plot(sma5,label="SMA5")

        # trendline
        line=self.interpolation(100,200,3000,3500,len(close))
        plt.plot(line,label="line")

        # zigzag
        #pivots = peak_valley_pivots(open,high,low,close, 0.1, -0.1)
        pivots = calc_peakbottom(open,high,low,close,10)

        #plt.plot(pivots)
        print(pivots)
        ts_pivots = pd.Series(close)
        ts_pivots = ts_pivots[pivots != 0]
        plt.plot(ts_pivots,label="test")
        print (ts_pivots)

        plt.xlabel('Date')
        plt.ylabel('Price')
        plt.title("title")
        plt.legend()
        plt.show()