# coding=utf-8
from __future__ import print_function, absolute_import
from gm.api import *
import numpy as np
# 策略中必须有init方法
def init(context):
today = context.now
# 设置标的股票
context.symbol = 'SHSE.600000'
# 用于判定第一个仓位是否成功开仓
context.first = 0
# 订阅浦发银行, bar频率为1min
subscribe(symbols=context.symbol, frequency='1d', count=3)
# 日内回转每次交易100股
context.trade_n = 100
# 获取昨今天的时间
context.day = [0, 0]
# 获取历史价格
data = history_n(symbol=context.symbol, frequency='1d', end_time=today, count=3,
fill_missing='last', df=True)
close = data['close'].values
max_x = data['high'].values
min_n = data['low'].values
amount = data['amount'].values
市值 = stocks[(stocks['NEGOTIABLEMV'] == MV) & (stocks['BM'] == BM)]
avg = np.mean(close)
avg_amount = np.mean(amount)
max_high = max_x[-1]
min_colse = min_n[-1]
print('收盘价:{},最高价:{},最低价:{},成交量:{}'.format(close, max_x, min_n, amount))
print('收盘均价:{},最高价:{},最低价:{},成交量:{}'.format(avg, max_high, min_colse, avg_amount))
print(市值)
# print('最高价:{}'.format(max_x))
# print('最低价:{}'.format(min_n))
# print('成交量:{}'.format(amount))
if __name__ == '__main__':
'''
strategy_id策略ID, 由系统生成
filename文件名, 请与本文件名保持一致
mode运行模式, 实时模式:MODE_LIVE回测模式:MODE_BACKTEST
token绑定计算机的ID, 可在系统设置-密钥管理中生成
backtest_start_time回测开始时间
backtest_end_time回测结束时间
backtest_adjust股票复权方式, 不复权:ADJUST_NONE前复权:ADJUST_PREV后复权:ADJUST_POST
backtest_initial_cash回测初始资金
backtest_commission_ratio回测佣金比例
backtest_slippage_ratio回测滑点比例
'''
run(strategy_id='f197c2fc-8305-11eb-9dab-00ff7c7ac806',
filename='test.py',
mode=MODE_BACKTEST,
token='2c705a9dd13617610384e13505253dbe93d698eb',
backtest_start_time='2021-03-10 08:00:00',
backtest_end_time='2021-03-12 16:00:00',
backtest_adjust=ADJUST_PREV,
backtest_initial_cash=10000000,
backtest_commission_ratio=0.0001,
backtest_slippage_ratio=0.0001)