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_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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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):
    df = TA_strategy.adx(stock_data, i)
    df = df[df['date'] >= pd.to_datetime('2005-01-01')]  # 采用2005年起的数据
    df.reset_index(inplace=True,
                   drop=True)  # 在计算ADX之后,最早的一部分数据没有对应的值,需要重新排index
Exemplo n.º 5
0
# 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'
# index_data = Functions.import_index_data_xbx()
# print index_data
# exit()

# ==== 3 测试计算除权股价,默认是后复权
stock_data_adjust = Functions.cal_adjust_price(stock_data,
                                               adjust_type='adjust_forth',
                                               return_type=2)
print stock_data_adjust
exit()

# ==== 4 测试从一个指定的文件夹里获得所有股票名称的列表
# 4.1 从万得的数据读取股票列表
# file_path = 'C:/all_trading_data/data/input_data/stock_data_wande'
# print Functions.get_stock_code_list_in_one_dir_wande(file_path)
# 4.2 从xbx的数据读取股票列表
file_path = 'D:/all_trading_data/data/input_data/stock_data'
# print Functions.get_stock_code_list_in_one_dir_xbx(file_path)
# exit()

# ==== 5 个股数据和指数数据合并,日周期
stock_data = Functions.merge_with_index_data(stock_data_adjust, index_data)