def EWMA(self, stk_id): p = Profiler() self.log.info(p.startLog("stk_id: {}", stk_id)) last_quote_obj = self.gdo.Get_Last_EWMA(stk_id) Ay = last_quote_obj["A"] lambdaa = 0.06 ls = self.gdo.Get_Noncalcute_EWMA(stk_id) for obj in ls: r = obj["updown_limit"] Ai = round(pow(r, 2) * lambdaa + Ay * (1-lambdaa), 2) ewma = round(pow(Ai*250, 0.5), 2) self.gdo.updateEWMA(stk_id, obj["q_date"], Ai, ewma) self.log.info(p.endLog("stk_id: {}", stk_id))
def Get_Stock(self, stk_id=None): p = Profiler() #self.log.info("[START] {cname}.Get_Stock(), stk_id: {stk_id}".format(cname = type(self).__name__, stk_id = stk_id)) self.log.info(p.startLog("stk_id: {}", stk_id)) sql = "select distinct a.* from TW_STOCK_LIST a left join tw_stock_quote b on a.STOCK_ID = b.stk_id where a.DELISTING_DATE is null " if stk_id is not None: sql = sql + (" and a.STOCK_ID = " + stk_id) self.log.debug("exec sql statement: {sql}".format(sql=sql)) session = self.sessionFactory.GetSession() stk_list = session.execute(sql) session.close() #self.log.info("[END] {cname}.Get_Stock(), exec TIME: {t} ms., stk_no: {sn}".format(cname = type(self).__name__, t = p.executeTime(), sn = stk_id)) self.log.info(p.endLog("stk_id: {}", stk_id)) return stk_list
def Save_Daily_Exchange(self, a, b, c, d, e, f, g, h, i, j): p = Profiler() self.log.info( p.startLog( "商品代碼: {}, 交易日期: {}, 券商代碼: {}, 券商名稱: {}, 買量: {}, 賣量: {}, 買價: {}, 賣價: {}, 買賣超: {}, 均價: {}", a, b, c, d, e, f, g, h, i, j)) sql = "insert into tw_stock_daily_exchange (stk_id, date, company_id, company_name, buy_quantity, sell_quantity, buy_price, sell_price, over_quantity, avg_price) values ('{a}', '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}')" sql = sql.format(a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h, i=i, j=j) session = self.sessionFactory.GetSession() session.execute(sql) session.commit() session.close() self.log.info( p.endLog( "商品代碼: {}, 交易日期: {}, 券商代碼: {}, 券商名稱: {}, 買量: {}, 賣量: {}, 買價: {}, 賣價: {}, 買賣超: {}, 均價: {}", a, b, c, d, e, f, g, h, i, j)) pass
def Calcute_UpDown(self, stk_id): p = Profiler() #self.log.info("[START] {cn}.Calcute_UpDown(), stk_id: {id}".format(cn = type(self).__name__, id = stk_id)) self.log.info(p.startLog("stk_id: {}", stk_id)) #取出未計算漲跌的資料 ls = self.gdo.Get_Uncalcute_Updown(stk_id) #取出最後一筆有計算漲跌的資料 updownObj = self.gdo.Get_Last_Updown(stk_id) close = updownObj["close"] for obj in ls: distance = obj["close"] - close updown = distance updown_limit = round((distance / close) * 100, 2) self.log.debug("stk_id: {id}, q_date: {qd}, updown: {upd}, updown_limit: {updl}".format(id = stk_id, qd = obj["q_date"], upd = updown, updl = updown_limit)) self.gdo.update_updown_value( stk_id = stk_id, q_date = obj["q_date"].strftime("%Y-%m-%d"), updown = updown, updown_limit = updown_limit ) close = obj["close"] self.log.info(p.endLog("stk_id: {}", stk_id))