Beispiel #1
0
	def __init__(self):
		input_file_path = "input/PriceVolume/bench_mark.xlsx"

		bench_mark_list,self.bench_mark_name_list = self.load_bench_mark_data(input_file_path)

		#bench_mark_list = ["000016.SH","000001.SH","000300.SH","399006.SZ","399905.SZ"]
		#self.bench_mark_name_list = [u"上证50",u"上证综指",u"沪深300",u"创业板指",u"中证500"]
		#bench_mark_list = ["0806.HK","QIHU.N"]
		#self.bench_mark_name_list = [u"惠理",u"奇虎"]
		stock_data_list = LoadData.get_daily_stock_data(bench_mark_list,"20110101")
		self.price_index = 4
		self.volume_index = 5 

		self.trade_cost = 1-0.001
		self.range_day = 1
		self.regression_day = [2,5]
		
		# short flag = 1 表示可以做空
		short_flag = 1
		
		self.price_list = []
		self.volume_list = []

		for ii in range(len(bench_mark_list)):
			self.price_list.append(list(zip(*stock_data_list[ii])[self.price_index]))
			self.volume_list.append(list(zip(*stock_data_list[ii])[self.volume_index]))

		self.plot(self.price_list,bench_mark_list,self.range_day,short_flag)

		#self.run(bench_mark_list)

		print "done\n"
	def __init__(self):
		file_path = "input/HighLowPoint/user_data.xlsx"

		stock_code_list,stock_name_list,stock_buy_price_list,stock_sell_price_list = LoadUserData.load_user_data(file_path)
		stock_daily_data_list = LoadData.get_daily_stock_data(stock_code_list)
		self.fall_end_flag = []
		self.rise_end_flag = []

		print "begin running\n"
		self.run(stock_code_list,stock_buy_price_list,stock_sell_price_list)
Beispiel #3
0
    def __init__(self):
        file_path = "input/HighLowPoint/user_data.xlsx"

        stock_code_list, stock_name_list, stock_buy_price_list, stock_sell_price_list = LoadUserData.load_user_data(
            file_path)
        stock_daily_data_list = LoadData.get_daily_stock_data(stock_code_list)
        self.fall_end_flag = []
        self.rise_end_flag = []

        print "begin running\n"
        self.run(stock_code_list, stock_buy_price_list, stock_sell_price_list)
Beispiel #4
0
    def get_high_low_points(self, stock_code_list):
        msg = '''<html> <tr>Trend inverse reminder from H&L Model</tr> <table width="300" border="1" bordercolor="black" cellspacing="1">'''
        bar_size = [5, 30, 60]
        column_num = [5, 9, 13]
        threshold = [0.03, 0.05, 0.15]
        send_email_flag = False
        for ii in range(len(bar_size)):
            if bar_size[ii] == 60:
                stock_intraday_data = LoadData.get_daily_stock_data(
                    stock_code_list, "20100101")
                msg = msg + ''' <tr><td rowspan="2">''' + ''' daily </td>'''
            else:
                stock_intraday_data = LoadData.get_intraday_stock_data(
                    stock_code_list, bar_size=bar_size[ii], delta_days=365)
                msg = msg + ''' <tr><td rowspan="2">''' + str(
                    bar_size[ii]) + ''' min </td>'''
            high_point_index_list, high_point_list, high_point_time_list, low_point_index_list, low_point_list, low_point_time_list = HighLowPoint.get_high_low_points_list(
                stock_intraday_data, threshold[ii])

            fall_end_list = []
            rise_end_lsit = []
            fall_end_msg = ""
            rise_end_msg = ""
            for jj in range(len(stock_code_list)):

                self.write_data_to_file(column_num[ii], jj,
                                        high_point_list[jj][-1],
                                        high_point_time_list[jj][-1],
                                        low_point_list[jj][-1],
                                        low_point_time_list[jj][-1])

                temp_msg_fall_end, temp_msg_rise_end = self.judge_trend_inverse(
                    high_point_list[jj], low_point_list[jj],
                    self.current_price[jj])

                if temp_msg_fall_end == True:
                    fall_end_list.append(stock_code_list[jj])
                    send_email_flag = True
                if temp_msg_rise_end == True:
                    rise_end_lsit.append(stock_code_list[jj])
                    send_email_flag = True
            for item in fall_end_list:
                fall_end_msg = fall_end_msg + item + " "
            for item in rise_end_lsit:
                rise_end_msg = rise_end_msg + item + " "

            msg = msg + "<td>" + "Falling End" + "</td><td>" + fall_end_msg + "</td></tr><tr><td> Rising End </td><td>" + rise_end_msg + "</td></tr> \n"
        msg = msg + " </table></html>"
        print msg
        if send_email_flag == True:
            a = SendEmail.Send_Email("Trend inverse reminder from H&L Model",
                                     msg)
            print a.isSend
