def on_initialize(self):
        self.myinstr = "XSHE_000513"
        self.bartype1 = "Bar_1day"  #type1:订阅1day k线
        self.bartype2 = "Bar_1min"  #type2:订阅1min k线
        self.subscribe(self.myinstr, self.bartype1)  #订阅1day K线 of 白云机场
        self.subscribe(self.myinstr, self.bartype2)
        self.date = []

        self.order0 = 0  ##6个订单编号
        self.order1 = 0
        self.order2 = 0
        self.order3 = 0
        self.order4 = 0
        self.order5 = 0

        self.bar0 = 0  ##6个收集bartype收盘价的全局变量
        self.bar1 = 0
        self.bar2 = 0
        self.bar3 = 0
        self.bar4 = 0
        self.bar5 = 0

        self.default_date = chrono.Date(19700101)
        self.date0 = self.default_date
        self.total_volumn = 0  ##用于计算每次分次下单的总交易额,在下一个交易日分次下单之前清零。
        self.total_size = 0  ## 用于计算每次分次下单的总股数,在下一个交易日分次下单之前清零。
        self.average_price = 0  ## 分次下单的平均价格
        self.average_price_once = 0  ## 集合竞价的平均撮合价格
        self.Trade_date = []  ##空列表,搜集SEP后的第五个交易日期,每一个列表中的交易日,我们将在下一个交易日交易
        self.history = []  # 存档历史数据  这个应该是bar类型
예제 #2
0
    def on_initialize(self):

        self.bartype1 = "Bar_1day"  #type1:订阅1day k线
        self.bartype2 = "Bar_1min"  #type2:订阅1min k线
        self.default_date = chrono.Date(19700101)

        self.list = DataFrame(pd.read_csv("/workspace/user-files/Sh_list.csv"))
        self.df = DataFrame(columns=[
            'date', 'history', 'order0', 'order1', 'order2', 'order3',
            'order4', 'order5', 'bar0', 'bar1', 'bar2', 'bar3', 'bar4', 'bar5',
            't0', 't1', 't2', 't3', 't4', 't5', 'Trade_date', 'date0',
            'total_volumn', 'total_size', 'average_price', 'average_price_once'
        ],
                            index=self.list['name'])
        ## 可以将异常数据和统计量统一打到这张DataFrame里面,然后取出这些行列打表
        #
        #结果输出可以用pd.concat([])去写
        self.report = DataFrame(columns=['report'], index=self.list['name'])

        for instr in self.list['name']:
            self.subscribe(instr, self.bartype1)  #订阅1day K线
            self.subscribe(instr, self.bartype2)  #订阅1min K线
            self.df['date'][instr] = []  ## 对应于该只股票的空列表,存档每只股票的交易日,因为不同股票可能不一样
            self.df['Trade_date'][instr] = [
            ]  ## 对应于该只股票的空列表,搜集SEP后的第五个交易日期,每一个列表中的交易日,我们将在下一个交易日交易
            self.df['history'][instr] = []  ## 对应于该只股票的空列表,存档每日收盘价
            self.df['date0'][instr] = self.default_date
예제 #3
0
 def on_initialize(self):
     #load参数
     self.myinstr = "XSHE_000513"
     self.bartype = "Bar_5min" #订阅5分钟k线
     self.buyunit = 100 # 1手
     self.subscribe(self.myinstr,self.bartype)         
     self.best_day = chrono.Date(20160712)
     self.a0 = self.add_alarm(chrono.str_to_time(str(self.best_day)+" 01:35:00.000000"))
예제 #4
0
 def on_initialize(self):
     self.myinstr = "XSHE_000513"
     self.bartype1 = "Bar_1day"  #type1:订阅1day k线
     #self.bartype2 = "Bar_1min" #type2:订阅1min k线
     self.buyunit = 100  # 1手
     self.subscribe(self.myinstr, self.bartype1)  #订阅1day K线 of 白云机场
     #self.subscribe(self.myinstr,self.bartype2)
     self.default_date = chrono.Date(19700101)
     self.date = []
     self.Trade_date = []  ##空列表,搜集SEP后的交易日期
     self.history = []  # 存档300天历史数据  这个应该是bar类型
