Class: EarningsEstimates

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

Constant Summary collapse

MAX_REVISION_SCORE =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticker) ⇒ EarningsEstimates

Returns a new instance of EarningsEstimates.



20
21
22
23
24
# File 'lib/earnings_estimates.rb', line 20

def initialize(ticker)
  @ticker = ticker
  @estimates = {}
  @analysis = {}
end

Instance Attribute Details

#analysisObject

TODO: Analyze spread between high and low estimate



17
18
19
# File 'lib/earnings_estimates.rb', line 17

def analysis
  @analysis
end

#estimatesObject

TODO: Analyze spread between high and low estimate



17
18
19
# File 'lib/earnings_estimates.rb', line 17

def estimates
  @estimates
end

#tickerObject

TODO: Analyze spread between high and low estimate



17
18
19
# File 'lib/earnings_estimates.rb', line 17

def ticker
  @ticker
end

Instance Method Details

#analyzeObject

Analyzes earnings data and gives the security a score. Score is based on:

  • % of times beating estimates

  • % by which estimates were beat

  • Bonus for upward revisions:

  • 4 points for 7 days

  • 3 points for 30 days

  • 2 points for 60 days

  • 1 point for 90 days

Max score is 40



36
37
38
39
40
41
42
43
44
# File 'lib/earnings_estimates.rb', line 36

def analyze
  percentages = percentages_to_f
  @analysis = {
    :average_beating_percentage => average_percent_beating(percentages),
    :beats                      => times_beating_estimates(percentages),
    :revision_points            => revision_score,
    :recently_revised           => nearest_quarters_upward_revised_recently?
  }
end

#fetch_earnings_dataObject

Retrieves earnings data. Current source is MSN Money. Result is stored in @estimates.



47
48
49
50
51
52
53
54
55
# File 'lib/earnings_estimates.rb', line 47

def fetch_earnings_data
  threads = []
  analysts_covering, earnings_surprise, eps_trend = nil, nil, nil
  threads << Thread.new { analysts_covering = parse_earnings_table("http://moneycentral.msn.com/investor/invsub/analyst/earnest.asp?Symbol=#{@ticker}") }
  threads << Thread.new { earnings_surprise = parse_earnings_table("http://moneycentral.msn.com/investor/invsub/analyst/earnest.asp?Page=EarningsSurprise&Symbol=#{@ticker}") }
  threads << Thread.new { eps_trend = parse_earnings_table("http://moneycentral.msn.com/investor/invsub/analyst/earnest.asp?Page=ConsensusEPSTrend&Symbol=#{@ticker}") }
  threads.each { |t| t.join }
  @estimates[:analysts_covering], @estimates[:earnings_surprise], @estimates[:eps_trend] = analysts_covering, earnings_surprise, eps_trend
end