在回测中调用下面研究中生成的pkl方法如下:
import cPickle as pickle from six import StringIO # 导入文件 pkl_file_read = read_file('research.pkl') result = pickle.load(StringIO(pkl_file_read)) # 打印结果 print result
效果如下图
import pandas as pd from pandas import Series, DataFrame import numpy as np a = ['a','b','c'] b = ['o','p','q'] result = {} score_df = DataFrame(np.zeros(len(a)*len(b)).reshape(len(a),len(b)),index = a,columns = b) result['2017-04-17'] = score_df score_df = score_df + 1 result['2017-04-18'] = score_df score_df = score_df + 1 result['2017-04-19'] = score_df result
{'2017-04-17': o p q a 0 0 0 b 0 0 0 c 0 0 0, '2017-04-18': o p q a 1 1 1 b 1 1 1 c 1 1 1, '2017-04-19': o p q a 2 2 2 b 2 2 2 c 2 2 2}
#使用pickle模块将数据对象保存到文件 import pickle pkl_file = open('research.pkl', 'wb') pickle.dump(result, pkl_file, 0) pkl_file.close()
#使用pickle模块从文件中重构python对象 import pickle pkl_file = open('research.pkl', 'rb') temp = pickle.load(pkl_file) pkl_file.close() temp
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
玉兔呈祥:2019年08月23日操盘计划(1)...
玉兔呈祥:2019年07月26日操盘计划(1)...
交易匠人:震荡行情多耐心,黄金早间有望延续...
交易匠人:黄金震荡回踩1708,有波段机会
移动端课程