Exemple #1
0
def run(firstRun_update, start, end, fre, index_code, dir_path,
        beachmark_file):
    if not os.path.exists('%s' % beachmark_file):
        os.mkdir('%s' % beachmark_file)
    if not os.path.exists('%s/%s' % (beachmark_file, index_code)):
        os.mkdir('%s/%s' % (beachmark_file, index_code))
    if firstRun_update == 0:
        trade_day = get_tradeDay.wind(start, end, fre)
        for i in trade_day:
            print(i)
            df = pd.read_excel('%s/000846weightnextday%s.xls' % (dir_path, i),
                               dtype={u'成分券代码\nConstituent Code': str})
            df = df.iloc[:, [4, 16]]
            df.columns = ['code', 'weight']
            df['code'] = df['code'].apply(lambda x: x + '-CN')
            df.to_csv('%s/%s/benchmark_%s.csv' %
                      (beachmark_file, index_code, i),
                      index=None,
                      header=None)
    elif firstRun_update == 1:
        cal = Calendar('China.SSE')
        today = strftime("%Y%m%d", localtime())
        today = Date.strptime(today, '%Y%m%d')
        today = cal.advanceDate(today, Period('-1b'))
        today = today.strftime("%Y%m%d")
        df = pd.read_excel('%s/000846weightnextday%s.xls' % (dir_path, today),
                           dtype={u'成分券代码\nConstituent Code': str})
        df = df.iloc[:, [4, 16]]
        df.columns = ['code', 'weight']
        df['code'] = df['code'].apply(lambda x: x + '-CN')
        df.to_csv('%s/%s/benchmark_%s.csv' %
                  (beachmark_file, index_code, today),
                  index=None,
                  header=None)
 def forward_date(date, tenor, date_format='%Y-%m-%d'):
     try:
         start_date = Date.strptime(date, date_format)
         sse_cal = Calendar('China.SSE')
         ret = sse_cal.advanceDate(start_date,
                                   Period('-' + tenor),
                                   endOfMonth=True)
         # 此处返回的是上一期期末日期,再向后调整一天,以避免区间日期重叠
         ret = sse_cal.advanceDate(ret, Period('1b'))
         return str(ret)
     except NameError:
         pass
Exemple #3
0
def factor_multi():
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    today = today.strftime("%Y%m%d")

    update_risk_factor(today)
    update_barra_factor(today)
    update_stdfcf(today)
    update_stdni(today)
    update_pmom(today)
    update_to_reverse(today)
Exemple #4
0
 def forward_date(date, tenor, date_format='%Y-%m-%d'):
     try:
         # use pyfin instead to get more accurate and flexible date math
         start_date = Date.strptime(date, date_format)
         sseCal = Calendar('China.SSE')
         ret = sseCal.advanceDate(start_date,
                                  Period('-' + tenor),
                                  endOfMonth=True)
         # 此处返回的是上一期期末日期,再向后调整一天,以避免区间日期重叠
         ret = sseCal.advanceDate(ret, Period('1b'))
         return str(ret)
     except NameError:
         pass
Exemple #5
0
def insider_data():
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    today = today.strftime("%Y%m%d")

    N = -1
    Fre = 'Y'
    Halflife = 180.0
    datapath = 'F:/factor_data/Insider_Data/'
    barapath = 'Z:/axioma_data/barra_model/Exposure/'
    outputpath = 'F:/factor_data/test_data/'

    update_insider_data([today], N, Fre, datapath, barapath)
Exemple #6
0
def base_data():
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    today = today.strftime("%Y%m%d")

    update_barra_model()

    update_risk_model()
    update_risk_tolocal()

    update_esg100_weight()
    update_csi_weight()
    update_barra_model_backtest(today)
Exemple #7
0
def suspend(day, dirpath, getdb):
    sql = 'select S_INFO_WINDCODE from wind.AShareTradingSuspension t where S_DQ_SUSPENDDATE = %s and S_DQ_RESUMPDATE is null' % (
        day)
    df = getdb.db_query(sql)
    df = df.drop_duplicates()
    df['value'] = 1
    df['S_INFO_WINDCODE'] = df['S_INFO_WINDCODE'].apply(
        lambda x: x.split('.')[0] + '-CN')

    cal = Calendar('China.SSE')
    day_temp = Date.strptime(day, '%Y%m%d')
    day_temp = cal.advanceDate(day_temp, Period('-1b'))
    day = day_temp.strftime("%Y%m%d")

    df.to_csv('%s/suspended_%s.csv' % (dirpath, day), index=None, header=None)
