Beispiel #1
0
    def generate_factor(self):

        trade_cal = tools.get_trade_cal(self.start_date, self.end_date)
        skew = DataFrame()
        for date in trade_cal:
            r_daily = DataFrame()
            files = os.listdir('%s/StockSnapshootData/%s' %
                               (gc.DATABASE_PATH, date))
            try:
                data_dic = {
                    file.split('.')[1]:
                    pd.read_csv('%s/StockSnapshootData/%s/%s' %
                                (gc.DATABASE_PATH, date, file),
                                index_col=[0],
                                parse_dates=[0])
                    for file in files
                }
            except:
                print(date)
            keys = list(data_dic.keys())
            for key in keys:
                if len(data_dic[key]) == 0:
                    del data_dic[key]
            price = DataFrame({
                '%s.SZ' % stock: data_dic[stock].loc[:, 'price']
                for stock in data_dic.keys()
            })
            price.fillna(method='ffill', inplace=True)
            price = price.loc[(price.index > '%s093000' %
                               (date.replace('-', ''))) &
                              (price.index < '%s150100' %
                               (date.replace('-', ''))), :]
            r_daily = np.log(price).diff()
            r_daily.fillna(0, inplace=True)
            skew_daily = r_daily.resample(rule='15T').sum().skew()
            skew = pd.concat([skew, DataFrame({date: skew_daily}).T], axis=0)
            print(skew)
        a = skew
        self.factor = a
import os
import sys
import time
import datetime
import numpy as np
import pandas as pd
from pandas import Series, DataFrame

import Config

sys.path.append(Config.GLOBALCONFIG_PATH)
import Global_Config as gc
import tools

date = datetime.datetime.today().strftime('%Y%m%d')
trade_cal = tools.get_trade_cal(start_date=date, end_date=date)
if len(trade_cal) == 0:
    sys.exit()

if len(sys.argv) == 2:
    today = sys.argv[1]
else:
    today = datetime.datetime.today().strftime('%Y%m%d')

start = today
end = today

pro = ts.pro_api()

#获取行业分类
stocks = pro.stock_basic(fields='ts_code').ts_code