Пример #1
0
 def getLastOneAndADV(self, code):
     import DBStock.dbQueryPools as dbpool
     import tools.timeTool as tT
     #print(tT.getDateStrNow(), tT.getDateStrBefore())
     ts = dbpool.queryMySQL_plot_stock_market(code, tT.getDateStrBefore(), tT.getDateStrNow())
     #print(ts)
     ts['Date'] = pd.to_datetime(ts['Date'])
     ts.set_index('Date', inplace=True)
     ts = ts[(True^ts['Close'].isin([0]))]#条件删除去除值为0的行
     import FeatureBase.FeatureUtils as FU
     ts = FU.ADV(ts)
     #打印不换行
     #pd.set_option('display.height',1000)
     #pd.set_option('display.max_rows',500)
     #pd.set_option('display.max_columns',500)
     pd.set_option('display.width',1000)
     #print(ts.tail(1))
     #self.dataAndADV = ts
     return ts.tail(1)
Пример #2
0
    '''#FeatureUtils.py
    start = datetime.datetime(2012, 1, 1)
    end = datetime.datetime(2013, 1, 1)
    NSEI = web.DataReader("AREX", "yahoo", start, end)
    data = pd.DataFrame(NSEI)
    #print(data)
    # Compute the Bollinger Bands for NIFTY using the 50-day Moving average
    n = 12
    NIFTY_BBANDS = BBANDS(data, n)
    print(NIFTY_BBANDS)'''

    startdate = '2017-12-09'
    enddate = '2018-12-13'
    code = '600016'
    import DBStock.dbQueryPools as dbpool
    data = dbpool.queryMySQL_plot_stock_market(code, startdate, enddate)
    #print(data)
    '''n = 12
    NIFTY_BBANDS = BBANDS(data, n)
    print(NIFTY_BBANDS)'''
    '''n = 20
    NIFTY_CCI = CCI(data, n)
    CCI = NIFTY_CCI['CCI']
    print(NIFTY_CCI)

    # Plotting the Price Series chart and the Commodity Channel index below
    fig = plt.figure(figsize=(7,5))
    ax = fig.add_subplot(2, 1, 1)
    ax.set_xticklabels([])
    plt.plot(data['Close'],lw=1)
    plt.title('NSE Price Chart')
def create_lagged_series(symbol, startdate, enddate, lags=5):

    # Obtain stock information from Yahoo Finance
    '''ts = DataReader(
    	symbol, "yahoo",
    	startdate-datetime.timedelta(days=365),
    	enddate
    )'''

    import DBStock.dbQueryPools as dbpool
    ts = dbpool.queryMySQL_plot_stock_market(symbol, startdate, enddate)
    ts['Date'] = pd.to_datetime(ts['Date'])
    ts.set_index('Date', inplace=True)
    ts = ts[(True^ts['Close'].isin([0]))]#条件删除去除值为0的行
    #打印不换行
    #pd.set_option('display.height',1000)
    #pd.set_option('display.max_rows',500)
    #pd.set_option('display.max_columns',500)
    pd.set_option('display.width',1000)
    print(ts)

    # Create the new lagged DataFrame
    tslag = pd.DataFrame(index=ts.index)
    tslag["Today"] = ts["Close"]
    tslag["Volume"] = ts["Volume"]


    # Create the shifted lag series of prior trading period close values
    for i in range(0, lags):
        tslag["Lag%s" % str(i+1)] = ts["Close"].shift(i+1)
    #print(tslag)

    # Create the returns DataFrame
    tsret = pd.DataFrame(index=tslag.index)
    #tsret["Volume"] = tslag["Volume"]
    tsret["Today"] = tslag["Today"].pct_change()*100.0
    #tsret["Close"] = ts["Close"]
    tsret = tsret.join(ts)
    #print('tsret')
    #print(tsret)

    # If any of the values of percentage returns equal zero, set them to
    # a small number (stops issues with QDA model in scikit-learn)
    for i,x in enumerate(tsret["Today"]):
        if (abs(x) < 0.0001):
            tsret["Today"][i] = 0.0001
    #print(tsret)

    # Create the lagged percentage returns columns
    for i in range(0, lags):
        tsret["Lag%s" % str(i+1)] = \
        tsret["Today"].shift(i+1)
        #tslag["Lag%s" % str(i+1)].pct_change()*100.0
        #if (abs(tsret["Lag%s" % str(i+1)]) < 0.0001):
        #    tsret["Lag%s" % str(i+1)] = 0.0001
    #print(tsret)

    # Create the "Direction" column (+1 or -1) indicating an up/down day
    tsret["TargetValue"] = tsret["Close"].shift(-1)
    tsret = tsret[tsret.index >= startdate]

    return tsret