Пример #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)
Пример #2
0
 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
Пример #3
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
Пример #4
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)
Пример #5
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")
Пример #6
0
@author: shiyunchao
"""

import numpy as np
import pandas as pd
import os
from sklearn.preprocessing import OneHotEncoder
from time import strftime, localtime
from tools import get_tradeDay
from datetime import datetime

from xutils import (Date, Calendar, Period)

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


def get_filename(tradeday):
    exposure_list = []
    cov_list = []
    for day in tradeday:
        if day > '20140930':
            cov_list.append('CNE5S%s.COV' % day[2:])
            exposure_list.append('CNE5S_X_%s.RSK' % day[2:])
        else:
            cov_list.append('CNE5S%s.COV' % day[2:6])
            exposure_list.append('CNE5S%s.RSK' % day[2:6])
    return exposure_list, cov_list

Пример #7
0
# 也可以直接传递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)

# 判断该日是否是交易日、节假日、周末或者月末
cal.isBizDay(current_date)  # False
cal.isHoliday(current_date)  # True
cal.isWeekEnd(current_date.weekday())  # True
cal.isEndOfMonth(current_date)  # False

# 交易日历下的日期加减

# 默认 当计算返回值为非交易日时返回下一个交易日 bizDayConv = BizDayConventions.Following
current_date = Date(2014, 1, 31)
Пример #8
0
from xutils.custom_logger import CustomLogger
from xutils.decorators import handle_exception

LOGGER = CustomLogger(logger_name='Update_error_log',
                      log_level='info',
                      log_file='F:/logger_file/Update_error.log')

logger123 = CustomLogger(logger_name='log_update',
                         log_level='info',
                         log_file='F:/logger_file/log%s.log' %
                         strftime("%Y%m%d", localtime()))

from xutils import (Date, Calendar, Period)

cal = Calendar('China.SSE')

sys.path.append("F:/QUANT/factor_daily/Suspension/")
reload(sys)
import get_suspension

sys.path.append("F:/QUANT/factor_daily/Insider_Code/")
reload(sys)
import Insider

with open('F:/QUANT/config/config.yaml') as f:
    temp = yaml.load(f.read())
username = temp['ct_mail']['username']
password = temp['ct_mail']['password']
host = temp['ct_mail']['host']
receiver = temp['ct_mail']['receiver']