Skip to content

Commit

Permalink
added feature requested in #18
Browse files Browse the repository at this point in the history
  • Loading branch information
JECSand committed Jan 13, 2019
1 parent eb7a8b5 commit 1d6bce9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
1.2 08/29/2018 -- Fixed timezone error in python testing. Issue #11.
1.2 08/29/2018 -- Fixed unicode formatted_date string for consistency.
1.3 10/25/2018 -- Added patch for reported bug described in Issue #14.
1.4 01/13/2019 -- Python3.7 support added.
1.4 01/13/2019 -- Added patch for reported bug described in Issue #15.
1.4 01/13/2019 -- Added method for get_stock_earnings_data().
78 changes: 71 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A python module that returns stock, cryptocurrency, forex, mutual fund, commodit

Current Version: v1.4

Version Released: 01/12/2019
Version Released: 01/13/2019

Report any bugs by opening an issue here: https://github.com/JECSand/yahoofinancials/issues

Expand All @@ -21,8 +21,7 @@ A powerful financial data module used for pulling both fundamental and technical

Installation
------------
- yahoofinancials runs on Python 2.7, 3.3, 3.4, 3.5, and 3.6.
- Python 3.7 support is coming soon.
- yahoofinancials runs on Python 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7.
- The package depends on beautifulsoup4 and pytz to work.

1. Installation using pip:
Expand Down Expand Up @@ -67,7 +66,7 @@ Module Methods
--------------
- The financial data from all methods is returned as JSON.
- You can run multiple symbols at once using an inputted array or run an individual symbol using an inputted string.
- YahooFinancials works with Python 2.7, 3.3, 3.4, 3.5, and 3.6 and runs on all operating systems. (Windows, Mac, Linux).
- YahooFinancials works with Python 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7 and runs on all operating systems. (Windows, Mac, Linux).

Featured Methods
^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -99,10 +98,9 @@ Featured Methods

- price_type can also be set to 'average' to calculate the shares outstanding with the daily average price.

Methods Removed in V1.0
Methods Added in V1.4
^^^^^^^^^^^^^^^^^^^^^^^
- get_stock_summary_data():
- get_historical_stock_data():
- get_key_statistics_data():

Additional Module Methods
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -622,3 +620,69 @@ Examples of Returned JSON Data
"ytdReturn": null
}
}
11. Apple Key Statistics Data:


.. code-block:: python
yahoo_financials = YahooFinancials('AAPL')
print(yahoo_financials.get_key_statistics_data())
.. code-block:: javascript
{
"AAPL": {
"annualHoldingsTurnover": null,
"enterpriseToRevenue": 2.973,
"beta3Year": null,
"profitMargins": 0.22413999,
"enterpriseToEbitda": 9.652,
"52WeekChange": -0.12707871,
"morningStarRiskRating": null,
"forwardEps": 13.49,
"revenueQuarterlyGrowth": null,
"sharesOutstanding": 4729800192,
"fundInceptionDate": "-",
"annualReportExpenseRatio": null,
"totalAssets": null,
"bookValue": 22.534,
"sharesShort": 44915125,
"sharesPercentSharesOut": 0.0095,
"fundFamily": null,
"lastFiscalYearEnd": 1538179200,
"heldPercentInstitutions": 0.61208,
"netIncomeToCommon": 59531001856,
"trailingEps": 11.91,
"lastDividendValue": null,
"SandP52WeekChange": -0.06475246,
"priceToBook": 6.7582316,
"heldPercentInsiders": 0.00072999997,
"nextFiscalYearEnd": 1601337600,
"yield": null,
"mostRecentQuarter": 1538179200,
"shortRatio": 1,
"sharesShortPreviousMonthDate": "2018-10-31",
"floatShares": 4489763410,
"beta": 1.127094,
"enterpriseValue": 789555511296,
"priceHint": 2,
"threeYearAverageReturn": null,
"lastSplitDate": "2014-06-09",
"lastSplitFactor": "1/7",
"legalType": null,
"morningStarOverallRating": null,
"earningsQuarterlyGrowth": 0.318,
"priceToSalesTrailing12Months": null,
"dateShortInterest": 1543536000,
"pegRatio": 0.98,
"ytdReturn": null,
"forwardPE": 11.289103,
"maxAge": 1,
"lastCapGain": null,
"shortPercentOfFloat": 0.0088,
"sharesShortPriorMonth": 36469092,
"category": null,
"fiveYearAverageReturn": null
}
}
6 changes: 3 additions & 3 deletions test/test_yahoofinancials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# YahooFinancials Unit Tests v1.4
# Version Released: 01/12/2019
# Version Released: 01/13/2019
# Author: Connor Sanders
# Tested on Python 2.7, 3.3, 3.4, 3.5, and 3.6
# Tested on Python 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7
# Copyright (c) 2019 Connor Sanders
# MIT License

Expand All @@ -16,7 +16,7 @@


# Test Configuration Variables
stocks = ['AAPL', 'MSFT', 'C']
stocks = ['AAPL', 'MSFT', 'C', 'IL&FSTRANS.NS']
currencies = ['EURUSD=X', 'JPY=X', 'GBPUSD=X']
us_treasuries = ['^TNX', '^IRX', '^TYX']

Expand Down
17 changes: 14 additions & 3 deletions yahoofinancials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Author: Connor Sanders
Email: [email protected]
Version Released: 01/12/2018
Tested on Python 2.7, 3.3, 3.4, 3.5, and 3.6
Version Released: 01/13/2019
Tested on Python 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7
Copyright (c) 2019 Connor Sanders
MIT License
Expand Down Expand Up @@ -86,6 +86,7 @@ def __init__(self, ticker):
'income': ['financials', 'incomeStatementHistory', 'incomeStatementHistoryQuarterly'],
'balance': ['balance-sheet', 'balanceSheetHistory', 'balanceSheetHistoryQuarterly', 'balanceSheetStatements'],
'cash': ['cash-flow', 'cashflowStatementHistory', 'cashflowStatementHistoryQuarterly', 'cashflowStatements'],
'keystats': ['key-statistics'],
'history': ['history']
}

Expand Down Expand Up @@ -484,7 +485,10 @@ def get_stock_data(self, statement_type='income', tech_type='', report_name='',

# Public Method to get technical stock data
def get_stock_tech_data(self, tech_type):
return self.get_stock_data(tech_type=tech_type)
if tech_type == 'defaultKeyStatistics':
return self.get_stock_data(statement_type='keystats', tech_type=tech_type)
else:
return self.get_stock_data(tech_type=tech_type)

# Public Method to get reformatted statement data
def get_reformatted_stmt_data(self, raw_data, statement_type):
Expand Down Expand Up @@ -567,6 +571,13 @@ def get_stock_price_data(self, reformat=True):
else:
return self.get_stock_tech_data('price')

# Public Method for the user to return key-statistics data
def get_key_statistics_data(self, reformat=True):
if reformat:
return self.get_clean_data(self.get_stock_tech_data('defaultKeyStatistics'), 'defaultKeyStatistics')
else:
return self.get_stock_tech_data('defaultKeyStatistics')

# Public Method for the user to get stock earnings data
def get_stock_earnings_data(self, reformat=True):
if reformat:
Expand Down

0 comments on commit 1d6bce9

Please sign in to comment.