Class: FinModeling::Company

Inherits:
Object
  • Object
show all
Defined in:
lib/finmodeling/company.rb

Constant Summary collapse

BASE_FILENAME =
File.join(FinModeling::BASE_PATH, "companies/")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ Company

Returns a new instance of Company.



34
35
36
# File 'lib/finmodeling/company.rb', line 34

def initialize(entity)
  @entity = entity
end

Class Method Details

.find(stock_symbol) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/finmodeling/company.rb', line 39

def self.find(stock_symbol)
  filename = BASE_FILENAME + stock_symbol.upcase + ".rb"
  entity = SecQuery::Entity.load(filename)
  return Company.new(entity) if !entity.nil?
  begin
    entity = SecQuery::Entity.find(stock_symbol, { :relationships => false, 
                                                   :transactions  => false, 
                                                   :filings       => true })
                                                   #:filings       => {:start=> 0, :count=>20, :limit=> 20} })
    return nil if !entity
    entity.write_constructor(filename)
    return Company.new(entity)
  rescue Exception => e
    puts "Warning: failed to load entity"
    puts "\t" + e.message
    puts "\t" + e.backtrace.inspect.gsub(/, /, "\n\t ")
    return nil
  end
end

Instance Method Details

#annual_reportsObject



63
64
65
# File 'lib/finmodeling/company.rb', line 63

def annual_reports
  CompanyFilings.new(sorted_reports_of_type("10-K"))
end

#filings_since_date(start_date) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/finmodeling/company.rb', line 71

def filings_since_date(start_date)
  reports  = self.annual_reports
  reports += self.quarterly_reports
  reports.select!{ |report| Time.parse(report.date) >= start_date }
  reports.sort!{ |x, y| Time.parse(x.date) <=> Time.parse(y.date) }

  filings = []
  reports.each do |report|
    begin
      case report.term 
        when "10-Q" then filings << FinModeling::QuarterlyReportFiling.download(report.link)
        when "10-K" then filings << FinModeling::AnnualReportFiling.download(   report.link) 
      end
    rescue Exception => e  
      # *ReportFiling.download() will throw errors if it doesn't contain xbrl data.
      puts "Caught error in FinModeling::(.*)ReportFiling.download:"
      puts "\t" + e.message  
      puts "\t" + e.backtrace.inspect.gsub(/, /, "\n\t ")
    end
  end

  return CompanyFilings.new(filings)
end

#nameObject



59
60
61
# File 'lib/finmodeling/company.rb', line 59

def name
  @entity.name.gsub(/ \(.*/, '')
end

#quarterly_reportsObject



67
68
69
# File 'lib/finmodeling/company.rb', line 67

def quarterly_reports
  CompanyFilings.new(sorted_reports_of_type("10-Q"))
end