这两个API小伙伴们在使用过程中经常存在疑惑,特地在此多解释下。
(1)这两个API目前只能在投资研究环境(官网和客户端)中使用,不能在回测、模拟交易及实盘中使用;
(2)create_backtest中的algorithm_id为:官网策略网址algorithmId后的部分,或者客户端策略ID(1,2,3...);
(3)create_backtest中的extras与初始化中的g对象后的参数一一对应:如 extras={'x':1, 'y':2},则回测中 g.x = 1, g.y = 2;
(4)get_backtest中的backtest_id为回测或者模拟交易的backtestId后面的部分;
(5)get_backtest中的gt.get_status()表示获取回测状态,只有状态为done后,才能获取其他的信息;
(1)客户端和官网是独立的,不能在客户端读取官网的回测及模拟交易;
【量化课堂】多回测运行和参数分析框架
关于回测中的绘图,多基准,策略对比等问题
Get API 新技能,研究中写策略并回测
为了进一步打通研究模块与回测模块,我们增加了在研究中调用回测的新功能。
主要功能如下:
具体功能参看API - 研究中创建回测函数、研究中获取回测信息
首先打我的策略标签,找到策略 ID, 如下所示(上方红色框内的部分):
测试所使用的代码如下所示:
def initialize(context):
# 定义一个全局变量, 保存要操作的股票
# 000001(股票:平安银行)
g.security = '000001.XSHE'
# 初始化此策略
# 设置我们要操作的股票池, 这里我们只操作一支股票
set_universe([g.security])
# 设置均线长度
g.ma_long = 5
g.m = 1.01
# 每个单位时间(如果按天回测,则每天调用一次,如果按分钟,则每分钟调用一次)调用一次
def handle_data(context, data):
security = g.security
# 取得过去五天的平均价格
average_price = data[security].mavg(g.ma_long, 'close')
# 取得上一时间点价格
current_price = data[security].close
# 取得当前的现金
cash = context.portfolio.cash
# 如果上一时间点价格高出五天平均价1%, 则全仓买入
if current_price > g.m*average_price:
# 用所有 cash 买入股票
order_value(security, cash)
# 记录这次买入
log.info("Buying %s" % (security))
# 如果上一时间点价格低于五天平均价, 则空仓卖出
elif current_price < average_price and context.portfolio.positions[security].sellable_amount > 0:
# 卖出所有股票,使这只股票的最终持有量为0
order_target(security, 0)
# 记录这次卖出
log.info("Selling %s" % (security))
# 画出上一时间点价格
record(stock_price=current_price)
接下来设定初始化仓位,设定g.全局变量的值,当然也可以选择不设置:
# 设定初始仓位
InitialPositions = [
{
'security': '000001.XSHE',
'amount': '1000', # 100股
'avg_cost': '10.0' # 持仓均价10元
}
]
# 设定g.全局变量的值
extra_vars = {'ma_long': 5, 'm': 1.01}
# 记得此处传入你自己的 algorithmId
out_algorithm_id = create_backtest('1', '2015-06-01', '2015-12-31', frequency="day",\
initial_cash=100000, initial_positions=InitialPositions, extras=extra_vars, name=None)
out_algorithm_id
118
out_algorithm_id 即为生成的回测 ID,在回测列表中可以查看到。
# 研究中获取回测信息
gt = get_backtest(out_algorithm_id)
gt.get_status() # 获取回测状态
u'done'
gt.get_params() # 获取回测参数
{u'algorithm_id': 1, u'end_date': u'2015-12-31 00:00:00', u'extras': {}, u'frequency': u'day', u'initial_cash': 100000, u'initial_positions': [], u'name': u'\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u7b56\u7565-1', u'start_date': u'2015-06-01 00:00:00'}
gt.get_results() # 获取收益曲线
[{u'benchmark_returns': 0.04861770576899138, u'returns': 0.0, u'time': u'2015-06-01 16:00:00'}, {u'benchmark_returns': 0.06631942586693307, u'returns': 0.0, u'time': u'2015-06-02 16:00:00'}, {u'benchmark_returns': 0.0625432131562591, u'returns': 0.0, u'time': u'2015-06-03 16:00:00'}, {u'benchmark_returns': 0.07035716403120218, u'returns': 0.030503200000000064, u'time': u'2015-06-04 16:00:00'}, {u'benchmark_returns': 0.08050749158873405, u'returns': 0.025883199999999995, u'time': u'2015-06-05 16:00:00'}, {u'benchmark_returns': 0.10595747133393907, u'returns': 0.0874832000000001, u'time': u'2015-06-08 16:00:00'}, {u'benchmark_returns': 0.09846082148326252, u'returns': 0.0682332000000001, u'time': u'2015-06-09 16:00:00'}, {u'benchmark_returns': 0.09673611689237527, u'returns': 0.04975320000000005, u'time': u'2015-06-10 16:00:00'}, {u'benchmark_returns': 0.09621513174706253, u'returns': 0.04686389999999996, u'time': u'2015-06-11 16:00:00'}, {u'benchmark_returns': 0.102107717500453, u'returns': 0.04686390000000018, u'time': u'2015-06-12 16:00:00'}, {u'benchmark_returns': 0.07856877406741702, u'returns': 0.04686390000000018, u'time': u'2015-06-15 16:00:00'}, {u'benchmark_returns': 0.046271413429394004, u'returns': 0.04686390000000018, u'time': u'2015-06-16 16:00:00'}, {u'benchmark_returns': 0.061560117079120236, u'returns': 0.04686390000000018, u'time': u'2015-06-17 16:00:00'}, {u'benchmark_returns': 0.018534015558079098, u'returns': 0.04686390000000018, u'time': u'2015-06-18 16:00:00'}, {u'benchmark_returns': -0.04209547579557138, u'returns': 0.04686390000000018, u'time': u'2015-06-19 16:00:00'}, {u'benchmark_returns': -0.011307567360879567, u'returns': 0.04686390000000018, u'time': u'2015-06-23 16:00:00'}, {u'benchmark_returns': 0.008117824447011035, u'returns': 0.04686390000000018, u'time': u'2015-06-24 16:00:00'}, {u'benchmark_returns': -0.027745867495009624, u'returns': 0.04686390000000018, u'time': u'2015-06-25 16:00:00'}, {u'benchmark_returns': -0.10424536789049976, u'returns': 0.04686390000000018, u'time': u'2015-06-26 16:00:00'}, {u'benchmark_returns': -0.13412578713274104, u'returns': 0.04686390000000018, u'time': u'2015-06-29 16:00:00'}, {u'benchmark_returns': -0.07598512568818283, u'returns': 0.04686390000000018, u'time': u'2015-06-30 16:00:00'}, {u'benchmark_returns': -0.12142713572406705, u'returns': 0.015050200000000125, u'time': u'2015-07-01 16:00:00'}, {u'benchmark_returns': -0.15138584734143667, u'returns': 0.011035099999999964, u'time': u'2015-07-02 16:00:00'}, {u'benchmark_returns': -0.1972620805238111, u'returns': 0.011035100000000186, u'time': u'2015-07-03 16:00:00'}, {u'benchmark_returns': -0.17399747026800572, u'returns': 0.011035100000000186, u'time': u'2015-07-06 16:00:00'}, {u'benchmark_returns': -0.1885681150893782, u'returns': 0.011035100000000186, u'time': u'2015-07-07 16:00:00'}, {u'benchmark_returns': -0.24330357465632435, u'returns': -0.035166999999999726, u'time': u'2015-07-08 16:00:00'}, {u'benchmark_returns': -0.1948432799423404, u'returns': -0.0373154, u'time': u'2015-07-09 16:00:00'}, {u'benchmark_returns': -0.1516833170516868, u'returns': 0.031248500000000012, u'time': u'2015-07-10 16:00:00'}, {u'benchmark_returns': -0.12993993384191016, u'returns': 0.0023485000000000866, u'time': u'2015-07-13 16:00:00'}, {u'benchmark_returns': -0.15052793643402806, u'returns': -0.03675149999999994, u'time': u'2015-07-14 16:00:00'}, {u'benchmark_returns': -0.18056204835989864, u'returns': -0.053272499999999945, u'time': u'2015-07-15 16:00:00'}, {u'benchmark_returns': -0.17424143674564818, u'returns': -0.053272499999999945, u'time': u'2015-07-16 16:00:00'}, {u'benchmark_returns': -0.14239978317763335, u'returns': -0.053272499999999945, u'time': u'2015-07-17 16:00:00'}, {u'benchmark_returns': -0.14051663465080044, u'returns': -0.053272499999999945, u'time': u'2015-07-20 16:00:00'}, {u'benchmark_returns': -0.1394023626944888, u'returns': -0.053272499999999945, u'time': u'2015-07-21 16:00:00'}, {u'benchmark_returns': -0.1412297356506499, u'returns': -0.053272499999999945, u'time': u'2015-07-22 16:00:00'}, {u'benchmark_returns': -0.1218849085559518, u'returns': -0.053272499999999945, u'time': u'2015-07-23 16:00:00'}, {u'benchmark_returns': -0.1372802055185175, u'returns': -0.053272499999999945, u'time': u'2015-07-24 16:00:00'}, {u'benchmark_returns': -0.21114110826885224, u'returns': -0.053272499999999945, u'time': u'2015-07-27 16:00:00'}, {u'benchmark_returns': -0.21271893719030355, u'returns': -0.053272499999999945, u'time': u'2015-07-28 16:00:00'}, {u'benchmark_returns': -0.18807729006746565, u'returns': -0.053272499999999945, u'time': u'2015-07-29 16:00:00'}, {u'benchmark_returns': -0.2118267346357411, u'returns': -0.053272499999999945, u'time': u'2015-07-30 16:00:00'}, {u'benchmark_returns': -0.21156087108220512, u'returns': -0.053272499999999945, u'time': u'2015-07-31 16:00:00'}, {u'benchmark_returns': -0.2089712319935283, u'returns': -0.053272499999999945, u'time': u'2015-08-03 16:00:00'}, {u'benchmark_returns': -0.18440519175537895, u'returns': -0.048095099999999946, u'time': u'2015-08-04 16:00:00'}, {u'benchmark_returns': -0.20119053988480062, u'returns': -0.06811509999999998, u'time': u'2015-08-05 16:00:00'}, {u'benchmark_returns': -0.20843062211038643, u'returns': -0.07266509999999993, u'time': u'2015-08-06 16:00:00'}, {u'benchmark_returns': -0.19291819644940977, u'returns': -0.06841179999999991, u'time': u'2015-08-07 16:00:00'}, {u'benchmark_returns': -0.15626744923235258, u'returns': -0.06841179999999991, u'time': u'2015-08-10 16:00:00'}, {u'benchmark_returns': -0.15992302144942527, u'returns': -0.07492109999999996, u'time': u'2015-08-11 16:00:00'}, {u'benchmark_returns': -0.17036400170301402, u'returns': -0.0945010999999999, u'time': u'2015-08-12 16:00:00'}, {u'benchmark_returns': -0.15810639045502317, u'returns': -0.10012199999999982, u'time': u'2015-08-13 16:00:00'}, {u'benchmark_returns': -0.15850363646391963, u'returns': -0.10012199999999982, u'time': u'2015-08-14 16:00:00'}, {u'benchmark_returns': -0.15760874841891748, u'returns': -0.10012199999999982, u'time': u'2015-08-17 16:00:00'}, {u'benchmark_returns': -0.20976097275900474, u'returns': -0.10012199999999982, u'time': u'2015-08-18 16:00:00'}, {u'benchmark_returns': -0.19721684033871056, u'returns': -0.10012199999999982, u'time': u'2015-08-19 16:00:00'}, {u'benchmark_returns': -0.2229731725702353, u'returns': -0.10012199999999982, u'time': u'2015-08-20 16:00:00'}, {u'benchmark_returns': -0.25848733760271225, u'returns': -0.10012199999999982, u'time': u'2015-08-21 16:00:00'}, {u'benchmark_returns': -0.3233526736846106, u'returns': -0.10012199999999982, u'time': u'2015-08-24 16:00:00'}, {u'benchmark_returns': -0.37140374097081297, u'returns': -0.10012199999999982, u'time': u'2015-08-25 16:00:00'}, {u'benchmark_returns': -0.3749640815653682, u'returns': -0.10012199999999982, u'time': u'2015-08-26 16:00:00'}, {u'benchmark_returns': -0.3377915228982473, u'returns': -0.10012199999999982, u'time': u'2015-08-27 16:00:00'}, {u'benchmark_returns': -0.30956330000501975, u'returns': -0.10549189999999986, u'time': u'2015-08-28 16:00:00'}, {u'benchmark_returns': -0.304553827453934, u'returns': -0.0861118999999998, u'time': u'2015-08-31 16:00:00'}, {u'benchmark_returns': -0.30547371121764466, u'returns': -0.04531189999999974, u'time': u'2015-09-01 16:00:00'}, {u'benchmark_returns': -0.3046992570900563, u'returns': -0.022871899999999834, u'time': u'2015-09-02 16:00:00'}, {u'benchmark_returns': -0.3285272006096476, u'returns': -0.10141189999999989, u'time': u'2015-09-07 16:00:00'}, {u'benchmark_returns': -0.31127023904376705, u'returns': -0.10359879999999988, u'time': u'2015-09-08 16:00:00'}, {u'benchmark_returns': -0.29778453236005653, u'returns': -0.10359879999999988, u'time': u'2015-09-09 16:00:00'}, {u'benchmark_returns': -0.30640784873830484, u'returns': -0.10359879999999988, u'time': u'2015-09-10 16:00:00'}, {u'benchmark_returns': -0.3085506635330436, u'returns': -0.10359879999999988, u'time': u'2015-09-11 16:00:00'}, {u'benchmark_returns': -0.32219626018601355, u'returns': -0.10359879999999988, u'time': u'2015-09-14 16:00:00'}, {u'benchmark_returns': -0.3488239307771458, u'returns': -0.10359879999999988, u'time': u'2015-09-15 16:00:00'}, {u'benchmark_returns': -0.31638816409338144, u'returns': -0.10359879999999988, u'time': u'2015-09-16 16:00:00'}, {u'benchmark_returns': -0.33131308707661433, u'returns': -0.10359879999999988, u'time': u'2015-09-17 16:00:00'}, {u'benchmark_returns': -0.32836441857376075, u'returns': -0.10359879999999988, u'time': u'2015-09-18 16:00:00'}, {u'benchmark_returns': -0.3165949468572429, u'returns': -0.10359879999999988, u'time': u'2015-09-21 16:00:00'}, {u'benchmark_returns': -0.3102359120720851, u'returns': -0.10359879999999988, u'time': u'2015-09-22 16:00:00'}, {u'benchmark_returns': -0.3259361154876572, u'returns': -0.10359879999999988, u'time': u'2015-09-23 16:00:00'}, {u'benchmark_returns': -0.3213974300682796, u'returns': -0.10359879999999988, u'time': u'2015-09-24 16:00:00'}, {u'benchmark_returns': -0.33235588367199087, u'returns': -0.10359879999999988, u'time': u'2015-09-25 16:00:00'}, {u'benchmark_returns': -0.3301246542689279, u'returns': -0.10359879999999988, u'time': u'2015-09-28 16:00:00'}, {u'benchmark_returns': -0.3433244595088981, u'returns': -0.10359879999999988, u'time': u'2015-09-29 16:00:00'}, {u'benchmark_returns': -0.33834721284308944, u'returns': -0.10359879999999988, u'time': u'2015-09-30 16:00:00'}, {u'benchmark_returns': -0.3190253157052232, u'returns': -0.10359879999999988, u'time': u'2015-10-08 16:00:00'}, {u'benchmark_returns': -0.31001157033227156, u'returns': -0.09253789999999973, u'time': u'2015-10-09 16:00:00'}, {u'benchmark_returns': -0.28778872379090437, u'returns': -0.06472790000000017, u'time': u'2015-10-12 16:00:00'}, {u'benchmark_returns': -0.2883361506882395, u'returns': -0.0729679000000002, u'time': u'2015-10-13 16:00:00'}, {u'benchmark_returns': -0.29637836825056196, u'returns': -0.08532790000000012, u'time': u'2015-10-14 16:00:00'}, {u'benchmark_returns': -0.27970705017673625, u'returns': -0.09063290000000013, u'time': u'2015-10-15 16:00:00'}, {u'benchmark_returns': -0.26994632530915674, u'returns': -0.09063290000000013, u'time': u'2015-10-16 16:00:00'}, {u'benchmark_returns': -0.26992215589519897, u'returns': -0.09063290000000013, u'time': u'2015-10-19 16:00:00'}, {u'benchmark_returns': -0.2609317536314544, u'returns': -0.09063290000000013, u'time': u'2015-10-20 16:00:00'}, {u'benchmark_returns': -0.28250842985777846, u'returns': -0.09783470000000016, u'time': u'2015-10-21 16:00:00'}, {u'benchmark_returns': -0.27191520295387417, u'returns': -0.0970259, u'time': u'2015-10-22 16:00:00'}, {u'benchmark_returns': -0.26226664895620144, u'returns': -0.0970259, u'time': u'2015-10-23 16:00:00'}, {u'benchmark_returns': -0.2585441460543225, u'returns': -0.10497660000000009, u'time': u'2015-10-26 16:00:00'}, {u'benchmark_returns': -0.2577967534073192, u'returns': -0.10785660000000008, u'time': u'2015-10-27 16:00:00'}, {u'benchmark_returns': -0.27183546454543217, u'returns': -0.1241766000000003, u'time': u'2015-10-28 16:00:00'}, {u'benchmark_returns': -0.27010291005941334, u'returns': -0.12339730000000027, u'time': u'2015-10-29 16:00:00'}, {u'benchmark_returns': -0.26994343324252923, u'returns': -0.12339730000000027, u'time': u'2015-10-30 16:00:00'}, {u'benchmark_returns': -0.2819490215415582, u'returns': -0.12339730000000027, u'time': u'2015-11-02 16:00:00'}, {u'benchmark_returns': -0.2841116676503136, u'returns': -0.12339730000000027, u'time': u'2015-11-03 16:00:00'}, {u'benchmark_returns': -0.25043045313106493, u'returns': -0.12339730000000027, u'time': u'2015-11-04 16:00:00'}, {u'benchmark_returns': -0.2344348457671196, u'returns': -0.08924960000000037, u'time': u'2015-11-05 16:00:00'}, {u'benchmark_returns': -0.21637926065969282, u'returns': -0.06506960000000017, u'time': u'2015-11-06 16:00:00'}, {u'benchmark_returns': -0.20667410478659742, u'returns': -0.024149600000000104, u'time': u'2015-11-09 16:00:00'}, {u'benchmark_returns': -0.20814430751427082, u'returns': -0.03809960000000012, u'time': u'2015-11-10 16:00:00'}, {u'benchmark_returns': -0.20806002442969984, u'returns': -0.05297960000000013, u'time': u'2015-11-11 16:00:00'}, {u'benchmark_returns': -0.21597643709372916, u'returns': -0.06413960000000007, u'time': u'2015-11-12 16:00:00'}, {u'benchmark_returns': -0.22611560953712673, u'returns': -0.08021410000000029, u'time': u'2015-11-13 16:00:00'}, {u'benchmark_returns': -0.22242120099677132, u'returns': -0.08021410000000018, u'time': u'2015-11-16 16:00:00'}, {u'benchmark_returns': -0.22360674173783035, u'returns': -0.08021410000000018, u'time': u'2015-11-17 16:00:00'}, {u'benchmark_returns': -0.23244964860357598, u'returns': -0.08021410000000018, u'time': u'2015-11-18 16:00:00'}, {u'benchmark_returns': -0.22018129539382614, u'returns': -0.08021410000000018, u'time': u'2015-11-19 16:00:00'}, {u'benchmark_returns': -0.22030234903980284, u'returns': -0.08021410000000018, u'time': u'2015-11-20 16:00:00'}, {u'benchmark_returns': -0.22465036463795762, u'returns': -0.08021410000000018, u'time': u'2015-11-23 16:00:00'}, {u'benchmark_returns': -0.22453592142998635, u'returns': -0.08021410000000018, u'time': u'2015-11-24 16:00:00'}, {u'benchmark_returns': -0.21881004266004844, u'returns': -0.08021410000000018, u'time': u'2015-11-25 16:00:00'}, {u'benchmark_returns': -0.22339148935027442, u'returns': -0.08021410000000018, u'time': u'2015-11-26 16:00:00'}, {u'benchmark_returns': -0.26521015305436313, u'returns': -0.08021410000000018, u'time': u'2015-11-27 16:00:00'}, {u'benchmark_returns': -0.26326420536647754, u'returns': -0.08021410000000018, u'time': u'2015-11-30 16:00:00'}, {u'benchmark_returns': -0.2580411330373372, u'returns': -0.08021410000000018, u'time': u'2015-12-01 16:00:00'}, {u'benchmark_returns': -0.23113272540715646, u'returns': -0.08021410000000018, u'time': u'2015-12-02 16:00:00'}, {u'benchmark_returns': -0.22548410613140846, u'returns': -0.07684820000000026, u'time': u'2015-12-03 16:00:00'}, {u'benchmark_returns': -0.24029706482092217, u'returns': -0.10141820000000001, u'time': u'2015-12-04 16:00:00'}, {u'benchmark_returns': -0.2382282043013707, u'returns': -0.09959819999999997, u'time': u'2015-12-07 16:00:00'}, {u'benchmark_returns': -0.2515703405346481, u'returns': -0.10712279999999985, u'time': u'2015-12-08 16:00:00'}, {u'benchmark_returns': -0.2489017893422799, u'returns': -0.10712280000000007, u'time': u'2015-12-09 16:00:00'}, {u'benchmark_returns': -0.2515571196586369, u'returns': -0.10712280000000007, u'time': u'2015-12-10 16:00:00'}, {u'benchmark_returns': -0.25466092687843334, u'returns': -0.10712280000000007, u'time': u'2015-12-11 16:00:00'}, {u'benchmark_returns': -0.23332925001069027, u'returns': -0.10712280000000007, u'time': u'2015-12-14 16:00:00'}, {u'benchmark_returns': -0.23682720459656803, u'returns': -0.10712280000000007, u'time': u'2015-12-15 16:00:00'}, {u'benchmark_returns': -0.23867585490005938, u'returns': -0.10712280000000007, u'time': u'2015-12-16 16:00:00'}, {u'benchmark_returns': -0.22412297563082684, u'returns': -0.10712280000000007, u'time': u'2015-12-17 16:00:00'}, {u'benchmark_returns': -0.22163889697405126, u'returns': -0.10712280000000007, u'time': u'2015-12-18 16:00:00'}, {u'benchmark_returns': -0.20138368862027545, u'returns': -0.0812885000000001, u'time': u'2015-12-21 16:00:00'}, {u'benchmark_returns': -0.19915927623140572, u'returns': -0.08758850000000018, u'time': u'2015-12-22 16:00:00'}, {u'benchmark_returns': -0.20129775292620333, u'returns': -0.08398850000000013, u'time': u'2015-12-23 16:00:00'}, {u'benchmark_returns': -0.20893673377018684, u'returns': -0.09388850000000015, u'time': u'2015-12-24 16:00:00'}, {u'benchmark_returns': -0.20711906989484652, u'returns': -0.09325970000000017, u'time': u'2015-12-25 16:00:00'}, {u'benchmark_returns': -0.2299599923897332, u'returns': -0.09325970000000017, u'time': u'2015-12-28 16:00:00'}, {u'benchmark_returns': -0.22288620399522474, u'returns': -0.09325970000000017, u'time': u'2015-12-29 16:00:00'}, {u'benchmark_returns': -0.22220450257590174, u'returns': -0.09325970000000017, u'time': u'2015-12-30 16:00:00'}]
gt.get_positions() # 获取所有持仓列表
[{u'amount': 7700, u'avg_cost': 12.85, u'closeable_amount': 0, u'price': 13.25, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-04 16:00:00'}, {u'amount': 7700, u'avg_cost': 12.85, u'closeable_amount': 7700, u'price': 13.19, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-05 16:00:00'}, {u'amount': 7700, u'avg_cost': 12.85, u'closeable_amount': 7700, u'price': 13.99, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-08 16:00:00'}, {u'amount': 7700, u'avg_cost': 12.85, u'closeable_amount': 7700, u'price': 13.74, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-09 16:00:00'}, {u'amount': 7700, u'avg_cost': 12.85, u'closeable_amount': 7700, u'price': 13.5, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-10 16:00:00'}, {u'amount': 9000, u'avg_cost': 11.62, u'closeable_amount': 0, u'price': 11.27, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-01 16:00:00'}, {u'amount': 9000, u'avg_cost': 11.19, u'closeable_amount': 0, u'price': 10.68, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-08 16:00:00'}, {u'amount': 8500, u'avg_cost': 11.22, u'closeable_amount': 0, u'price': 12.03, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-10 16:00:00'}, {u'amount': 8500, u'avg_cost': 11.22, u'closeable_amount': 8500, u'price': 11.69, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-13 16:00:00'}, {u'amount': 8500, u'avg_cost': 11.22, u'closeable_amount': 8500, u'price': 11.23, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-14 16:00:00'}, {u'amount': 9100, u'avg_cost': 10.35, u'closeable_amount': 0, u'price': 10.41, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-04 16:00:00'}, {u'amount': 9100, u'avg_cost': 10.35, u'closeable_amount': 9100, u'price': 10.19, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-05 16:00:00'}, {u'amount': 9100, u'avg_cost': 10.35, u'closeable_amount': 9100, u'price': 10.14, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-06 16:00:00'}, {u'amount': 8900, u'avg_cost': 10.46, u'closeable_amount': 0, u'price': 10.39, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-11 16:00:00'}, {u'amount': 8900, u'avg_cost': 10.46, u'closeable_amount': 8900, u'price': 10.17, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-12 16:00:00'}, {u'amount': 10200, u'avg_cost': 8.82, u'closeable_amount': 0, u'price': 8.77, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-28 16:00:00'}, {u'amount': 10200, u'avg_cost': 8.82, u'closeable_amount': 10200, u'price': 8.96, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-31 16:00:00'}, {u'amount': 10200, u'avg_cost': 8.82, u'closeable_amount': 10200, u'price': 9.36, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-09-01 16:00:00'}, {u'amount': 10200, u'avg_cost': 8.82, u'closeable_amount': 10200, u'price': 9.58, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-09-02 16:00:00'}, {u'amount': 10200, u'avg_cost': 8.82, u'closeable_amount': 10200, u'price': 8.81, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-09-07 16:00:00'}, {u'amount': 10300, u'avg_cost': 8.71, u'closeable_amount': 0, u'price': 8.82, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-09 16:00:00'}, {u'amount': 10300, u'avg_cost': 8.71, u'closeable_amount': 10300, u'price': 9.09, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-12 16:00:00'}, {u'amount': 10300, u'avg_cost': 8.71, u'closeable_amount': 10300, u'price': 9.01, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-13 16:00:00'}, {u'amount': 10300, u'avg_cost': 8.71, u'closeable_amount': 10300, u'price': 8.89, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-14 16:00:00'}, {u'amount': 9900, u'avg_cost': 9.15, u'closeable_amount': 0, u'price': 9.08, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-21 16:00:00'}, {u'amount': 9600, u'avg_cost': 9.4, u'closeable_amount': 0, u'price': 9.32, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-26 16:00:00'}, {u'amount': 9600, u'avg_cost': 9.4, u'closeable_amount': 9600, u'price': 9.29, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-27 16:00:00'}, {u'amount': 9600, u'avg_cost': 9.4, u'closeable_amount': 9600, u'price': 9.12, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-28 16:00:00'}, {u'amount': 9300, u'avg_cost': 9.4, u'closeable_amount': 0, u'price': 9.77, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-05 16:00:00'}, {u'amount': 9300, u'avg_cost': 9.4, u'closeable_amount': 9300, u'price': 10.03, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-06 16:00:00'}, {u'amount': 9300, u'avg_cost': 9.4, u'closeable_amount': 9300, u'price': 10.47, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-09 16:00:00'}, {u'amount': 9300, u'avg_cost': 9.4, u'closeable_amount': 9300, u'price': 10.32, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-10 16:00:00'}, {u'amount': 9300, u'avg_cost': 9.4, u'closeable_amount': 9300, u'price': 10.16, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-11 16:00:00'}, {u'amount': 9300, u'avg_cost': 9.4, u'closeable_amount': 9300, u'price': 10.04, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-12 16:00:00'}, {u'amount': 9100, u'avg_cost': 10.04, u'closeable_amount': 0, u'price': 10.08, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-03 16:00:00'}, {u'amount': 9100, u'avg_cost': 10.04, u'closeable_amount': 9100, u'price': 9.81, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-04 16:00:00'}, {u'amount': 9100, u'avg_cost': 10.04, u'closeable_amount': 9100, u'price': 9.83, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-07 16:00:00'}, {u'amount': 9000, u'avg_cost': 9.84, u'closeable_amount': 0, u'price': 10.13, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-21 16:00:00'}, {u'amount': 9000, u'avg_cost': 9.84, u'closeable_amount': 9000, u'price': 10.06, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-22 16:00:00'}, {u'amount': 9000, u'avg_cost': 9.84, u'closeable_amount': 9000, u'price': 10.1, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-23 16:00:00'}, {u'amount': 9000, u'avg_cost': 9.84, u'closeable_amount': 9000, u'price': 9.99, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-24 16:00:00'}]
gt.get_orders() # 获取交易列表
[{u'action': u'open', u'amount': 7700, u'commission': 29.68, u'filled': 7700, u'price': 12.85, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-04 09:30:00'}, {u'action': u'close', u'amount': 7700, u'commission': 134.93, u'filled': 7700, u'price': 13.48, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-06-11 09:30:00'}, {u'action': u'open', u'amount': 9000, u'commission': 31.37, u'filled': 9000, u'price': 11.62, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-01 09:30:00'}, {u'action': u'close', u'amount': 9000, u'commission': 131.51, u'filled': 9000, u'price': 11.24, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-02 09:30:00'}, {u'action': u'open', u'amount': 9000, u'commission': 30.21, u'filled': 9000, u'price': 11.19, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-08 09:30:00'}, {u'action': u'close', u'amount': 9000, u'commission': 124.84, u'filled': 9000, u'price': 10.67, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-09 09:30:00'}, {u'action': u'open', u'amount': 8500, u'commission': 28.61, u'filled': 8500, u'price': 11.22, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-10 09:30:00'}, {u'action': u'close', u'amount': 8500, u'commission': 122.1, u'filled': 8500, u'price': 11.05, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-07-15 09:30:00'}, {u'action': u'open', u'amount': 9100, u'commission': 28.26, u'filled': 9100, u'price': 10.35, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-04 09:30:00'}, {u'action': u'close', u'amount': 9100, u'commission': 120.67, u'filled': 9100, u'price': 10.2, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-07 09:30:00'}, {u'action': u'open', u'amount': 8900, u'commission': 27.93, u'filled': 8900, u'price': 10.46, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-11 09:30:00'}, {u'action': u'close', u'amount': 8900, u'commission': 117.09, u'filled': 8900, u'price': 10.12, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-13 09:30:00'}, {u'action': u'open', u'amount': 10200, u'commission': 26.99, u'filled': 10200, u'price': 8.82, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-08-28 09:30:00'}, {u'action': u'close', u'amount': 10200, u'commission': 116.69, u'filled': 10200, u'price': 8.8, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-09-08 09:30:00'}, {u'action': u'open', u'amount': 10300, u'commission': 26.91, u'filled': 10300, u'price': 8.71, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-09 09:30:00'}, {u'action': u'close', u'amount': 10300, u'commission': 118.5, u'filled': 10300, u'price': 8.85, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-15 09:30:00'}, {u'action': u'open', u'amount': 9900, u'commission': 27.18, u'filled': 9900, u'price': 9.15, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-21 09:30:00'}, {u'action': u'close', u'amount': 9900, u'commission': 117.12, u'filled': 9900, u'price': 9.1, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-22 09:30:00'}, {u'action': u'open', u'amount': 9600, u'commission': 27.07, u'filled': 9600, u'price': 9.4, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-26 09:30:00'}, {u'action': u'close', u'amount': 9600, u'commission': 114.07, u'filled': 9600, u'price': 9.14, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-10-29 09:30:00'}, {u'action': u'open', u'amount': 9300, u'commission': 26.23, u'filled': 9300, u'price': 9.4, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-05 09:30:00'}, {u'action': u'close', u'amount': 9300, u'commission': 119.45, u'filled': 9300, u'price': 9.88, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-11-13 09:30:00'}, {u'action': u'open', u'amount': 9100, u'commission': 27.41, u'filled': 9100, u'price': 10.04, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-03 09:30:00'}, {u'action': u'close', u'amount': 9100, u'commission': 115.46, u'filled': 9100, u'price': 9.76, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-08 09:30:00'}, {u'action': u'open', u'amount': 9000, u'commission': 26.57, u'filled': 9000, u'price': 9.84, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-21 09:30:00'}, {u'action': u'close', u'amount': 9000, u'commission': 117.12, u'filled': 9000, u'price': 10.01, u'security': u'000001.XSHE', u'security_name': u'\u5e73\u5b89\u94f6\u884c', u'time': u'2015-12-25 09:30:00'}]
gt.get_records() # 获取所有record()记录
[{u'stock_price': 12.4, u'time': u'2015-06-01'}, {u'stock_price': 12.87, u'time': u'2015-06-02'}, {u'stock_price': 12.76, u'time': u'2015-06-03'}, {u'stock_price': 12.81, u'time': u'2015-06-04'}, {u'stock_price': 13.25, u'time': u'2015-06-05'}, {u'stock_price': 13.19, u'time': u'2015-06-08'}, {u'stock_price': 13.99, u'time': u'2015-06-09'}, {u'stock_price': 13.74, u'time': u'2015-06-10'}, {u'stock_price': 13.5, u'time': u'2015-06-11'}, {u'stock_price': 13.34, u'time': u'2015-06-12'}, {u'stock_price': 13.36, u'time': u'2015-06-15'}, {u'stock_price': 12.89, u'time': u'2015-06-16'}, {u'stock_price': 12.66, u'time': u'2015-06-17'}, {u'stock_price': 12.73, u'time': u'2015-06-18'}, {u'stock_price': 12.45, u'time': u'2015-06-19'}, {u'stock_price': 11.84, u'time': u'2015-06-23'}, {u'stock_price': 12.1, u'time': u'2015-06-24'}, {u'stock_price': 12.24, u'time': u'2015-06-25'}, {u'stock_price': 12.04, u'time': u'2015-06-26'}, {u'stock_price': 11.15, u'time': u'2015-06-29'}, {u'stock_price': 10.98, u'time': u'2015-06-30'}, {u'stock_price': 11.77, u'time': u'2015-07-01'}, {u'stock_price': 11.27, u'time': u'2015-07-02'}, {u'stock_price': 11.13, u'time': u'2015-07-03'}, {u'stock_price': 10.58, u'time': u'2015-07-06'}, {u'stock_price': 11.23, u'time': u'2015-07-07'}, {u'stock_price': 11.86, u'time': u'2015-07-08'}, {u'stock_price': 10.68, u'time': u'2015-07-09'}, {u'stock_price': 11.54, u'time': u'2015-07-10'}, {u'stock_price': 12.03, u'time': u'2015-07-13'}, {u'stock_price': 11.69, u'time': u'2015-07-14'}, {u'stock_price': 11.23, u'time': u'2015-07-15'}, {u'stock_price': 10.99, u'time': u'2015-07-16'}, {u'stock_price': 11.01, u'time': u'2015-07-17'}, {u'stock_price': 11.19, u'time': u'2015-07-20'}, {u'stock_price': 11.01, u'time': u'2015-07-21'}, {u'stock_price': 10.98, u'time': u'2015-07-22'}, {u'stock_price': 10.94, u'time': u'2015-07-23'}, {u'stock_price': 11.06, u'time': u'2015-07-24'}, {u'stock_price': 10.83, u'time': u'2015-07-27'}, {u'stock_price': 10.07, u'time': u'2015-07-28'}, {u'stock_price': 10.21, u'time': u'2015-07-29'}, {u'stock_price': 10.2, u'time': u'2015-07-30'}, {u'stock_price': 9.92, u'time': u'2015-07-31'}, {u'stock_price': 10.0, u'time': u'2015-08-03'}, {u'stock_price': 10.38, u'time': u'2015-08-04'}, {u'stock_price': 10.41, u'time': u'2015-08-05'}, {u'stock_price': 10.19, u'time': u'2015-08-06'}, {u'stock_price': 10.14, u'time': u'2015-08-07'}, {u'stock_price': 10.21, u'time': u'2015-08-10'}, {u'stock_price': 10.46, u'time': u'2015-08-11'}, {u'stock_price': 10.39, u'time': u'2015-08-12'}, {u'stock_price': 10.17, u'time': u'2015-08-13'}, {u'stock_price': 10.17, u'time': u'2015-08-14'}, {u'stock_price': 10.23, u'time': u'2015-08-17'}, {u'stock_price': 10.15, u'time': u'2015-08-18'}, {u'stock_price': 9.93, u'time': u'2015-08-19'}, {u'stock_price': 9.9, u'time': u'2015-08-20'}, {u'stock_price': 9.75, u'time': u'2015-08-21'}, {u'stock_price': 9.31, u'time': u'2015-08-24'}, {u'stock_price': 8.38, u'time': u'2015-08-25'}, {u'stock_price': 7.66, u'time': u'2015-08-26'}, {u'stock_price': 8.02, u'time': u'2015-08-27'}, {u'stock_price': 8.74, u'time': u'2015-08-28'}, {u'stock_price': 8.77, u'time': u'2015-08-31'}, {u'stock_price': 8.96, u'time': u'2015-09-01'}, {u'stock_price': 9.36, u'time': u'2015-09-02'}, {u'stock_price': 9.58, u'time': u'2015-09-07'}, {u'stock_price': 8.81, u'time': u'2015-09-08'}, {u'stock_price': 8.9, u'time': u'2015-09-09'}, {u'stock_price': 8.98, u'time': u'2015-09-10'}, {u'stock_price': 8.94, u'time': u'2015-09-11'}, {u'stock_price': 8.87, u'time': u'2015-09-14'}, {u'stock_price': 8.8, u'time': u'2015-09-15'}, {u'stock_price': 8.56, u'time': u'2015-09-16'}, {u'stock_price': 8.82, u'time': u'2015-09-17'}, {u'stock_price': 8.72, u'time': u'2015-09-18'}, {u'stock_price': 8.75, u'time': u'2015-09-21'}, {u'stock_price': 8.76, u'time': u'2015-09-22'}, {u'stock_price': 8.87, u'time': u'2015-09-23'}, {u'stock_price': 8.66, u'time': u'2015-09-24'}, {u'stock_price': 8.67, u'time': u'2015-09-25'}, {u'stock_price': 8.54, u'time': u'2015-09-28'}, {u'stock_price': 8.52, u'time': u'2015-09-29'}, {u'stock_price': 8.4, u'time': u'2015-09-30'}, {u'stock_price': 8.49, u'time': u'2015-10-08'}, {u'stock_price': 8.66, u'time': u'2015-10-09'}, {u'stock_price': 8.82, u'time': u'2015-10-12'}, {u'stock_price': 9.09, u'time': u'2015-10-13'}, {u'stock_price': 9.01, u'time': u'2015-10-14'}, {u'stock_price': 8.89, u'time': u'2015-10-15'}, {u'stock_price': 9.04, u'time': u'2015-10-16'}, {u'stock_price': 9.09, u'time': u'2015-10-19'}, {u'stock_price': 9.11, u'time': u'2015-10-20'}, {u'stock_price': 9.16, u'time': u'2015-10-21'}, {u'stock_price': 9.08, u'time': u'2015-10-22'}, {u'stock_price': 9.17, u'time': u'2015-10-23'}, {u'stock_price': 9.28, u'time': u'2015-10-26'}, {u'stock_price': 9.32, u'time': u'2015-10-27'}, {u'stock_price': 9.29, u'time': u'2015-10-28'}, {u'stock_price': 9.12, u'time': u'2015-10-29'}, {u'stock_price': 9.12, u'time': u'2015-10-30'}, {u'stock_price': 9.19, u'time': u'2015-11-02'}, {u'stock_price': 9.02, u'time': u'2015-11-03'}, {u'stock_price': 8.94, u'time': u'2015-11-04'}, {u'stock_price': 9.46, u'time': u'2015-11-05'}, {u'stock_price': 9.77, u'time': u'2015-11-06'}, {u'stock_price': 10.03, u'time': u'2015-11-09'}, {u'stock_price': 10.47, u'time': u'2015-11-10'}, {u'stock_price': 10.32, u'time': u'2015-11-11'}, {u'stock_price': 10.16, u'time': u'2015-11-12'}, {u'stock_price': 10.04, u'time': u'2015-11-13'}, {u'stock_price': 9.91, u'time': u'2015-11-16'}, {u'stock_price': 9.99, u'time': u'2015-11-17'}, {u'stock_price': 10.12, u'time': u'2015-11-18'}, {u'stock_price': 10.05, u'time': u'2015-11-19'}, {u'stock_price': 10.12, u'time': u'2015-11-20'}, {u'stock_price': 10.16, u'time': u'2015-11-23'}, {u'stock_price': 10.08, u'time': u'2015-11-24'}, {u'stock_price': 9.94, u'time': u'2015-11-25'}, {u'stock_price': 9.97, u'time': u'2015-11-26'}, {u'stock_price': 9.9, u'time': u'2015-11-27'}, {u'stock_price': 9.49, u'time': u'2015-11-30'}, {u'stock_price': 9.5, u'time': u'2015-12-01'}, {u'stock_price': 9.51, u'time': u'2015-12-02'}, {u'stock_price': 10.13, u'time': u'2015-12-03'}, {u'stock_price': 10.08, u'time': u'2015-12-04'}, {u'stock_price': 9.81, u'time': u'2015-12-07'}, {u'stock_price': 9.83, u'time': u'2015-12-08'}, {u'stock_price': 9.68, u'time': u'2015-12-09'}, {u'stock_price': 9.7, u'time': u'2015-12-10'}, {u'stock_price': 9.68, u'time': u'2015-12-11'}, {u'stock_price': 9.58, u'time': u'2015-12-14'}, {u'stock_price': 9.77, u'time': u'2015-12-15'}, {u'stock_price': 9.65, u'time': u'2015-12-16'}, {u'stock_price': 9.62, u'time': u'2015-12-17'}, {u'stock_price': 9.77, u'time': u'2015-12-18'}, {u'stock_price': 9.9, u'time': u'2015-12-21'}, {u'stock_price': 10.13, u'time': u'2015-12-22'}, {u'stock_price': 10.06, u'time': u'2015-12-23'}, {u'stock_price': 10.1, u'time': u'2015-12-24'}, {u'stock_price': 9.99, u'time': u'2015-12-25'}, {u'stock_price': 10.04, u'time': u'2015-12-28'}, {u'stock_price': 9.7, u'time': u'2015-12-29'}, {u'stock_price': 9.79, u'time': u'2015-12-30'}]
gt.get_risk() # 获取总的风险指标
{u'__version': 101, u'algorithm_return': -0.09325970000000006, u'algorithm_volatility': 0.24686601869782554, u'alpha': -0.1264840086118137, u'annual_algo_return': -0.15531518517855092, u'annual_bm_return': -0.3516090579148625, u'benchmark_return': -0.22220450257590085, u'benchmark_volatility': 0.44370449985970895, u'beta': 0.17576502681840783, u'day_win_ratio': 0.42758620689655175, u'excess_return': -0.11649257671232882, u'information': 0.44992933161432286, u'lose_count': 9, u'max_drawdown': 0.19463270788918885, u'max_drawdown_period': [u'2015-06-08', u'2015-10-28'], u'max_leverage': 0.0, u'period_label': u'2015-12', u'profit_loss_ratio': 0.6243711570709893, u'sharpe': -0.79117890023424, u'sortino': -0.867468062186946, u'trading_days': 145, u'treasury_return': 0.02323287671232877, u'win_count': 4, u'win_ratio': 0.3076923076923077}
k = gt.get_risk()
k['max_drawdown_period'] = [(u'2015-04-16', u'2015-10-28')]
import pandas as pd
pd.DataFrame(k)
__version | algorithm_return | algorithm_volatility | alpha | annual_algo_return | annual_bm_return | benchmark_return | benchmark_volatility | beta | day_win_ratio | ... | max_drawdown_period | max_leverage | period_label | profit_loss_ratio | sharpe | sortino | trading_days | treasury_return | win_count | win_ratio | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 101 | -0.09326 | 0.246866 | -0.126484 | -0.155315 | -0.351609 | -0.222205 | 0.443704 | 0.175765 | 0.427586 | ... | (2015-04-16, 2015-10-28) | 0.0 | 2015-12 | 0.624371 | -0.791179 | -0.867468 | 145 | 0.023233 | 4 | 0.307692 |
1 rows × 24 columns
gt.get_period_risks() # 获取分月计算的风险指标
{'algorithm_return': one_month three_month six_month twelve_month 2015-06 0.046864 NaN NaN NaN 2015-07 -0.095654 NaN NaN NaN 2015-08 -0.034687 -0.086112 NaN NaN 2015-09 -0.019135 -0.143727 NaN NaN 2015-10 -0.022087 -0.074071 NaN NaN 2015-11 0.049262 0.006454 -0.080214 NaN 2015-12 -0.014183 0.011534 -0.133851 NaN, 'algorithm_volatility': one_month three_month six_month twelve_month 2015-06 0.251622 NaN NaN NaN 2015-07 0.342315 NaN NaN NaN 2015-08 0.136963 0.260242 NaN NaN 2015-09 0.344152 0.288331 NaN NaN 2015-10 0.169573 0.232747 NaN NaN 2015-11 0.247332 0.264006 0.261217 NaN 2015-12 0.146573 0.191906 0.246264 NaN, 'alpha': one_month three_month six_month twelve_month 2015-06 0.735366 NaN NaN NaN 2015-07 -0.475093 NaN NaN NaN 2015-08 -0.364626 -0.227756 NaN NaN 2015-09 -0.105391 -0.363256 NaN NaN 2015-10 -1.751701 -0.283988 NaN NaN 2015-11 0.708999 -0.089500 -0.110792 NaN 2015-12 -0.445724 -0.297888 -0.223360 NaN, 'benchmark_return': one_month three_month six_month twelve_month 2015-06 -0.075985 NaN NaN NaN 2015-07 -0.146725 NaN NaN NaN 2015-08 -0.117946 -0.304554 NaN NaN 2015-09 -0.048592 -0.283937 NaN NaN 2015-10 0.103383 -0.074048 NaN NaN 2015-11 0.009149 0.059371 -0.263264 NaN 2015-12 0.055732 0.175534 -0.158244 NaN, 'benchmark_volatility': one_month three_month six_month twelve_month 2015-06 0.553131 NaN NaN NaN 2015-07 0.605976 NaN NaN NaN 2015-08 0.602886 0.579502 NaN NaN 2015-09 0.341508 0.528661 NaN NaN 2015-10 0.254009 0.435778 NaN NaN 2015-11 0.303270 0.303330 0.470614 NaN 2015-12 0.242035 0.265819 0.424935 NaN, 'beta': one_month three_month six_month twelve_month 2015-06 0.077529 NaN NaN NaN 2015-07 0.266485 NaN NaN NaN 2015-08 0.022695 0.132428 NaN NaN 2015-09 0.296257 0.170775 NaN NaN 2015-10 0.446108 0.118918 NaN NaN 2015-11 0.317140 0.320417 0.170118 NaN 2015-12 0.315107 0.332873 0.204439 NaN, 'information': one_month three_month six_month twelve_month 2015-06 2.409919 NaN NaN NaN 2015-07 0.941784 NaN NaN NaN 2015-08 1.491993 1.626420 NaN NaN 2015-09 0.940981 1.156385 NaN NaN 2015-10 -9.504728 -0.151490 NaN NaN 2015-11 1.459239 -0.722447 0.805395 NaN 2015-12 -3.836540 -2.618727 -0.007429 NaN, 'max_drawdown': one_month three_month six_month twelve_month 2015-06 0.037352 NaN NaN NaN 2015-07 0.095654 NaN NaN NaN 2015-08 0.060297 0.177451 NaN NaN 2015-09 0.082616 0.145535 NaN NaN 2015-10 0.063563 0.103676 NaN NaN 2015-11 0.057452 0.103676 0.194633 NaN 2015-12 0.032795 0.085027 0.163384 NaN, 'sharpe': one_month three_month six_month twelve_month 2015-06 2.722326 NaN NaN NaN 2015-07 -2.058756 NaN NaN NaN 2015-08 -2.797356 -1.278522 NaN NaN 2015-09 -0.739650 -1.715168 NaN NaN 2015-10 -1.886834 -1.384793 NaN NaN 2015-11 2.962136 -0.045016 -0.751448 NaN 2015-12 -1.295178 0.046603 -1.183779 NaN, 'sortino': one_month three_month six_month twelve_month 2015-06 5.663754 NaN NaN NaN 2015-07 -4.056391 NaN NaN NaN 2015-08 -3.296274 -1.742154 NaN NaN 2015-09 -0.346371 -1.393109 NaN NaN 2015-10 -3.025377 -1.032753 NaN NaN 2015-11 4.867143 -0.049848 -0.845587 NaN 2015-12 -1.578239 0.076382 -1.182389 NaN}
gt.get_period_risks()['alpha'] # 获取分月计算的风险指标中的alpha
one_month | three_month | six_month | twelve_month | |
---|---|---|---|---|
2015-06 | 0.735366 | NaN | NaN | NaN |
2015-07 | -0.475093 | NaN | NaN | NaN |
2015-08 | -0.364626 | -0.227756 | NaN | NaN |
2015-09 | -0.105391 | -0.363256 | NaN | NaN |
2015-10 | -1.751701 | -0.283988 | NaN | NaN |
2015-11 | 0.708999 | -0.089500 | -0.110792 | NaN |
2015-12 | -0.445724 | -0.297888 | -0.223360 | NaN |
如有任何疑问,请咨询聚宽官方人员。
聚宽(JoinQuant)因你而多彩, 感谢有你~~~
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...