コード例 #1
0
 def find_recent_trade_day(self, dat):
     days = StockData.mgr().get_trade_day(self._sp_start.strftime('%Y-%m-%d'),self._sp_end.strftime('%Y-%m-%d'))[:]
     trade_days = [i['Date'].date() for i in days]
     if dat in trade_days:
         return dat
     else:
         return trade_days[-1]    
コード例 #2
0
 def generate_stock_list(self):
     sc_type = self._stock_condition.get_stock_condition_type()
     sc_term = self._stock_condition.get_stock_condition_term()
     if sc_type == 'condition':
         res = []
         date = sc_term['date']
         conditions = sc_term['condition']
         date = self.find_recent_trade_day(date)
         stock_list = StockData.mgr().generate_stock_list_by_condition(date,conditions)[:]
         for i in stock_list:
             res.append(StockInfo(i))
         return res
     elif sc_type == 'total':
         print sc_type
     elif sc_type == 'stocks':
         res = []
         stock_list = sc_term
         for i in stock_list:
             res.append(StockInfo(i))
         return res
コード例 #3
0
ファイル: position.py プロジェクト: appleface2050/pyquant
 def merge_trade(self, trade):
     m = re.match(r'^(\w+):(\w+)', trade.get_price())
     if m:
         date_order = m.group(1)
         p_order = m.group(2)
         #return m.group(2)
         if date_order == 'today':
             start = trade.get_deal_time()
             #print StockData.mgr().get_one_day_price(start,trade.get_stock_code(),trade.get_stock_exch(),p_order)
             #print start,trade.get_stock_code(),trade.get_stock_exch(),p_order
             try:
                 price = StockData.mgr().get_one_day_price(start,trade.get_stock_code(),trade.get_stock_exch(),p_order)[0]['Close']
                 trade.set_price(price)
                 return trade
             except Exception, e:
                 print e
                 print "may be this day mysql don't have data",start,trade.get_stock_code(),trade.get_stock_exch(),p_order
                 return False
             
         else:
             print "error, date_order not defined"
コード例 #4
0
 def generate_stock_list(self):
     sc_type = self._stock_condition.get_stock_condition_type()
     sc_term = self._stock_condition.get_stock_condition_term()
     if sc_type == 'condition':
         res = []
         date = sc_term['date']
         conditions = sc_term['condition']
         date = self.find_recent_trade_day(date)
         stock_list = StockData.mgr().generate_stock_list_by_condition(
             date, conditions)[:]
         for i in stock_list:
             res.append(StockInfo(i))
         return res
     elif sc_type == 'total':
         print sc_type
     elif sc_type == 'stocks':
         res = []
         stock_list = sc_term
         for i in stock_list:
             res.append(StockInfo(i))
         return res
コード例 #5
0
ファイル: stock.py プロジェクト: appleface2050/pyquant
 def get_last_exist_close_price(self, dat):
     q = StockData.mgr().get_one_day_price(dat,self.get_stockinfo_code(),self.get_stockinfo_exch(),'close')[:]
     if not q:
         q = StockData.mgr().get_interval_day_price(dat,self.get_stockinfo_code(),self.get_stockinfo_exch(),'close') # find the last exist close price
     return q[0]['close']
コード例 #6
0
ファイル: stock.py プロジェクト: appleface2050/pyquant
 def __init__(self, stock, start, end):
     self._stock = stock
     self._stock_data = {'stock_info':self._stock}
     q = StockData.mgr().get_stock_data_from_db(self._stock_data['stock_info'].get_stockinfo_code(),self._stock_data['stock_info'].get_stockinfo_exch(),start,end)[:]
     self._stock_data['stock_chart'] = q
コード例 #7
0
ファイル: alpha.py プロジェクト: appleface2050/pyquant
 def find_trade_day(self):
     days = StockData.mgr().get_trade_day(self._sim_start.strftime('%Y-%m-%d'),self._sim_end.strftime('%Y-%m-%d'))[:]
     return [i['Date'].date() for i in days]