def data_standardize_xbx(code): # 1.读取万得的股票数据 stock_data = Functions.import_stock_data_xbx(code) # 2.读取指数数据 index_data = Functions.import_index_data_xbx() # 3.个股数据除权处理, 默认后复权,直接替换OLHC列 stock_data = Functions.cal_adjust_price(stock_data) # 3.合并个股数据和指数数据 stock_data = Functions.merge_with_index_data(stock_data, index_data) # 4.添加涨跌停列 stock_data = Functions.limit_up_down(stock_data) return stock_data
def data_standardize_money163(stock_code, index_code='000001.SH'): # 1.读取万得的股票数据 stock_data = Functions.import_stock_data_money163(stock_code) # 2.读取指数数据 index_data = Functions.import_index_data_wande(index_code=index_code) # 3.个股数据除权处理, 默认后复权,直接替换OLHC列 stock_data = Functions.cal_adjust_price(stock_data) # 3.合并个股数据和指数数据 stock_data = Functions.merge_with_index_data(stock_data, index_data) # 4.添加涨跌停列 stock_data = Functions.limit_up_down(stock_data) return stock_data
def data_standardize_money163(df, index_code='000001.SH', return_type=1, start_date='19890101'): # 1.读取万得的股票数据 # stock_data = Functions.import_stock_data_money163(stock_code) stock_data = df.copy() # 2.读取指数数据 index_data = Functions.import_index_data_wande(index_code=index_code) # 3.个股数据除权处理, 默认后复权,直接替换OLHC列 stock_data = Functions.cal_adjust_price(stock_data, return_type=return_type) # 3.合并个股数据和指数数据 stock_data = Functions.merge_with_index_data(stock_data, index_data) # 4.添加涨跌停列 stock_data = Functions.limit_up_down(stock_data) # 取得指定时间范围的数据 stock_data = stock_data[stock_data['date'] >= pd.to_datetime(start_date)] return stock_data
def get_all_stock_data_wande( input_path='C:/all_trading_data/data/input_data/stock_data_wande', output_path='C:/all_trading_data/data/output_data/Going_Merry/', save=True): """ # 获取指定文件夹中所有股票代码的list :param input_path: 个股数据所在的文件夹 :param output_path: 结果输出所在的文件夹 :param save: 是否要保存数据 :return: all_stock_data """ all_stock_data = pd.DataFrame() stock_list = Functions.get_stock_code_list_in_one_dir_wande(input_path) for code in stock_list: # stock_data = Functions.import_stock_data_wande(code) # # 判断每天开盘是否涨停 # stock_data.ix[stock_data['open'] > stock_data['close'].shift(1) * 1.097, 'limit_up'] = 1 # stock_data['limit_up'].fillna(0, inplace=True) # 获取标准化的个股数据,除权、指数合并、涨跌停列添加 stock_data = Data_standardize.data_standardize_wande(code) all_stock_data = all_stock_data.append(stock_data, ignore_index=True) date = time.strftime('%Y%m%d', time.localtime(time.time())) # 输出一个进度过程,不然都不知道运行到哪里了 progess = ((stock_list.index(code) + 1.0) / len(stock_list)) * 100.00 # 读取当前股票在list中的位置, 除以总的list长度 print 'stock %s in progress is %.2f%%' % (code, progess) if save == True: all_stock_data.to_hdf(output_path + 'all_stock_data_wande_' + str(date) + '.h5', key='all_stock', mode='w') # all_stock_data.to_csv('C:/all_trading_data/data/output_data/Going_Merry/all_stock_data_20171005.csv') return all_stock_data print 'all_stock_data has been finished.'
""" import os import warnings import pandas as pd from Basic_Functions import Functions from Strategy_test import TA_strategy from Performance_analysis import pf_analysis from Performance_analysis import equity_cal import matplotlib.pyplot as plt warnings.filterwarnings("ignore") pd.set_option('expand_frame_repr', False) # 导入指数数据,作为benchmark index_data = Functions.import_index_data_wande() # 此处可以填入对应的code进行单个股票测试 stock_data = Functions.import_stock_data_wande('600000.SH') stock_data = Functions.cal_adjust_price(stock_data, adjust_type='adjust_back', return_type=2) # 和index合并 stock_data = Functions.merge_with_index_data(stock_data, index_data) stock_data = stock_data[[ 'date', 'code', 'open', 'high', 'low', 'close', 'change' ]] concat = pd.DataFrame() for i in range(14, 19):
""" import os import warnings import pandas as pd from Basic_Functions import Functions from Strategy_test import TA_strategy from Performance_analysis import pf_analysis from Performance_analysis import equity_cal warnings.filterwarnings("ignore") pd.set_option('expand_frame_repr', False) # 导入指数数据,作为benchmark index_data = Functions.import_index_data_wande() # 遍历数据文件夹中所有股票文件的文件名,得到股票代码列表 stock_code_list = Functions.get_stock_code_list_in_one_dir_wande() # print len(stock_code_list) # exit() # ====数据准备 for code in stock_code_list[0:]: # 可以适当少选一点股票 stock_data = Functions.import_stock_data_wande(code, other_columns=['成交量(股)']) if len(stock_data) < 250: # 剔除发行时间小于约1年的数据 continue print 'The progress is in %.2f%%.' % (stock_code_list.index(code) * 1.0 /
""" import os import warnings import pandas as pd from Basic_Functions import Functions from Strategy_test import TA_strategy from Performance_analysis import pf_analysis from Performance_analysis import equity_cal warnings.filterwarnings("ignore") pd.set_option('expand_frame_repr', False) # 导入指数数据,作为benchmark index_data = Functions.import_index_data_wande() # 遍历数据文件夹中所有股票文件的文件名,得到股票代码列表 stock_code_list = Functions.get_stock_code_list_in_one_dir_wande() # print len(stock_code_list) # exit() # ====数据准备 for code in stock_code_list[0:]: # 可以适当少选一点股票 stock_data = Functions.import_stock_data_wande(code) if len(stock_data) < 250: # 剔除发行时间小于约1年的数据 continue print 'The progress is in %.2f%%.' % (stock_code_list.index(code) * 1.0 / len(stock_code_list) * 100)
@contract: [email protected] @file: test_20171118.py @time: 2017/11/18 16:20 """ import pandas as pd from Basic_Functions import Functions from Basic_Functions import Data_standardize from Strategy_test import TA_strategy from Performance_analysis import equity_cal from Performance_analysis import pf_analysis import tushare as ts pd.set_option('expand_frame_repr', False) # 读取万得的非除权数据,然后进行数据标准化 stock_data = Functions.import_stock_data_wande('600000.SH') stock_data = Data_standardize.data_standardize_wande(stock_data, adjust_type='adjust_back', start_date='20050101') # stock_data.to_csv(Functions.out_put_path+'/600000.SH.csv') #读取xbx的数据 # stock_data = Functions.import_stock_data_xbx('sh600000') # stock_data = Data_standardize.data_standardize_xbx(stock_data, adjust_type='adjust_back', start_date='20081031') # stock_data.to_csv(Functions.out_put_path+'/sh600000.csv') #读取tushare的股票数据 # cons = ts.get_apis() # stock_data=ts.bar(code='600000', adj='hfq', conn=cons) # stock_data.to_csv(Functions.out_put_path+'/600000ts.csv') # print stock_data
数据:万得 每月调仓 每次10个 选股策略 市值因子 实际买卖方式:每月末选股,买入,持有一个月 """ import pandas as pd from Basic_Functions import Functions import matplotlib.pyplot as plt pd.set_option('expand_frame_repr', False) # =====建立all_stock_data_monthly all_stock_data_monthly = pd.DataFrame() # 获得stock_list stock_list = Functions.get_stock_code_list_in_one_dir_wande() # print stock_list # # range = stock_list # for code in range: # # 获得每个股票的数据 # df = Functions.import_stock_data_wande(code) # # 读取指数数据 # index_df = Functions.import_index_data_wande() # # 个股与指数数据合并 # df = Functions.merge_with_index_data(df,index_df) # # 截取20060101以后的数据 # df = df[df['date']>pd.to_datetime('20060101')] # # 周期转化昵称月 # df_month = Functions.transfer_to_period_data(df)
pd.set_option('expand_frame_repr', False) # ====1 测试个股数据导入 # 1.1 测试万得个股数据读取 # stock_data = Functions.import_stock_data_wande('000001.SZ') # print stock_data['date'] # exit() # 1.2 测试xbx个股数据读取 # stock_data = Functions.import_stock_data_xbx('sh600000') # print stock_data # exit() # 1.3 测试money163个股数据读取 stock_data = Functions.import_stock_data_money163('000001') # df['change'] = df['change'].astype('float') print stock_data # print df['change'].astype('float', inplace=True) # print df['change'].astype('float') exit() # 2 测试指数数据导入 # 2.1 测试大盘数据读取 万得 # index_code='000001.SH' # index_data = Functions.import_index_data_wande() # print index_data['date'] # exit() # 2.2 测试大盘数据读取 xbx # index_code='sh000001'