def get_latest_exchange_rates(f): currencies = ["RMB", "USD"] res = { "HKD" : 1 } for currency in currencies: recs = records.get_records(f, currency) res[currency] = float(recs[-1][2]) return res
def check_button_clicked(self, widget, data=None): records_list = get_records() #print records_list self.running = False time = str(datetime.datetime.now() - self.start_time) self.time_label.set_text(time) self.start_button.set_sensitive(True) self.check_button.set_sensitive(False) lst = self.collect_words() i = 0 for word in lst: #print check_word(word) if check_word(word): self.score += len(word) self.score_label.set_text(str(self.score)) self.icons[i].clear() self.icons[i].set_from_stock(gtk.STOCK_SPELL_CHECK, gtk.ICON_SIZE_BUTTON) self.icons[i].queue_draw() while (gtk.events_pending()): gtk.main_iteration() else: self.icons[i].clear() self.icons[i].set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) self.icons[i].queue_draw() while (gtk.events_pending()): gtk.main_iteration() i += 1 utf_syll = self.syll[0].decode('utf-8') + self.syll[1].decode('utf-8') add_record(self.score, utf_syll, "None", time)
def get_latest_ratings(f, code): recs = records.get_records(f, str(code)) recs = [ r for r in recs if datetime.fromtimestamp(r[1]) <= ref_date ] if len(recs) < 1: return None ratings = batch.Ratings(buy_analysts=int(recs[-1][2]), outperform_analysts=int(recs[-1][3]), hold_analysts=int(recs[-1][4]), underperform_analysts=int(recs[-1][5]), sell_analysts=int(recs[-1][6]), target_high=float(recs[-1][7]), target_low=float(recs[-1][8]), target_median=float(recs[-1][9]), target=float(recs[-1][10])) return ratings
def check_button_clicked(self, widget, data=None): records_list = get_records() #print records_list self.running = False time = str(datetime.datetime.now()-self.start_time) self.time_label.set_text(time) self.start_button.set_sensitive(True) self.check_button.set_sensitive(False) lst = self.collect_words() i = 0 for word in lst: #print check_word(word) if check_word(word): self.score += len(word) self.score_label.set_text(str(self.score)) self.icons[i].clear() self.icons[i].set_from_stock(gtk.STOCK_SPELL_CHECK, gtk.ICON_SIZE_BUTTON) self.icons[i].queue_draw() while (gtk.events_pending ()): gtk.main_iteration (); else: self.icons[i].clear() self.icons[i].set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) self.icons[i].queue_draw() while (gtk.events_pending ()): gtk.main_iteration (); i+=1 utf_syll = self.syll[0].decode('utf-8')+self.syll[1].decode('utf-8') add_record(self.score, utf_syll, "None", time)
def get_latest_forecasts(f, code): recs = records.get_records(f, str(code)) recs = [ r for r in recs if datetime.fromtimestamp(r[1]) <= ref_date ] forecasts = {} if len(recs) < 1: return forecasts for r in recs: raw_key = r[0].split("|") key = batch.CompoundKey(code=int(raw_key[0]), financial_year=int(raw_key[1]), financial_period=raw_key[2]) if key not in forecasts: forecasts[key] = batch.ForecastedFundamentals(revenue_analysts=int(r[2]), revenue_high=float(r[3]), revenue_low=float(r[4]), revenue=float(r[5]), eps_analysts=int(r[6]), eps_high=float(r[7]), eps_low=float(r[8]), eps=float(r[9]), dps=float(r[10])) return forecasts
def get_latest_fundamentals(f, code): recs = records.get_records(f, str(code)) recs = [ r for r in recs if datetime.fromtimestamp(r[1]) <= ref_date ] fundamentals = {} if len(recs) < 1: return {} # for r in recs: raw_key = r[0].split("|") key = batch.CompoundKey(code=int(raw_key[0]), financial_year=int(raw_key[1]), financial_period=raw_key[2]) if key not in fundamentals: fundamentals[key] = batch.Fundamentals(financial_period_start=recs[-1][2], financial_period_end=recs[-1][3], reporting_date=recs[-1][4], currency=recs[-1][5], extraordinary_income=float(recs[-1][6]), eps=float(recs[-1][7]), diluted_eps=float(recs[-1][8]), dps=float(recs[-1][9]), sdps=float(recs[-1][10]), cash=float(recs[-1][11]), accounts_receivable=float(recs[-1][12]), inventory=float(recs[-1][13]), current_assets=float(recs[-1][14]), loans=float(recs[-1][15]), ppe=float(recs[-1][16]), intangibles=float(recs[-1][17]), associates=float(recs[-1][18]), noncurrent_assets=float(recs[-1][19]), total_assets=float(recs[-1][20]), accounts_payable=float(recs[-1][21]), bank_debt=float(recs[-1][22]), current_liabilities=float(recs[-1][23]), long_term_debt=float(recs[-1][24]), deposits=float(recs[-1][25]), total_liabilities=float(recs[-1][26]), minority_equity=float(recs[-1][27]), share_capital=float(recs[-1][28]), reserve=float(recs[-1][29]), total_equity=float(recs[-1][30]), interest_revenue=float(recs[-1][31]), interest_payout=float(recs[-1][32]), net_interest_revenue=float(recs[-1][33]), other_revenue=float(recs[-1][34]), revenue=float(recs[-1][35]), cogs=float(recs[-1][36]), gross_profit=float(recs[-1][37]), sales_expense=float(recs[-1][38]), general_expense=float(recs[-1][39]), credit_provisions=float(recs[-1][40]), depreciation=float(recs[-1][41]), operating_income=float(recs[-1][42]), associates_operating_income=float(recs[-1][43]), ebit=float(recs[-1][44]), interest_expense=float(recs[-1][45]), ebt=float(recs[-1][46]), tax=float(recs[-1][47]), minority_interest=float(recs[-1][48]), net_income=float(recs[-1][49]), dividend=float(recs[-1][50]), retained_earnings=float(recs[-1][51]), operating_cash_flow=float(recs[-1][52]), capex=float(recs[-1][53]), investing_cash_flow=float(recs[-1][54]), financing_cash_flow=float(recs[-1][55]), fx_translation=float(recs[-1][56])) res = {} latest_period = sorted(fundamentals, key=lambda x: x.financial_year * 4 + financial_period_map[x.financial_period])[-1] res[latest_period] = fundamentals[latest_period] return res
def get_latest_shares(f, code): recs = records.get_records(f, str(code)) recs = [ r for r in recs if datetime.fromtimestamp(r[1]) <= ref_date ] if len(recs) < 1: return 0 return float(recs[-1][2])
def get_latest_sector(f, code): recs = records.get_records(f, str(code)) recs = [ r for r in recs if datetime.fromtimestamp(r[1]) <= ref_date ] if len(recs) < 1: return None return recs[-1][3]
def get_corporate_action_occurrence(f, code, start_date, end_date): recs = records.get_records(f, str(code)) recs = [ r for r in recs if datetime.strftime(datetime.fromtimestamp(r[1]), "%Y%m%d") >= start_date and datetime.strftime(datetime.fromtimestamp(r[1]), "%Y%m%d") <= end_date ] return len(recs) > 0