예제 #5
0
    def on_initialize(self):

        self.bartype1 = "Bar_1day"  #type1:订阅1day k线
        self.bartype2 = "Bar_1min"  #type2:订阅1min k线
        self.default_date = chrono.Date(19700101)
        self.list = DataFrame(
            pd.read_csv("/workspace/user-files/Sh_list2.csv"))
        self.df = DataFrame(columns=[
            'date', 'history', 'order0', 'order1', 'order2', 'order3',
            'order4', 'order5', 'bar0', 'bar1', 'bar2', 'bar3', 'bar4', 'bar5',
            't0', 't1', 't2', 't3', 't4', 't5', 'Trade_date', 'date0',
            'total_volumn', 'total_size', 'average_price',
            'average_price_once', 'price1', 'price2', 'price3', 'price4',
            'price5'
        ],
                            index=self.list['name'])
        self.report = DataFrame(columns=['report', 'order_record'],
                                index=self.list['name'])
        ## 可以将异常数据和统计量统一打到这张DataFrame里面,然后取出这些行列打表
        ############初始化################################################
        for instr in self.list['name']:
            self.subscribe(instr, self.bartype1)  #订阅1day K线
            self.subscribe(instr, self.bartype2)  #订阅1min K线
            self.df['date'][instr] = []  ## 对应于该只股票的空列表,存档每只股票的交易日,因为不同股票可能不一样
            self.df['Trade_date'][instr] = [
            ]  ## 对应于该只股票的空列表,搜集SEP后的第五个交易日期,每一个列表中的交易日,我们将在下一个交易日交易
            self.df['history'][instr] = []  ## 对应于该只股票的空列表,存档每日收盘价
            self.df['date0'][instr] = self.default_date
            ## report 为记录输出结果的DataFrame,‘report'用来记录交易日的信息,’order_record'用来记录订单的详情。
            self.report['report'][instr] = {}
            self.report['report'][instr]['date'] = []  #记录交易日
            self.report['report'][instr]['stock_id'] = []  #记录交易品种
            self.report['report'][instr]['possible_error0'] = [
            ]  #记录可能出现的错误:集合竞价与分次下单平均价格差别太大。
            self.report['report'][instr]['possible_error1'] = [
            ]  #记录可能出现的错误:bar线数据与实际成交数据差别太大。

            self.report['order_record'][instr] = {}
            self.report['order_record'][instr]['datetime'] = []  #订单对应的交易日
            self.report['report'][instr]['stock_id'] = []  #重复记录交易品种 其实可有可无
            self.report['order_record'][instr]['time0'] = []  #每天order0结束成交的时间
            self.report['order_record'][instr]['time1'] = []  #每天order1结束成交的时间
            self.report['order_record'][instr]['time2'] = []  #每天order2结束成交的时间
            self.report['order_record'][instr]['time3'] = []  #每天order3结束成交的时间
            self.report['order_record'][instr]['time4'] = []  #每天order4结束成交的时间
            self.report['order_record'][instr]['time5'] = []  #每天order5结束成交的时间

            self.report['order_record'][instr]['value_single'] = []  #集合竞价的总价值
            self.report['order_record'][instr]['size_single'] = []  #集合竞价的单子大小
            self.report['order_record'][instr]['auction_price'] = []  #集合竞价价格
            self.report['order_record'][instr]['value_all'] = []  #分次下单的总价值
            self.report['order_record'][instr]['size_all'] = []  #分次下单的总单量
            self.report['order_record'][instr]['average_price'] = []  #分次下单的均价
    def on_initialize(self):

        self.list = DataFrame(pd.read_csv("/workspace/user-files/Sh_list.csv"))

        self.bartype1 = "Bar_1day"  #type1:订阅1day k线
        self.bartype2 = "Bar_1min"  #type2:订阅1min k线

        for instr in self.list['name']:
            self.subscribe(instr, self.bartype1)  #订阅1day K线
            self.subscribe(instr, self.bartype2)  #订阅1min K线

        self.date = {}

        self.order0 = {}  ##6个订单编号
        self.order1 = {}
        self.order2 = {}
        self.order3 = {}
        self.order4 = {}
        self.order5 = {}

        self.bar0 = {}  ##6个收集bartype收盘价的全局变量
        self.bar1 = {}
        self.bar2 = {}
        self.bar3 = {}
        self.bar4 = {}
        self.bar5 = {}

        self.Trade_date = {}  ##空字典,搜集SEP后的第五个交易日期,每一个列表中的交易日,我们将在下一个交易日交易
        self.history = {}  # 存档历史数据  这个应该是bar类型

        self.t0 = {}  ##存档对应于某一只股票的交易闹钟
        self.t1 = {}
        self.t2 = {}
        self.t3 = {}
        self.t4 = {}
        self.t5 = {}

        self.default_date = chrono.Date(19700101)
        self.date0 = {}  ##用来在timeline上更新 对于某一只股票来说,每一日是否是买入日

        self.total_volumn = {}  ##用于计算每次分次下单的总交易额,在下一个交易日分次下单之前清零。
        self.total_size = {}  ## 用于计算每次分次下单的总股数,在下一个交易日分次下单之前清零。
        self.average_price = {}  ## 分次下单的平均价格
        self.average_price_once = {}  ## 集合竞价价格
