Module: YfAsDataframe::Quote
Class Method Summary collapse
-
.included(base) ⇒ Object
built-in Ruby hook for modules.
Instance Method Summary collapse
- #calendar ⇒ Object
-
#info ⇒ Object
(self).
- #initialize_quote ⇒ Object
- #recommendations ⇒ Object (also: #recommendation_summary, #recommendations_summary)
- #sustainability ⇒ Object
- #upgrades_downgrades ⇒ Object
- #valid_modules ⇒ Object
Class Method Details
.included(base) ⇒ Object
built-in Ruby hook for modules
8 9 10 11 12 13 14 15 16 |
# File 'lib/yf_as_dataframe/quote.rb', line 8 def self.included(base) # built-in Ruby hook for modules base.class_eval do original_method = instance_method(:initialize) define_method(:initialize) do |*args, &block| original_method.bind(self).call(*args, &block) initialize_quote # (your module code here) end end end |
Instance Method Details
#calendar ⇒ Object
94 95 96 97 |
# File 'lib/yf_as_dataframe/quote.rb', line 94 def calendar self._fetch_calendar() if @calendar.nil? return @calendar end |
#info ⇒ Object
(self)
31 32 33 34 35 36 37 |
# File 'lib/yf_as_dataframe/quote.rb', line 31 def info #(self) if @info.nil? _fetch_info() #(@proxy) _fetch_complementary() #(@proxy) end return @info end |
#initialize_quote ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/yf_as_dataframe/quote.rb', line 18 def initialize_quote @info = nil @retired_info = nil @sustainability = nil @recommendations = nil @upgrades_downgrades = nil @calendar = nil @already_scraped = false @already_fetched = false @already_fetched_complementary = false end |
#recommendations ⇒ Object Also known as: recommendation_summary, recommendations_summary
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yf_as_dataframe/quote.rb', line 44 def recommendations Polars::Config.set_tbl_rows(-1) if @recommendations.nil? result = _fetch(['recommendationTrend']).parsed_response # Rails.logger.info { "#{__FILE__}:#{__LINE__} result = #{result.inspect}" } # if result.nil? # @recommendations = YfAsDataframe::Utils.empty_df() #Polars::DataFrame() # else begin data = result["quoteSummary"]["result"][0]["recommendationTrend"]["trend"] rescue KeyError, IndexError => e raise YfinDataException(f"Failed to parse json response from Yahoo Finance: #{e.result}") end @recommendations = Polars::DataFrame.new(data) # end end return @recommendations end |
#sustainability ⇒ Object
39 40 41 42 |
# File 'lib/yf_as_dataframe/quote.rb', line 39 def sustainability raise YFNotImplementedError.new('sustainability') if @sustainability.nil? return @sustainability end |
#upgrades_downgrades ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/yf_as_dataframe/quote.rb', line 67 def upgrades_downgrades Polars::Config.set_tbl_rows(-1) if @upgrades_downgrades.nil? result = _fetch(['upgradeDowngradeHistory']).parsed_response # Rails.logger.info { "#{__FILE__}:#{__LINE__} result = #{result.inspect}" } # if result.nil? # @upgrades_downgrades = YfAsDataframe::Utils.empty_df() #Polars::DataFrame() # else begin data = result["quoteSummary"]["result"][0]["upgradeDowngradeHistory"]["history"] raise YfinDataException("No upgrade/downgrade history found for #{ticker.symbol}") if (data).length.zero? df = Polars::DataFrame.new(data) df.rename({"epochGradeDate" => "GradeDate", 'firm' => 'Firm', 'toGrade' => 'ToGrade', 'fromGrade' => 'FromGrade', 'action' => 'Action'}) # df.set_index('GradeDate', inplace=true) # df.index = pd.to_datetime(df.index, unit='s') @upgrades_downgrades = df rescue KeyError, IndexError => e raise YfinDataException("Failed to parse json response from Yahoo Finance: #{e.result}") end # end end return @upgrades_downgrades end |
#valid_modules ⇒ Object
99 100 101 |
# File 'lib/yf_as_dataframe/quote.rb', line 99 def valid_modules() return QUOTE_SUMMARY_VALID_MODULES end |