Beispiel #5
0
    def __init__(self,
                 ma_days=200,
                 start_date="19950101",
                 init_days=60,
                 short_flag=0):

        input_file_path = "../input/DeviationFromMA/user_data.xlsx"
        self.user_stock_code_list, self.user_stock_name_list = self.load_excel(
            input_file_path)
        self.user_stock_data_list = LoadData.get_daily_stock_data(
            self.user_stock_code_list, start_date)
        self.short_flag = short_flag
        self.trade_cost = 1 - 0.001
        self.ma_days = ma_days
        self.user_stock_price_data_list = []
        self.user_stock_uniform_price_list = []
        self.user_stock_datetime_list = []
        self.user_stock_price_data_old_list = []
        for ii in range(len(self.user_stock_code_list)):
            self.user_stock_price_data_list.append(
                (list(zip(*self.user_stock_data_list[ii])[4]))[init_days:])
            self.user_stock_price_data_old_list.append(
                list(zip(*self.user_stock_data_list[ii])[4]))
            self.user_stock_datetime_list.append(
                (list(zip(*self.user_stock_data_list[ii])[0]))[init_days:])
            self.user_stock_uniform_price_list.append(
                CalcIndex.Uniform_Price(self.user_stock_price_data_list[ii]))

        self.price_ma_list = CalcIndex.Calc_MA(
            self.user_stock_price_data_old_list, int(ma_days), int(init_days))

        self.diviation_from_ma_list, self.diviation_from_ma_std_list = self.calc_diviation_from_ma(
            ma_days)

        self.ma_dict = {60: 10, 120: 20, 200: 60, 250: 60}

        self.diviation_ma_list = CalcIndex.Calc_MA(self.diviation_from_ma_list,
                                                   self.ma_dict[self.ma_days])

        #self.plot(ma_days)
        #self.eveluate_index(ma_days)

        long_stand_deviation = {60: -0.5, 120: -0.1, 200: -0.15, 250: -0.2}
        short_stand_deviation = {60: 0.5, 120: 0.1, 200: 0.15, 250: 0.2}

        self.back_test_info = self.back_test(long_stand_deviation[ma_days],
                                             short_stand_deviation[ma_days])
        self.plot_back_test(ma_days)

        print "done."
	def __init__(self):
		file_path = "input/user_data.xlsx"
		self.user_stock_code_list,self.user_stock_name_list,user_stock_buy_point_list,user_stock_sell_point_list = LoadUserData.load_user_data(file_path)

		self.daily_stock_data_all = LoadData.get_daily_stock_data(self.user_stock_code_list,"20150101")
		#存放收盘价
		self.daily_stock_data = []

		for ii in range(len(self.daily_stock_data_all)):
			temp = []
			for jj in range(len(self.daily_stock_data_all[ii])):
				temp.append(self.daily_stock_data_all[ii][jj][4])
			self.daily_stock_data.append(temp)
		#print self.daily_stock_data[0][-1],self.daily_stock_data[1][-1]
		self.reminder_info= []
		self.run()
