stock_financials 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjUzZjVjMWUyMWRiYzZjOTE5ZTMzNDA2ODRjNTYyOTM0MzIwMDdhYw==
5
+ data.tar.gz: !binary |-
6
+ NDliMmE2Nzg1NjhlYmZmNjA5Njg2MTkwMjI4ZDcyZDUzYjQ1YzFjYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTA5OGE0MzEyZjIwZGMxNDUwYzFjMjc2YTAyNDFkOWI5NWRkZWY4M2JkN2Fl
10
+ ZGEwODhjYjI5MmQ1Nzg3Nzc3NWU3NmVhYTI5ZGQ4MGY3NTcyZGYxNWIyZTky
11
+ MjdlOWUxYWEwMTY0MTBlYzI4MDFmZGY0YjdkZmQ3NDdlYWE5NzQ=
12
+ data.tar.gz: !binary |-
13
+ MTRmY2Q3NDAwZGIzOGYxOGUzNjhiZGI4NDRkNTUwOWI2ODliZGIyODgxMGY1
14
+ ODYwYTdiNjg3MzZiM2UxNzUxZDA0YTNiYmI4YzRiNDAyYjA4MjIyYjk1ZmQ0
15
+ YjUwM2UyMTNmNWNkYjc0MDBmNjNhOGNlNmU1Y2VhYWQ2NTA0ZTc=
@@ -0,0 +1,23 @@
1
+ require 'date'
2
+ class BalanceSheet
3
+ attr_accessor :cash_and_cash_equivalents, :total_current_assets, :total_assets, :short_term_debt, :total_current_liabilites, :long_term_debt, :total_liabilities,
4
+ :total_equity, :period
5
+
6
+ def initialize(params)
7
+ @cash_and_cash_equivalents = params["CashAndCashEquivalents"]["content"] if params["CashAndCashEquivalents"]
8
+ @total_current_assets = params["TotalCurrentAssets"]["content"] if params["TotalCurrentAssets"]
9
+ @total_assets = params["TotalAssets"]["content"] if params["TotalAssets"]
10
+ @short_term_debt = params["Short_CurrentLongTermDebt"]["content"] if params["Short_CurrentLongTermDebt"]
11
+ @total_current_liabilites = params["TotalCurrentLiabilities"]["content"] if params["TotalCurrentLiabilities"]
12
+ @long_term_debt = params["LongTermDebt"]["content"] if params["LongTermDebt"]
13
+ @total_liabilities = params["TotalLiabilities"]["content"] if params["TotalLiabilities"]
14
+ @total_equity = params["TotalStockholderEquity"]["content"] if params["TotalStockholderEquity"]
15
+ @period = Date.parse(params["period"])
16
+ end
17
+
18
+ def to_s
19
+ p "#{@period}"
20
+ p "CashAndCashEquivalents: #{@cash_and_cash_equivalents}"
21
+ p "TotalAssets: #{@total_assets}"
22
+ end
23
+ end
data/lib/financials.rb ADDED
@@ -0,0 +1,21 @@
1
+
2
+ class Financials
3
+ attr_accessor :statements, :timeframe, :symbol, :type
4
+
5
+ def initialize(params,type)
6
+ @type = type
7
+ statements = params["statement"]
8
+ @symbol = params["symbol"]
9
+ @timeframe = params["timeframe"]
10
+ @statements = []
11
+ if type == INCOME_STATEMENT
12
+ statements.each { |statement|
13
+ @statements << IncomeStatement.new(statement)
14
+ }
15
+ elsif type == BALANCE_SHEET
16
+ statements.each { |statement|
17
+ @statements << BalanceSheet.new(statement)
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ class IncomeStatement
2
+ attr_accessor :total_revenue,:cost_of_revenue,:gross_profit,
3
+ :total_operating_expenses,:operating_income_or_loss,:ebit,
4
+ :interest_expenses,:income_before_tax,:income_tax_expense,:net_income, :period
5
+ def initialize(params)
6
+ @total_revenue = params["TotalRevenue"]["content"] if params["TotalRevenue"]
7
+ @cost_of_revenue = params["CostofRevenue"]["content"] if params["CostofRevenue"]
8
+ @gross_profit = params["GrossProfit"]["content"] if params["GrossProfit"]
9
+ @total_operating_expenses = params["TotalOperatingExpenses"]["content"] if params["TotalOperatingExpenses"]
10
+ @operating_income_or_loss = params["OperatingIncomeOrLoss"]["content"] if params["OperatingIncomeOrLoss"]
11
+ @ebit = params["EarningsBeforeInterestAndTaxes"]["content"] if params["EarningsBeforeInterestAndTaxes"]
12
+ @interest_expenses = params["InterestExpense"]["content"] if params["InterestExpense"]
13
+ @income_before_tax = params["IncomeBeforeTax"]["content"] if params["IncomeBeforeTax"]
14
+ @income_tax_expense = params["IncomeTaxExpense"]["content"] if params["IncomeTaxExpense"]
15
+ @net_income = params["NetIncome"]["content"] if params["NetIncome"]
16
+ @period = Date.parse(params["period"])
17
+ end
18
+
19
+ def to_s
20
+ p "Total Revenue: #{@total_revenue}"
21
+ p "Cost of Revenue: #{@cost_of_revenue}"
22
+ p "Gross Profit: #{@gross_profit}"
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ require 'yql'
2
+ require 'json'
3
+
4
+ require_relative 'income_statement.rb'
5
+ require_relative 'balance_sheet.rb'
6
+ require_relative 'financials.rb'
7
+
8
+ QUARTERLY_TIME_FRAME = 'quarterly'
9
+ ANNUAL_TIME_FRAME = 'annual'
10
+
11
+ BALANCE_SHEET = "BalanceSheet"
12
+ INCOME_STATEMENT = "IncomeStatement"
13
+
14
+ class StockFinancials
15
+
16
+ def initialize
17
+ @yql = Yql::Client.new
18
+ @yql.format = 'json'
19
+ end
20
+
21
+ def income_statement(stock_symbol, period = QUARTERLY_TIME_FRAME)
22
+ financials = send_query(stock_symbol, period, INCOME_STATEMENT)
23
+ end
24
+
25
+ def balance_sheet(stock_symbol, period = QUARTERLY_TIME_FRAME)
26
+ financials = send_query(stock_symbol, period, BALANCE_SHEET)
27
+ end
28
+
29
+ private
30
+
31
+ def send_query(stock_symbol,period,statement_type)
32
+ query = ""
33
+ if statement_type == INCOME_STATEMENT
34
+ query = Yql::QueryBuilder.new 'yahoo.finance.incomestatement'
35
+ elsif statement_type == BALANCE_SHEET
36
+ query = Yql::QueryBuilder.new 'yahoo.finance.balancesheet'
37
+ end
38
+ query.conditions = "symbol ='#{stock_symbol}' and timeframe='#{period}'"
39
+ @yql.query = query
40
+ response = @yql.get
41
+
42
+ unless response && response.show.to_s
43
+ return
44
+ end
45
+
46
+ results = JSON.parse(response.show.to_s)
47
+ if !results.has_key?("query") || !results["query"].has_key?("results")
48
+ return
49
+ end
50
+ if statement_type == INCOME_STATEMENT
51
+ financials = Financials.new(results["query"]["results"]["incomestatement"], statement_type)
52
+ elsif statement_type == BALANCE_SHEET
53
+ financials = Financials.new(results["query"]["results"]["balancesheet"], statement_type)
54
+ end
55
+ financials
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stock_financials
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abhijith Reddy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yql
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.2
27
+ description: Get stock financials.
28
+ email: archerabi@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/balance_sheet.rb
34
+ - lib/financials.rb
35
+ - lib/income_statement.rb
36
+ - lib/stock_financials.rb
37
+ homepage: https://github.com/archerabi/StockFinancials
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.2.0
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Financials for a stock!
61
+ test_files: []
62
+ has_rdoc: