Example #1
0
修改日期:2017-07-19
修改内容:
    添加get_recent_td用于获取最近的交易日
'''
__version__ = '1.1.2'

from windwrapper import get_tds_wind

import datetime as dt
import pickle
import pandas as pd
import sysconfiglee

# --------------------------------------------------------------------------------------------------
# 常量设置
TDS_FILE_PATH = sysconfiglee.get_config('tds_file_path')
# --------------------------------------------------------------------------------------------------


def date_formater(date, dateFormat=None):
    '''
    用于检查日期的类型,如果为str则转换为datetime的格式
    @param:
        date: 输入的需要处理的日期
    @return:
        按照转换方法转换后的格式
    注:当前该程序可以删除,使用dateutil.parser.parse代替
    '''
    if dateFormat is None:
        dateFormat = '%Y-%m-%d'
    if not isinstance(date, dt.datetime):
Example #2
0
# -*- coding: utf-8 -*-
# @Date    : 2017-10-20 14:37:02
# @Author  : Li Hao ([email protected])
# @Link    : https://github.com/SAmmer0
# @Version : $Id$
# 系统模块
from os.path import dirname
from datetime import time

# 本地模块
import sysconfiglee
import portmonitor
from factortest.const import WEEKLY, MONTHLY

# 组合的资金,持仓等明细数据所在的文件
PORT_DATA_PATH = sysconfiglee.get_config('portfolio_data_path')
# 组合的配置所在的文件,这个文件也可以不放在模块下,但是必须能够被Python解释器找到
PORT_CONFIG_PATH = dirname(portmonitor.__file__) + '\\portfolios'

# 组合的类型,包含做多、做空和多空
LONG = 'long'
SHORT = 'short'

# 组合中现金的标志
CASH = 'CASH'

# 报告频率
DAILY = 'daily'

# 开交易时间段
MONING_START = time(9, 30)
Example #3
0
        def processing_backtest(self, sig_data, reb_dates):
            quote = self.quote_loader.load_data()
            ind_cls = self.ind_loader.load_data()
            index_constituent = self.constituent_loader.load_data()
            self.reb_dates = reb_dates
            # 进行回测
            stock_filter = self.stock_filter
            weight_method = self.weight_method
            holding = get_daily_holding(sig_data, quote, index_constituent,
                                        ind_cls, stock_filter, reb_dates)
            self.nav, self.turnover = cal_nav(holding,
                                              reb_dates[-1],
                                              quote,
                                              buildpos_type=weight_method,
                                              cal_to=True)
            self.holding = holding

    quote_path = sysconfiglee.get_config('quote_file_path')
    quote_loader = datatoolkits.DataLoader('HDF',
                                           quote_path,
                                           key='quote_adj_20170510')
    index_constituent_path = sysconfiglee.get_config(
        'index_constituent_file_path')
    constituent_loader = datatoolkits.DataLoader('HDF',
                                                 index_constituent_path,
                                                 key='Index_000985')
    industry_loader = datatoolkits.DataLoader('None', '')
    sizebt = SizeBT(quote_loader, constituent_loader, industry_loader,
                    get_stocks, '2015-01-01', '2016-12-31')
    sizebt.run()
Example #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2017-07-18 16:07:13
# @Author  : Li Hao ([email protected])
# @Link    : https://github.com/SAmmer0
# @Version : $Id$

import sysconfiglee

FACTOR_FILE_PATH = sysconfiglee.get_config('factor_file_path')  # 因子存储的主目录
SUFFIX = '.h5'  # 因子文件后缀
START_TIME = '2007-01-01'  # 因子最早可追溯的时间
UNIVERSE_FILE_PATH = FACTOR_FILE_PATH + '\\' + 'universe.pickle'
FACTOR_DICT_FILE_PATH = FACTOR_FILE_PATH + '\\' + 'factor_dict.pickle'