financeMacroFactors.companies package¶
Submodules¶
financeMacroFactors.companies.companyLists module¶
-
financeMacroFactors.companies.companyLists.getSNP500CompanyList()[source]¶ get the list of SNP 500 companies.
This function downloads the data from the Wikipedia page and populate a list of dictionaries. No check is performed on the accuracy or consistency of the result. If there is an error, an error message will be logged, and in that case an empty list will be returned.
- Returns
This will return a list of dictionaries, where each key will represent the header and each value will represent the associated text present within a particular table data element. In case of an error, an empty list will be returned. The logger will be used for exporting errors and warnings to the user.
- Return type
list of dictionaries
financeMacroFactors.companies.marketWarchData module¶
-
financeMacroFactors.companies.marketWarchData.convertNumberMW(number)[source]¶ translate a string to a potential number Marketwatch contains numbers within HTML tables as text. The text is present in a form that is specific to Marketwatch and thus cannot be easily translated. This function will help with the translation.
- Parameters
number (str) – A string that should be converted into a number
- Returns
If the correct translation was performed, then this is going to return a floating point number representing the number. Otherwise, it will return the original string.
- Return type
float or str
-
financeMacroFactors.companies.marketWarchData.convertToDates(yearInfo)[source]¶ Internal function - do not use
-
financeMacroFactors.companies.marketWarchData.convertToMonths(info)[source]¶ Internal function - do not use
-
financeMacroFactors.companies.marketWarchData.extractQuarterlyData(info, toExtract='EPS (Diluted)')[source]¶ extract required data from a given list of items
This is a utility function that will allow one to easily extract any informamtion from the MWData that you have already downloaded. For example, from the “IncomeStatement” It is possible to extract information about the “Earnings per Share”.
It is important to know that the information provided should not ge generated by the user, but rather through the function
getTickerFundamentalDataMW()with the parameterconvertset toFalse.- Parameters
info (list) – List containing quarterly information about a particular company.
toExtract (str, optional) – Information that you wish to extract, by default ‘EPS (Diluted)’
- Returns
returns a list of tuples containing the dates and the values corresponding to the information requested
- Return type
list
-
financeMacroFactors.companies.marketWarchData.extractYearlyData(info, toExtract='EPS (Diluted)')[source]¶ extract required data from a given list of items
This is a utility function that will allow one to easily extract any informamtion from the MWData that you have already downloaded. For example, from the “IncomeStatement” It is possible to extract information about the “Earnings per Share”.
It is important to know that the information provided should not ge generated by the user, but rather through the function
getTickerFundamentalDataMW()with the parameterconvertset toFalse.- Parameters
info (list) – List containing yearly information about a particular company.
toExtract (str, optional) – Information that you wish to extract, by default ‘EPS (Diluted)’
- Returns
returns a list of tuples containing the dates and the values corresponding to the information requested
- Return type
list
-
financeMacroFactors.companies.marketWarchData.getDataFromMWURL(url, convert=True)[source]¶ Get data from a mamrketwatch URL page Given a particular URL, this function is going to return all the data that is associated with the particular URL. Typically the results are present in multiple tables. The data from all the tables are combined into a single table before it is returned. Typically, the headers remain unchained. Note that this function should not be used directly, but rather through the use of other functions present within this module, sinnce this function doees not check whether this url actually exists or not. In the case of an error, an empty list is returned.
- Parameters
url (str) – This should be a Markektwatch URL that deals with proper stock information.
convert (bool, optional) – determine whether numbers represented as strings should be coonverted into numbers, by default
True.
- Returns
The data present within the tables within the supplied URL.
- Return type
list of list
-
financeMacroFactors.companies.marketWarchData.getTickerFundamentalDataMW(ticker, convert=True)[source]¶ get Valuation data for the supplied ticker This is going to get all financials from marketwatch, including the income statement, the balance sheet, and the cash-flow sheet for the lat few quarters and years separately and return the result in a dictionary. In case of any error is made, this is going to return an empty dictionary.
- Parameters
ticker (str) – A valid ticker for downloading company data.
convert (bool, optional) – Used to convert numeric data present in the webpage as a string back into a number, by default
True. Set this to False if you want to save the data from the internet as CSV files.
- Returns
financial data associated with a particular stock
- Return type
dict
financeMacroFactors.companies.yahooData module¶
-
financeMacroFactors.companies.yahooData.getStockDataYahoo(ticker, startDate=datetime.datetime(2019, 8, 24, 22, 15, 45, 438850), endDate=datetime.datetime(2020, 8, 23, 22, 15, 45, 438854), frequency='1mo', convert=True)[source]¶ obtains historical stock prices from Yahoo!
Historic prices of a company as obtained form yahoo. It comprises of a list of lists. The first like represents the header. The data is present in the following lines. Data for dividents and stock splits are removed from the list. All numerical values are converted to floating point numbers. If
convertis set toTrue, the dates are converted into adatetime.datetimeobject. Otherwise it is retained as a string.The returned data like the following:
[[‘Date’, ‘Open’, ‘High’, ‘Low’, ‘Close*’, ‘Adj. close**’, ‘Volume’], [datetime.datetime(2020, 7, 31, 0, 0), 204.4, 205.1, 199.01, 205.01, 205.01, 51247969.0], [datetime.datetime(2020, 7, 1, 0, 0), 203.14, 216.38, 197.51, 205.01, 205.01, 770306200.0], … ]
In case there is an error, an error will be logged and an empty list will be returned.
- Parameters
ticker (str) – a valid sticker symbol of the company for which the data is to be obtained.
startDate (datetime.datetime, optional) – This is the start date from which the date should be obtained, by default
dt.now()-tDel(365)endDate (datetime.datetime, optional) – This is the last datetime for which the data should be obtained, by default
dt.now()frequency (str, optional) – This is either
'1d','1wk','1mo'. By default this is set to'1mo'for an average data for a month.convert (bool, optional) – If this is set to
True, then the dates are converted intodatetime.datetimeobjects. Otherwise, they are kept as strings. By default, this is set toTrue.
- Returns
Stock data as returned from Yahoo. See the description above.
- Return type
list of list
Module contents¶
API for getting information about companies
This module can be used for obtaining a host of information for different companies. This includes, information lists of companies that are part of the S&P500, and other lists, and also about getting theri fundamental information. This set of functions largely rely upon obtaining data from open sources.