コード例 #1
0
def single_data_cal_index(iSymbol):
    df = ts.pro_bar(api=pro,
                    ts_code=iSymbol,
                    adj='qfq',
                    start_date=start_fetch_date)
    df = df.sort_values('trade_date')

    df = ic.macd_index_cal(df)
    df = ic.kdj_index_cal(df)
    df = ic.ema_index_cal(df)
    df = ic.roc_index_cal(df)
    df = df.fillna(0)
    startDate = start_analysis_date
    df1 = df[df['trade_date'] >= startDate]
    df1.to_pickle('symbol_data/%s.pkl' % df1['ts_code'][0])
コード例 #2
0
ファイル: dataAnalysis.py プロジェクト: lechen36/Qigit
def single_data_cal_index(iSymbol, method='yahoo'):
    try:
        if method == 'yahoo':
            df = YFetchData(iSymbol, START_ANALYSIS_DATE).data
        elif method == 'tushare':
            df = TFetchData(iSymbol, START_ANALYSIS_DATE).data
        else:
            pass
        df = ic.macd_index_cal(df)
        df = ic.kdj_index_cal(df)
        df = ic.ema_index_cal(df)
        df = ic.roc_index_cal(df)
        df = df.fillna(0)
        df.to_pickle('symbol_data/%s.pkl' % df['ts_code'][0][:6])

    except:
        pass
コード例 #3
0
def download_data(iSymbol):
    try:
        df = yf.download(iSymbol, start="2018-01-01", auto_adjust=True)
        df.columns = ['open', 'high', 'low', 'close', 'volume']
        df.loc[:, 'ts_code'] = iSymbol
        df.loc[:, 'trade_date'] = df.index.strftime('%Y%m%d').values
        df = df[[
            'ts_code', 'trade_date', 'open', 'high', 'low', 'close', 'volume'
        ]]

        df = ic.macd_index_cal(df)
        df = ic.kdj_index_cal(df)
        df = ic.ema_index_cal(df)
        df = ic.roc_index_cal(df)
        df = df.fillna(0)
        df.to_pickle('symbol_data_yahoo/%s.pkl' % iSymbol)
        #print(df.head())
    except:
        pass
コード例 #4
0
    def _open_convert_ts_files(self):
        """
        Opens the tushare from www.tushare.com , converting
        them into pandas DataFrames within a symbol dictionary.

        For this handler it will be assumed that the data is
        taken from Yahoo. Thus its format will be respected.
        """
        comb_index = None
        for s in self.symbol_list:
            # Load the tushare with no header information, indexed on date
            start1 = self.start_date.strftime('%Y%m%d')
            ts.set_token(
                'bf3b4e51fcc67507e8694e9a3f2bd591be93bea276f9d86f564fe28f')
            pro = ts.pro_api()
            df = ts.pro_bar(api=pro, ts_code=s, adj='qfq', start_date=start1)
            df.index = pd.DatetimeIndex(df.trade_date)
            df = df.sort_index()
            df = ic.ema_index_cal(df)
            df = ic.macd_index_cal(df)
            df = ic.kdj_index_cal(df)
            df = ic.roc_index_cal(df)
            df = df.fillna(0)
            self.symbol_data[s] = df

            # Combine the index to pad forward values
            if comb_index is None:
                comb_index = self.symbol_data[s].index
            else:
                comb_index.union(self.symbol_data[s].index)

            # Set the latest symbol_data to None
            self.latest_symbol_data[s] = []

        # Reindex the dataframes
        for s in self.symbol_list:
            self.symbol_data[s] = self.symbol_data[s].\
                reindex(index=comb_index, method='pad').iterrows()
コード例 #5
0
        ax2 = plt.axes([0.1, 0.1, 0.8, 0.2], sharex=ax1)
        ax2.plot(df['iNum'], df[['incomeSum']])
        # make these tick labels invisible
        ax2.set_ylabel('incomeSum')
        ax2.grid(True)
        plt.setp(ax2.get_xticklabels(), visible=True)
    return fig


if __name__ == '__main__':
    import tushare as ts
    import indexCal as ic
    ts.set_token('bf3b4e51fcc67507e8694e9a3f2bd591be93bea276f9d86f564fe28f')
    pro = ts.pro_api()
    df = ts.pro_bar(api=pro,
                    ts_code='000002.SZ',
                    adj='qfq',
                    start_date='20181201')
    #df = ts.pro_bar(ts_code='399005.SH', asset='I', start_date='20180101', end_date='20181212')
    #df=df.sort_values('trade_date')
    df = df.sort_values('trade_date')
    df['iNum'] = np.arange(len(df))
    df = ic.macd_index_cal(df)
    df = ic.kdj_index_cal(df)
    df = ic.roc_index_cal(df)
    df = ic.vol_index_cal(df)

    df['iNum'] = np.arange(len(df))
    date_tickers = df['trade_date']
    kplot(df, 'MACD')