def __init__(self,name,now_time="2015-09-30"): # self.share=Share(name) self.yahoo_data=[] self.yahoo_feature=[] self.name=name self.now_time = now_time self.DIR_NAME="../data/" self.C = CsvHandler(self.name,self.now_time)
def setUp(self): self.h1, self.h2, self.h3, self.h4 = XmlHandler(), TxtHandler(), JsonHandler(), CsvHandler() self.h1.set_next(self.h2) self.h2.set_next(self.h3) self.h3.set_next(self.h4) self.files_dict = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/tests/test_data/' self.output_file = self.files_dict + 'result.res' open(self.output_file, 'w').close()
class DataProducer: def __init__(self,name,now_time="2015-09-30"): # self.share=Share(name) self.yahoo_data=[] self.yahoo_feature=[] self.name=name self.now_time = now_time self.DIR_NAME="../data/" self.C = CsvHandler(self.name,self.now_time) #csvをチェック #CsvHandler.get_datai #csvからaggregatorでデータをとってくる(まだ加工前) # target # x_high:最高値の変化量 # x_low:最高値の変化量 # x_vol:取引量 def make_datemap(self,term,k): #何日おきにつくるか print"making datemap csv..." N=1 self.yahoo_data=self.C.get_data(self.name) size=len(self.yahoo_data["aver"]) obj = self.C.read_csv(self.name) g=open(self.DIR_NAME+self.name+"_datemap.csv","w") fieldnames=("Column","Start","End","TargetDay") headers = dict( (n,n) for n in fieldnames ) writer=csv.DictWriter(g,fieldnames) writer.writerow(headers) count = 1 day=k while (day+term)<=size: row="" start = obj[day-k]["Date"] end = obj[day]["Date"] targetday = obj[day+term-1]["Date"] writer.writerow({"Column":count,"Start":start,"End":end,"TargetDay":targetday}) count+=1 day+=N g.close() print 'Saving datemap: DONE' def make_train_data(self,term,k,per): #何日おきにつくるか N=1 self.yahoo_data=self.C.get_data(self.name) print"making trainning data..." size=len(self.yahoo_data["aver"]) col=size-term-k+1 #初期化 最初の時点 self.x_yahoo_data=np.zeros((col,3*(k+1))) self.y_yahoo_data=np.zeros(col) #print len(self.yahoo_data["aver"]),len(self.yahoo_data["low"]),len(self.yahoo_data["high"]) day=k index=0 #targetをつくる term内にper%あがったら1 while (day+term)<=size: maxaver=np.max(self.yahoo_data["aver"][day:day+term]) x_high=list(self.yahoo_data["high"][day-k:day+1]) x_low=list(self.yahoo_data["low"][day-k:day+1]) x_vol=list(self.yahoo_data["vol"][day-k:day+1]) self.x_yahoo_data[index]=x_high+x_low+x_vol self.y_yahoo_data[index]=maxaver/self.yahoo_data["aver"][day]-1 day+=N index+=1 output={"data":self.x_yahoo_data,"target":self.y_yahoo_data} return output def make_pickle(self,Data): filename="../data/"+self.name+".pkl" with open(filename,'wb') as output: six.moves.cPickle.dump(Data,output,-1) print 'Saving pickle: DONE' def plot(self,filename="graph"): plt.plot(self.yahoo_data["aver"]) #plt.show() plt.savefig(filename+".jpg")
def setUp(self): self.CsvHandler = CsvHandler()