예제 #7
0
 def on_data_update(self, data):
         #增加最新数据,去掉最旧数据
     self.history = np.append(self.history, data.close)
     self.history = np.delete(self.history, 0)
     
     self.date = np.append(self.date, data.date)
     self.date = np.delete(self.date, 0)
         
     record = []
     SEP_date = []
     
     for i in range(4,len(self.history)-4):
         if(self.history[i] > max(self.history[i-4:i]) and self.history[i] > max(self.history[i+1:i+5])):
             record.append(i) 
             SEP_date.append(self.date[i])
             
     for j in record:
         print j
         
     print chrono.Date(SEP_date)
예제 #8
0
    def on_initialize(self):

        self.bartype1 = "Bar_1day"  #type1:订阅1day k线
        self.bartype2 = "Bar_1min"  #type2:订阅1min k线
        self.default_date = chrono.Date(19700101)

        self.list = DataFrame(pd.read_csv("/workspace/user-files/Sh_list.csv"))
        self.df = DataFrame(columns=[
            'date', 'history', 'order0', 'order1', 'order2', 'order3',
            'order4', 'order5', 'bar0', 'bar1', 'bar2', 'bar3', 'bar4', 'bar5',
            't0', 't1', 't2', 't3', 't4', 't5', 'Trade_date', 'date0',
            'total_volumn', 'total_size', 'average_price', 'average_price_once'
        ],
                            index=self.list['name'])

        for instr in self.list['name']:

            self.subscribe(instr, self.bartype1)  #订阅1day K线
            self.subscribe(instr, self.bartype2)  #订阅1min K线

            # self.df['date'][instr] = []
            # self.df['history'][instr] = []
            self.df['date0'][instr] = self.default_date
            self.df['order0'][instr] = 0
            self.df['order1'][instr] = 0
            self.df['order2'][instr] = 0
            self.df['order3'][instr] = 0
            self.df['order4'][instr] = 0
            self.df['order5'][instr] = 0
            self.df['bar0'][instr] = 0
            self.df['bar1'][instr] = 0
            self.df['bar2'][instr] = 0
            self.df['bar3'][instr] = 0
            self.df['bar4'][instr] = 0
            self.df['bar5'][instr] = 0
            self.df['total_volumn'][instr] = 0
            self.df['total_size'][instr] = 0
            self.df['average_price'][instr] = 0
            self.df['average_price_once'][instr] = 0
예제 #9
0
import numpy as np
import quant
from quant import *
from quant import chrono
from quant import instr
%matplotlib inline
import matplotlib.pyplot as plt
quant.mustang.load_config("../default.ini")
###########################################################################################################
#获取Instrument
instr1 = instr.Instrument('XSHG_600004')
#定义起始时间
start = chrono.date_to_time(chrono.Date(20150303))
#定义截止时间
stop = chrono.date_to_time(chrono.Date(20150630))
#定义数据类型	
datatype = "Bar_1day"
#取得数据
data1 = data.MarketData(instr1, datatype, start, stop)
#取得从起始时间至截止时间每日收盘价的array  data1.close : type 为np.narray
record = []
# an empty list
# 
# ##########################################################################################################
for i in range(4,len(data1.close)):
    if(data1.close[i] > max(data1.close[i-4:i]) and data1.close[i] > max(data1.close[i+1:i+5])):
        record.append(i) 
# 判断SEP的准则,并记录下每一个符合要求的日期的顺序
for j in record:
    print data1.date[j]
## <type 'numpy.int32'>