Beispiel #7
0
    def __init__(self):
        file_path = "input/user_data.xlsx"
        self.user_stock_code_list, self.user_stock_name_list, user_stock_buy_point_list, user_stock_sell_point_list = LoadUserData.load_user_data(
            file_path)

        self.daily_stock_data_all = LoadData.get_daily_stock_data(
            self.user_stock_code_list, "20150101")
        #存放收盘价
        self.daily_stock_data = []

        for ii in range(len(self.daily_stock_data_all)):
            temp = []
            for jj in range(len(self.daily_stock_data_all[ii])):
                temp.append(self.daily_stock_data_all[ii][jj][4])
            self.daily_stock_data.append(temp)
        #print self.daily_stock_data[0][-1],self.daily_stock_data[1][-1]
        self.reminder_info = []
        self.run()
	def get_high_low_points(self,stock_code_list):
		msg = '''<html> <tr>Trend inverse reminder from H&L Model</tr> <table width="300" border="1" bordercolor="black" cellspacing="1">'''
		bar_size = [5,30,60]
		column_num = [5,9,13]
		threshold = [0.03,0.05,0.15]
		send_email_flag = False
		for ii in range(len(bar_size)):
			if bar_size[ii]==60:
				stock_intraday_data = LoadData.get_daily_stock_data(stock_code_list,"20100101")
				msg = msg +''' <tr><td rowspan="2">'''  + ''' daily </td>'''
			else:
				stock_intraday_data = LoadData.get_intraday_stock_data(stock_code_list,bar_size=bar_size[ii],delta_days = 365)
				msg = msg +''' <tr><td rowspan="2">''' +str(bar_size[ii]) + ''' min </td>'''
			high_point_index_list,high_point_list,high_point_time_list,low_point_index_list,low_point_list,low_point_time_list = HighLowPoint.get_high_low_points_list(stock_intraday_data,threshold[ii])
			
			
			fall_end_list = []
			rise_end_lsit = []
			fall_end_msg = ""
			rise_end_msg = ""
			for jj in range(len(stock_code_list)):

				self.write_data_to_file(column_num[ii],jj,high_point_list[jj][-1],high_point_time_list[jj][-1],low_point_list[jj][-1],low_point_time_list[jj][-1])
				
				temp_msg_fall_end, temp_msg_rise_end = self.judge_trend_inverse(high_point_list[jj],low_point_list[jj],self.current_price[jj]) 

				if temp_msg_fall_end ==True:
					fall_end_list.append(stock_code_list[jj])
					send_email_flag = True
				if temp_msg_rise_end == True:
					rise_end_lsit.append(stock_code_list[jj])
					send_email_flag = True
			for item in fall_end_list:
				fall_end_msg = fall_end_msg + item + " "
			for item in rise_end_lsit:
				rise_end_msg = rise_end_msg + item +" "

			msg = msg +"<td>" + "Falling End" + "</td><td>"+fall_end_msg +"</td></tr><tr><td> Rising End </td><td>"+rise_end_msg+"</td></tr> \n"
		msg = msg +" </table></html>"
		print msg
		if send_email_flag == True:
			a = SendEmail.Send_Email("Trend inverse reminder from H&L Model",msg)
			print a.isSend
    def __init__(self):
        input_file_path = "input/PriceVolume/bench_mark.xlsx"

        bench_mark_list, self.bench_mark_name_list = self.load_bench_mark_data(
            input_file_path)

        #bench_mark_list = ["000016.SH","000001.SH","000300.SH","399006.SZ","399905.SZ"]
        #self.bench_mark_name_list = [u"上证50",u"上证综指",u"沪深300",u"创业板指",u"中证500"]
        #bench_mark_list = ["0806.HK","QIHU.N"]
        #self.bench_mark_name_list = [u"惠理",u"奇虎"]
        stock_data_list = LoadData.get_daily_stock_data(
            bench_mark_list, "20110101")
        self.price_index = 4
        self.volume_index = 5

        self.trade_cost = 1 - 0.001
        self.range_day = 1
        self.regression_day = [2, 5]

        # short flag = 1 表示可以做空
        short_flag = 1

        self.price_list = []
        self.volume_list = []

        for ii in range(len(bench_mark_list)):
            self.price_list.append(
                list(zip(*stock_data_list[ii])[self.price_index]))
            self.volume_list.append(
                list(zip(*stock_data_list[ii])[self.volume_index]))

        self.plot(self.price_list, bench_mark_list, self.range_day, short_flag)

        #self.run(bench_mark_list)

        print "done\n"
	def __init__(self,ma_days=200,start_date="19950101",init_days = 60,short_flag =0):
		
		input_file_path = "../input/DeviationFromMA/user_data.xlsx"
		self.user_stock_code_list,self.user_stock_name_list = self.load_excel(input_file_path)
		self.user_stock_data_list = LoadData.get_daily_stock_data(self.user_stock_code_list,start_date)
		self.short_flag = short_flag
		self.trade_cost = 1-0.001
		self.ma_days = ma_days
		self.user_stock_price_data_list = []
		self.user_stock_uniform_price_list =[]
		self.user_stock_datetime_list = []
		self.user_stock_price_data_old_list =[]
		for ii in range(len(self.user_stock_code_list)):
			self.user_stock_price_data_list.append((list(zip(*self.user_stock_data_list[ii])[4]))[init_days:])
			self.user_stock_price_data_old_list.append(list(zip(*self.user_stock_data_list[ii])[4]))
			self.user_stock_datetime_list.append((list(zip(*self.user_stock_data_list[ii])[0]))[init_days:])
			self.user_stock_uniform_price_list.append(CalcIndex.Uniform_Price(self.user_stock_price_data_list[ii]))

		self.price_ma_list = CalcIndex.Calc_MA(self.user_stock_price_data_old_list,int(ma_days),int(init_days))

		self.diviation_from_ma_list,self.diviation_from_ma_std_list = self.calc_diviation_from_ma(ma_days)

		self.ma_dict ={60:10,120:20,200:60,250:60}
		
		self.diviation_ma_list = CalcIndex.Calc_MA(self.diviation_from_ma_list,self.ma_dict[self.ma_days])

		#self.plot(ma_days)
		#self.eveluate_index(ma_days)

		long_stand_deviation = {60:-0.5,120:-0.1,200:-0.15,250:-0.2}
		short_stand_deviation = {60:0.5,120:0.1,200:0.15,250:0.2}

		self.back_test_info = self.back_test(long_stand_deviation[ma_days],short_stand_deviation[ma_days])
		self.plot_back_test(ma_days)

		print "done."
    def creepy_data_from_wind_to_local(self):

        for ii in range(len(self.user_stock_name_list)):
            self.path_is_exist(self.user_stock_name_list[ii])
            data_base_path = sys.path[0] + "\\" + "data" + "\\" + "data_base"
            stock_fold_path = data_base_path + "\\" + self.user_stock_name_list[ii]

            for data_type in self.data_type_list:

                data_path = stock_fold_path + "\\" + data_type
                latest_date = self.get_latest_date_in_fold(data_path)
                print latest_date
                temp_stock_name = []
                temp_stock_name.append(self.user_stock_name_list[ii])

                delta_day = (
                    datetime.now() - datetime(int(latest_date[0:4]), int(latest_date[4:6]), int(latest_date[6:8]))
                ).days
                print latest_date, delta_day, self.user_stock_name_list[ii]

                pos = self.user_stock_name_list[ii].split(".")[1]
                print pos
                if data_type == "daily":

                    stock_daily_data = LoadData.get_daily_stock_data(temp_stock_name, latest_date)
                    for jj in range(len(stock_daily_data[0])):

                        output_data_path = data_path + "\\" + stock_daily_data[0][jj][0] + ".txt"
                        WriteToFile.write_to_file(output_data_path, stock_daily_data[0][jj])

                if pos != "SZ" and pos != "SH":
                    break

                if float(delta_day) > 3 * 365:
                    delta_day = 1095
                if data_type == "60min":
                    print "aaa"

                    stock_60_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=60, delta_days=delta_day
                    )
                    date_60_min_index = self.get_day_sperate_index(stock_60_min_data)
                    print stock_60_min_data
                    print date_60_min_index

                    for jj in range(len(date_60_min_index) - 1):
                        file_path = data_path + "\\" + stock_60_min_data[0][date_60_min_index[jj]][0][0:8] + ".txt"
                        WriteToFile.write_list_to_file(
                            file_path, stock_60_min_data[0][date_60_min_index[jj] : date_60_min_index[jj + 1]]
                        )

                elif data_type == "30min":
                    stock_30_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=30, delta_days=delta_day
                    )
                    date_30_min_index = self.get_day_sperate_index(stock_30_min_data)

                    for jj in range(len(date_30_min_index) - 1):
                        file_path = data_path + "\\" + stock_30_min_data[0][date_30_min_index[jj]][0][0:8] + ".txt"
                        WriteToFile.write_list_to_file(
                            file_path, stock_30_min_data[0][date_30_min_index[jj] : date_30_min_index[jj + 1]]
                        )
                elif data_type == "15min":
                    stock_15_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=15, delta_days=delta_day
                    )
                    date_15_min_index = self.get_day_sperate_index(stock_15_min_data)

                    for jj in range(len(date_15_min_index) - 1):
                        file_path = data_path + "\\" + stock_15_min_data[0][date_15_min_index[jj]][0][0:8] + ".txt"
                        WriteToFile.write_list_to_file(
                            file_path, stock_15_min_data[0][date_15_min_index[jj] : date_15_min_index[jj + 1]]
                        )

                elif data_type == "5min":
                    stock_5_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=5, delta_days=delta_day
                    )
                    date_5_min_index = self.get_day_sperate_index(stock_5_min_data)

                    for jj in range(len(date_5_min_index) - 1):
                        file_path = data_path + "\\" + stock_5_min_data[0][date_5_min_index[jj]][0][0:8] + ".txt"

                        WriteToFile.write_list_to_file(
                            file_path, stock_5_min_data[0][date_5_min_index[jj] : date_5_min_index[jj + 1]]
                        )
    def creepy_data_from_wind_to_local(self):

        for ii in range(len(self.user_stock_name_list)):
            self.path_is_exist(self.user_stock_name_list[ii])
            data_base_path = sys.path[0] + "\\" + "data" + "\\" + "data_base"
            stock_fold_path = data_base_path + "\\" + self.user_stock_name_list[
                ii]

            for data_type in self.data_type_list:

                data_path = stock_fold_path + "\\" + data_type
                latest_date = self.get_latest_date_in_fold(data_path)
                print latest_date
                temp_stock_name = []
                temp_stock_name.append(self.user_stock_name_list[ii])

                delta_day = (
                    datetime.now() -
                    datetime(int(latest_date[0:4]), int(latest_date[4:6]),
                             int(latest_date[6:8]))).days
                print latest_date, delta_day, self.user_stock_name_list[ii]

                pos = self.user_stock_name_list[ii].split(".")[1]
                print pos
                if data_type == "daily":

                    stock_daily_data = LoadData.get_daily_stock_data(
                        temp_stock_name, latest_date)
                    for jj in range(len(stock_daily_data[0])):

                        output_data_path = data_path + "\\" + stock_daily_data[
                            0][jj][0] + ".txt"
                        WriteToFile.write_to_file(output_data_path,
                                                  stock_daily_data[0][jj])

                if pos != "SZ" and pos != "SH":
                    break

                if float(delta_day) > 3 * 365:
                    delta_day = 1095
                if data_type == "60min":
                    print "aaa"

                    stock_60_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=60, delta_days=delta_day)
                    date_60_min_index = self.get_day_sperate_index(
                        stock_60_min_data)
                    print stock_60_min_data
                    print date_60_min_index

                    for jj in range(len(date_60_min_index) - 1):
                        file_path = data_path + "\\" + stock_60_min_data[0][
                            date_60_min_index[jj]][0][0:8] + ".txt"
                        WriteToFile.write_list_to_file(
                            file_path, stock_60_min_data[0]
                            [date_60_min_index[jj]:date_60_min_index[jj + 1]])

                elif data_type == "30min":
                    stock_30_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=30, delta_days=delta_day)
                    date_30_min_index = self.get_day_sperate_index(
                        stock_30_min_data)

                    for jj in range(len(date_30_min_index) - 1):
                        file_path = data_path + "\\" + stock_30_min_data[0][
                            date_30_min_index[jj]][0][0:8] + ".txt"
                        WriteToFile.write_list_to_file(
                            file_path, stock_30_min_data[0]
                            [date_30_min_index[jj]:date_30_min_index[jj + 1]])
                elif data_type == "15min":
                    stock_15_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=15, delta_days=delta_day)
                    date_15_min_index = self.get_day_sperate_index(
                        stock_15_min_data)

                    for jj in range(len(date_15_min_index) - 1):
                        file_path = data_path + "\\" + stock_15_min_data[0][
                            date_15_min_index[jj]][0][0:8] + ".txt"
                        WriteToFile.write_list_to_file(
                            file_path, stock_15_min_data[0]
                            [date_15_min_index[jj]:date_15_min_index[jj + 1]])

                elif data_type == "5min":
                    stock_5_min_data = LoadData.get_intraday_stock_data(
                        temp_stock_name, bar_size=5, delta_days=delta_day)
                    date_5_min_index = self.get_day_sperate_index(
                        stock_5_min_data)

                    for jj in range(len(date_5_min_index) - 1):
                        file_path = data_path + "\\" + stock_5_min_data[0][
                            date_5_min_index[jj]][0][0:8] + ".txt"

                        WriteToFile.write_list_to_file(
                            file_path, stock_5_min_data[0]
                            [date_5_min_index[jj]:date_5_min_index[jj + 1]])
Beispiel #13
0
# -*- coding: utf-8 -*-
# File Name: main.py
# Author: Changsheng Zhang
# mail: [email protected]
# Created Time: Tue Jul  7 10:09:08 2015

#########################################################################

import os
import sys
import strategy.test as test
import data.LoadData as LoadData
if __name__ == '__main__':
	
	b = LoadData.get_daily_stock_data(["600000.SH"])
	print b[0][0]