Exemple #8
0
    def __init__(self, config_path):
        with open(config_path) as f:
            self.config = yaml.load(f.read())
        self.account = self.config['account']
        self.dirpath = self.config['dirpath']
        self.account_type = {'s': 'simulation', 'p': 'production'}
        '''
        注意 这里的today就是指前一个交易日!!!  因为数据读取 保存日期都不会出现当天日期 
        '''
        cal = Calendar('China.SSE')

        self.today = strftime("%Y%m%d", localtime())
        today = Date.strptime(self.today, '%Y%m%d')

        pre_day = cal.advanceDate(today, Period('-1b'))
        self.pre_day = pre_day.strftime("%Y%m%d")
Exemple #9
0
def job():
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    today = today.strftime("%Y%m%d")

    update_barra_model()

    update_risk_model()
    update_risk_tolocal()

    update_esg100_weight()
    update_barra_model_backtest(today)

    f = open('F:/logger_file/log%s.log' % strftime("%Y%m%d", localtime()), "r")
    lines = f.readlines()
    msg = ''.join(lines)
    send('test', msg, receiver)
Exemple #10
0
def job():
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    today = today.strftime("%Y%m%d")

    update_barra_model()
    update_barra_factor(today)
    update_risk_model()
    update_risk_tolocal()
    update_risk_factor(today)

    update_esg100_weight()
    update_barra_model_backtest(today)

    update_stdfcf(today)
    update_stdni(today)
    update_pmom(today)
    update_to_reverse(today)
Exemple #11
0
def run(start, end, flag, dirpath, output1, output2):
    if not os.path.exists(output1):
        os.mkdir(output1)
    if not os.path.exists(output2):
        os.mkdir(output2)

    if flag == 0:
        fre = 'day'
        tradeday = get_tradeDay.wind(start, end, fre=fre)
        for day in tradeday:
            print(day)
            get_exposure(dirpath, output1, day)
            get_cov(dirpath, output2, day)
    else:
        end = Date.strptime(end, '%Y%m%d')
        today = cal.advanceDate(end, Period('-1b'))
        today = today.strftime("%Y%m%d")
        # today = datetime.strftime(today.toDateTime(), "%Y%m%d")
        get_exposure(dirpath, output1, today)
        get_cov(dirpath, output2, today)
Exemple #12
0
def factor_insider():
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    today = today.strftime("%Y%m%d")

    N = -1
    Fre = 'Y'
    Halflife = 180.0
    datapath = 'F:/factor_data/Insider_Data/'
    barapath = 'Z:/axioma_data/barra_model/Exposure/'
    outputpath = 'F:/factor_data/test_data/'

    update_PV(today, N, Fre, Halflife, datapath, outputpath)
    update_AES(today, datapath, outputpath)
    update_NSTS(today, N, Fre, Halflife, datapath, outputpath)
    update_SSAA(today, N, Fre, Halflife, datapath, outputpath)
    update_MJRR(today, N, Fre, Halflife, datapath, outputpath)
    update_MJRV(today, N, Fre, Halflife, datapath, outputpath)
    update_LIO(today, datapath, outputpath)
    update_LIOCHANGE(today, datapath, outputpath)
    if not os.path.exists(output2):
        os.mkdir(output2)

    if flag == 0:
        fre = 'day'
        tradeday = get_tradeDay.wind(start, end, fre=fre)
        for day in tradeday:
            print(day)
            get_exposure(dirpath, output1, day)
            get_cov(dirpath, output2, day)
    else:
        today = end
        # today = datetime.strftime(today.toDateTime(), "%Y%m%d")
        get_exposure(dirpath, output1, today)
        get_cov(dirpath, output2, today)


if __name__ == '__main__':
    dirpath = 'Z:/MSCI/daily'
    output1 = 'Z:/axioma_data/barra_model/Exposure'
    output2 = 'Z:/axioma_data/barra_model/Covariance'

    start = '20171201'
    # end = strftime("%Y%m%d", localtime())
    today = strftime("%Y%m%d", localtime())
    today = Date.strptime(today, '%Y%m%d')
    today = cal.advanceDate(today, Period('-1b'))
    end = today.strftime("%Y%m%d")

    flag = 0
    run(start, end, flag, dirpath, output1, output2)
Exemple #14
0
# -*- coding: utf-8 -*-

from xutils import (Date, Period, Calendar, Schedule)

# 生成Date对象
current_date = Date(2015, 7, 24)

# Date对象的字符串表示
str(current_date)  # 2015-07-24

# 也可以直接传递5位数的序列号初始化Date对象
current_date_2 = Date(serial_number=current_date.serialNumber)
str(current_date_2)  # 2015-07-24

# Date对象转换成datetime格式
current_date.toDateTime()  # dt.datetime(2015, 7, 24)

# 从字符串初始化成Date对象
Date.parseISO('2016-01-15')
Date.strptime('20160115', '%Y%m%d')

# Date对象的加减
Date()

# 设定为上交所的交易日历
cal = Calendar('China.SSE')

# 假设某日为 2015-07-11(周六), 初始化一个Date对象
current_date = Date(2015, 7, 11)

# 判断该日是否是交易日、节假日、周末或者月末