Module: Tushare::Stock::Fundamental

Extended by:
Util
Defined in:
lib/tushare/stock/fundamental.rb

Class Method Summary collapse

Methods included from Util

_code_to_symbol, _write_console, _write_head, check_quarter, check_year, fetch_ftp_file, holiday?, trade_cal

Class Method Details

.get_cashflow_data(year, quarter) ⇒ Object

Return


DataFrame

code,


190
191
192
193
194
# File 'lib/tushare/stock/fundamental.rb', line 190

def get_cashflow_data(year, quarter)
  check_year(year)
  check_quarter(quarter)
  get_data(year, quarter, 1, CASHFLOW_COLS, CASHFLOW_URL)
end

.get_data(year, quarter, page, headers, url_format) ⇒ Object



198
199
200
201
202
203
204
205
206
# File 'lib/tushare/stock/fundamental.rb', line 198

def get_data(year, quarter, page, headers, url_format)
  _write_head
  _write_console
  result = []
  result.concat process_data(page, headers, lambda do |p|
    format(url_format, P_TYPE['http'], DOMAINS['vsf'], PAGES['fd'],
           year, quarter, p, PAGE_NUM[1])
  end)
end

.get_debtpaying_data(year, quarter) ⇒ Object

Return


DataFrame

code,


167
168
169
170
171
# File 'lib/tushare/stock/fundamental.rb', line 167

def get_debtpaying_data(year, quarter)
  check_year(year)
  check_quarter(quarter)
  get_data(year, quarter, 1, DEBTPAYING_COLS, DEBTPAYING_URL)
end

.get_growth_data(year, quarter) ⇒ Object

Return


DataFrame

code,


143
144
145
146
147
# File 'lib/tushare/stock/fundamental.rb', line 143

def get_growth_data(year, quarter)
  check_year(year)
  check_quarter(quarter)
  get_data(year, quarter, 1, GROWTH_COLS, GROWTH_URL)
end

.get_operation_data(year, quarter) ⇒ Object

Return


DataFrame

code,


119
120
121
122
123
# File 'lib/tushare/stock/fundamental.rb', line 119

def get_operation_data(year, quarter)
  check_year(year)
  check_quarter(quarter)
  get_data(year, quarter, 1, OPERATION_COLS, OPERATION_URL)
end

.get_profit_data(year, quarter) ⇒ Object

Return


DataFrame

code,


95
96
97
98
99
# File 'lib/tushare/stock/fundamental.rb', line 95

def get_profit_data(year, quarter)
  check_year(year)
  check_quarter(quarter)
  get_data(year, quarter, 1, PROFIT_COLS, PROFIT_URL)
end

.get_report_data(year, quarter) ⇒ Object

获取业绩报表数据Parameters


year:int 年度 e.g:2014 quarter:int 季度 :1、2、3、4,只能输入这4个季度

Return


DataFrame

code,


70
71
72
73
74
# File 'lib/tushare/stock/fundamental.rb', line 70

def get_report_data(year, quarter)
  check_year(year)
  check_quarter(quarter)
  get_data(year, quarter, 1, REPORT_COLS, REPORT_URL)
end

.get_stock_basicsObject

获取沪深上市公司基本情况Return


DataFrame

code,


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tushare/stock/fundamental.rb', line 28

def get_stock_basics
  url = ALL_STOCK_BASICS_FILE
  response = HTTParty.get(url)
  if response.code.to_s == '200'
    table_value = response.body.encode('utf-8', 'gbk')
    table = CSV.new(table_value)
    headers = table.shift
    result = []
    table.each do |row|
      object = {}
      row.each_with_index do |cell, index|
        object[headers[index]] = cell
      end
      result << object
    end
    result
  else
    []
  end
end

.process_data(page, headers, url_generator) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/tushare/stock/fundamental.rb', line 208

def process_data(page, headers, url_generator)
  result = []
  loop do
    url = url_generator.call(page)
    doc = Nokogiri::HTML(open(url), nil, 'gbk')
    doc.css('table.list_table > tr').each do |tr|
      item = {}
      tr.css('td').each_with_index do |td, index|
        item[headers[index]] = td.content if headers[index]
      end
      result << item
    end
    next_page = doc.css('div.pages > a:last').css('a.nolink')
    break unless next_page.empty?
    page += 1
  end
  result
end