Esempio n. 1
0
    def __init__(self, symbol: str):
        """
        Constructor method to create the class. It will set all of the
        class instance variables to none.
        :param symbol: The string symbol for the company.
        """

        self._serial_printer = SerialPrinter()

        self._serial_printer.print_begin('Creating a YahooSummary object...')

        # Save the company's symbol as an instance variable.
        self._serial_printer.print_begin(
            'Creating Yahoo quote instance variables...')
        self._symbol = symbol.lower()
        self._directory = os.getcwd() + '\\data\\' + self._symbol + '\\quote\\'
        self._serial_printer.print_end('Complete!')

        self._serial_printer.print_begin('Creating quote datum objects...')
        self._quote = self.Datum(None, 'quote', self._directory + '_quote.csv')
        self._dividends = self.Datum(None, 'dividends',
                                     self._directory + '_dividends.csv')
        self._splits = self.Datum(None, 'splits',
                                  self._directory + '_splits.csv')
        self._serial_printer.print_end('Complete.')
Esempio n. 2
0
    def __init__(self, symbol: str):
        self._symbol = symbol.lower()

        self._serial_printer = SerialPrinter()

        self.directory = os.getcwd(
        ) + '\\data\\' + self._symbol + '\\summary\\'
        if not os.path.isdir(self.directory):
            os.makedirs(self.directory)
Esempio n. 3
0
    def __init__(self, symbol: str):
        self._symbol = symbol.lower()

        self._quote = None
        self._dividends = None
        self._splits = None

        self._yq = YahooQuote(self._symbol)
        self._serial_printer = SerialPrinter()
Esempio n. 4
0
    def __init__(self,
                 symbol: str,
                 response: object,
                 reader: YahooQuoteReader,
                 include_events: bool = False,
                 include_prepost: bool = False):

        self._yq = YahooQuote(symbol)
        self._serial_printer = SerialPrinter()

        super().__init__(symbol, response, reader)
Esempio n. 5
0
    def __init__(self, symbol: str):
        self._symbol = symbol
        self._yq = YahooQuote(self._symbol)

        self._serial_printer = SerialPrinter()
Esempio n. 6
0
class YahooQuoteReader():
    def __init__(self, symbol: str):
        self._symbol = symbol
        self._yq = YahooQuote(self._symbol)

        self._serial_printer = SerialPrinter()

    def format(self, df):
        return df

    def read_quote(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading quote')
        df = pd.read_csv(self._yq.quote.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self._yq.quote = df
        return self._yq

    def read_dividends(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading dividends')
        df = pd.read_csv(self._yq.dividends.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self._yq.dividends = df
        return self._yq

    def read_splits(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading splits')
        df = pd.read_csv(self._yq.splits.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self._yq.splits = df
        return self._yq


# for value in YahooQuote('aapl').as_list():
#     print('def read_{:}(self, format_value=False):'.format(value.title))
#     print('\t"""')
#     print('\tMethod for reading the data from the file.')
#     print('\t:param format_value: Whether or not to format the data.')
#     print('\t"""')
#     print('')
#     print('\tself._serial_printer.print_begin(\'Reading {:}\')'.format(value.title))
#     print('\tdf = pd.read_csv(self._yq.{:}.path)'.format(value.title))
#     print('\tself._serial_printer.print_end(\'Complete.\')')
#     print('')
#     print('\tif format_value:')
#     print('\t\tdf = self.format(df)')
#     print('')
#     print('\tself._yq.{:} = df'.format(value.title))
#     print('\treturn self._yq')
#     print('')
Esempio n. 7
0
class YahooQuote:
    def __init__(self, symbol: str):
        """
        Constructor method to create the class. It will set all of the
        class instance variables to none.
        :param symbol: The string symbol for the company.
        """

        self._serial_printer = SerialPrinter()

        self._serial_printer.print_begin('Creating a YahooSummary object...')

        # Save the company's symbol as an instance variable.
        self._serial_printer.print_begin(
            'Creating Yahoo quote instance variables...')
        self._symbol = symbol.lower()
        self._directory = os.getcwd() + '\\data\\' + self._symbol + '\\quote\\'
        self._serial_printer.print_end('Complete!')

        self._serial_printer.print_begin('Creating quote datum objects...')
        self._quote = self.Datum(None, 'quote', self._directory + '_quote.csv')
        self._dividends = self.Datum(None, 'dividends',
                                     self._directory + '_dividends.csv')
        self._splits = self.Datum(None, 'splits',
                                  self._directory + '_splits.csv')
        self._serial_printer.print_end('Complete.')

    def as_list(self):
        return [self._quote, self._dividends, self._splits]

    @property
    def quote_path(self):
        """
        A getter method to get the path to the company's quote data.
        """

        return self._quote.path

    @property
    def quote(self):
        """
        A getter method to get a company's quote data.
        """

        return self._quote.value

    @quote.setter
    def quote(self, value):
        """
        A setter method to set a company's quote data.
        :param value: The value to be set.
        """

        self._quote.value = value

    @property
    def dividends_path(self):
        """
        A getter method to get the path to the company's dividends data.
        """

        return self._dividends.path

    @property
    def dividends(self):
        """
        A getter method to get a company's dividends data.
        """

        return self._dividends.value

    @dividends.setter
    def dividends(self, value):
        """
        A setter method to set a company's dividends data.
        :param value: The value to be set.
        """

        self._dividends.value = value

    @property
    def splits_path(self):
        """
        A getter method to get the path to the company's splits data.
        """

        return self._splits.path

    @property
    def splits(self):
        """
        A getter method to get a company's splits data.
        """

        return self._splits.value

    @splits.setter
    def splits(self, value):
        """
        A setter method to set a company's splits data.
        :param value: The value to be set.
        """

        self._splits.value = value

    class Datum:
        def __init__(self, value, title, path):
            self._value = value
            self._title = title
            self._path = path

        @property
        def value(self):
            return self._value

        @value.setter
        def value(self, value):
            self._value = value

        @property
        def title(self):
            return self._title

        @property
        def path(self):
            return self._path
Esempio n. 8
0
 def __init__(self, symbol: str):
     self._symbol = symbol
     self.ys = YahooSummary(self._symbol)
     self._serial_printer = SerialPrinter()
Esempio n. 9
0
class YahooSummaryReader:
    def __init__(self, symbol: str):
        self._symbol = symbol
        self.ys = YahooSummary(self._symbol)
        self._serial_printer = SerialPrinter()

    def format(self, df):
        return df

    def read_all(self, format_value=False):
        self.ys.profile = self.read_profile(format_value=format_value)
        self.ys.company_officers = self.read_company_officers(
            format_value=format_value)
        self.ys.income_statements = self.read_income_statements(
            format_value=format_value)
        self.ys.income_statements_quarterly = self.read_income_statements_quarterly(
            format_value=format_value)
        self.ys.balance_sheets = self.read_balance_sheets(
            format_value=format_value)
        self.ys.balance_sheets_quarterly = self.read_balance_sheets_quarterly(
            format_value=format_value)
        self.ys.cash_flow_statements = self.read_cash_flow_statements(
            format_value=format_value)
        self.ys.cash_flow_statements_quarterly = self.read_cash_flow_statements_quarterly(
            format_value=format_value)
        self.ys.earnings_estimates = self.read_earnings_estimates(
            format_value=format_value)
        self.ys.earnings_estimates_quarterly = self.read_earnings_estimates_quarterly(
            format_value=format_value)
        self.ys.financials_quarterly = self.read_financials_quarterly(
            format_value=format_value)
        self.ys.financials_yearly = self.read_financials_yearly(
            format_value=format_value)
        self.ys.earnings_history = self.read_earnings_history(
            format_value=format_value)
        self.ys.financial_data = self.read_financial_data(
            format_value=format_value)
        self.ys.default_key_statistics = self.read_default_key_statistics(
            format_value=format_value)
        self.ys.institution_ownership = self.read_institution_ownership(
            format_value=format_value)
        self.ys.insider_holders = self.read_insider_holders(
            format_value=format_value)
        self.ys.insider_transactions = self.read_insider_transactions(
            format_value=format_value)
        self.ys.fund_ownership = self.read_fund_ownership(
            format_value=format_value)
        self.ys.major_direct_holders = self.read_major_direct_holders(
            format_value=format_value)
        self.ys.major_direct_holders_breakdown = self.read_major_direct_holders_breakdown(
            format_value=format_value)
        self.ys.recommendation_trend = self.read_recommendation_trend(
            format_value=format_value)
        self.ys.earnings_trend = self.read_earnings_trend(
            format_value=format_value)
        self.ys.industry_trend = self.read_industry_trend(
            format_value=format_value)
        self.ys.index_trend_info = self.read_index_trend_info(
            format_value=format_value)
        self.ys.index_trend_estimate = self.read_index_trend_estimate(
            format_value=format_value)
        self.ys.sector_trend = self.read_sector_trend(
            format_value=format_value)
        self.ys.calendar_events_earnings = self.read_calendar_events_earnings(
            format_value=format_value)
        self.ys.calendar_events_dividends = self.read_calendar_events_dividends(
            format_value=format_value)
        self.ys.sec_filings = self.read_sec_filings(format_value=format_value)
        self.ys.upgrade_downgrade_history = self.read_upgrade_downgrade_history(
            format_value=format_value)
        self.ys.net_share_purchase_activity = self.read_net_share_purchase_activity(
            format_value=format_value)

        return self.ys

    def read_profile(self, ys: YahooSummary = None, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading profile')
        df = pd.read_csv(self.ys.profile.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.profile = df
        return self.ys

    def read_company_officers(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading company_officers')
        df = pd.read_csv(self.ys.company_officers.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.company_officers = df
        return self.ys

    def read_income_statements(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading income_statements')
        self._serial_printer.print_begin('REading')
        df = pd.read_csv(self.ys.income_statements.path)

        if format_value:
            df = self.format(df)

        self.ys.income_statements = df
        return self.ys

    def read_income_statements_quarterly(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading income_statements_quarterly')
        df = pd.read_csv(self.ys.income_statements_quarterly.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.income_statements_quarterly = df
        return self.ys

    def read_balance_sheets(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading balance_sheets')
        df = pd.read_csv(self.ys.balance_sheets.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.balance_sheets = df
        return self.ys

    def read_balance_sheets_quarterly(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading balance_sheets_quarterly')
        df = pd.read_csv(self.ys.balance_sheets_quarterly.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.balance_sheets_quarterly = df
        return self.ys

    def read_cash_flow_statements(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading cash_flow_statements')
        df = pd.read_csv(self.ys.cash_flow_statements.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.cash_flow_statements = df
        return self.ys

    def read_cash_flow_statements_quarterly(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin(
            'Reading cash_flow_statements_quarterly')
        df = pd.read_csv(self.ys.cash_flow_statements_quarterly.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.cash_flow_statements_quarterly = df
        return self.ys

    def read_earnings_estimates(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading earnings_estimates')
        df = pd.read_csv(self.ys.earnings_estimates.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.earnings_estimates = df
        return self.ys

    def read_earnings_estimates_quarterly(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin(
            'Reading earnings_estimates_quarterly')
        df = pd.read_csv(self.ys.earnings_estimates_quarterly.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.earnings_estimates_quarterly = df
        return self.ys

    def read_financials_quarterly(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading financials_quarterly')
        df = pd.read_csv(self.ys.financials_quarterly.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.financials_quarterly = df
        return self.ys

    def read_financials_yearly(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading financials_yearly')
        df = pd.read_csv(self.ys.financials_yearly.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.financials_yearly = df
        return self.ys

    def read_earnings_history(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading earnings_history')
        df = pd.read_csv(self.ys.earnings_history.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.earnings_history = df
        return self.ys

    def read_financial_data(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading financial_data')
        df = pd.read_csv(self.ys.financial_data.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.financial_data = df
        return self.ys

    def read_default_key_statistics(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading default_key_statistics')
        df = pd.read_csv(self.ys.default_key_statistics.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.default_key_statistics = df
        return self.ys

    def read_institution_ownership(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading institution_ownership')
        df = pd.read_csv(self.ys.institution_ownership.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.institution_ownership = df
        return self.ys

    def read_insider_holders(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading insider_holders')
        df = pd.read_csv(self.ys.insider_holders.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.insider_holders = df
        return self.ys

    def read_insider_transactions(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading insider_transactions')
        df = pd.read_csv(self.ys.insider_transactions.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.insider_transactions = df
        return self.ys

    def read_fund_ownership(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading fund_ownership')
        df = pd.read_csv(self.ys.fund_ownership.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.fund_ownership = df
        return self.ys

    def read_major_direct_holders(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading major_direct_holders')
        df = pd.read_csv(self.ys.major_direct_holders.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.major_direct_holders = df
        return self.ys

    def read_major_direct_holders_breakdown(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin(
            'Reading major_direct_holders_breakdown')
        df = pd.read_csv(self.ys.major_direct_holders_breakdown.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.major_direct_holders_breakdown = df
        return self.ys

    def read_recommendation_trend(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading recommendation_trend')
        df = pd.read_csv(self.ys.recommendation_trend.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.recommendation_trend = df
        return self.ys

    def read_earnings_trend(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading earnings_trend')
        df = pd.read_csv(self.ys.earnings_trend.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.earnings_trend = df
        return self.ys

    def read_industry_trend(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading industry_trend')
        df = pd.read_csv(self.ys.industry_trend.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.industry_trend = df
        return self.ys

    def read_index_trend_info(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading index_trend_info')
        df = pd.read_csv(self.ys.index_trend_info.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.index_trend_info = df
        return self.ys

    def read_index_trend_estimate(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading index_trend_estimate')
        df = pd.read_csv(self.ys.index_trend_estimate.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.index_trend_estimate = df
        return self.ys

    def read_sector_trend(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading sector_trend')
        df = pd.read_csv(self.ys.sector_trend.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.sector_trend = df
        return self.ys

    def read_calendar_events_earnings(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading calendar_events_earnings')
        df = pd.read_csv(self.ys.calendar_events_earnings.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.calendar_events_earnings = df
        return self.ys

    def read_calendar_events_dividends(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading calendar_events_dividends')
        df = pd.read_csv(self.ys.calendar_events_dividends.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.calendar_events_dividends = df
        return self.ys

    def read_sec_filings(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading sec_filings')
        df = pd.read_csv(self.ys.sec_filings.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.sec_filings = df
        return self.ys

    def read_upgrade_downgrade_history(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading upgrade_downgrade_history')
        df = pd.read_csv(self.ys.upgrade_downgrade_history.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.upgrade_downgrade_history = df
        return self.ys

    def read_net_share_purchase_activity(self, format_value=False):
        """
        Method for reading the data from the file.
        :param format_value: Whether or not to format the data.
        """

        self._serial_printer.print_begin('Reading net_share_purchase_activity')
        df = pd.read_csv(self.ys.net_share_purchase_activity.path)
        self._serial_printer.print_end('Complete.')

        if format_value:
            df = self.format(df)

        self.ys.net_share_purchase_activity = df
        return self.ys


# print('self.ys.{:} = self.read_{:}(format=format)'.format(value.title, value.title))

# if __name__ == '__main__':
#     for value in YahooSummary('aapl').as_list():
#         print('def read_{:}(self, format_value=False):'.format(value.title))
#         print('\t"""')
#         print('\tMethod for reading the data from the file.')
#         print('\t:param format_value: Whether or not to format the data.')
#         print('\t"""')
#         print('')
#         print('\tself._serial_printer.print_begin(\'Reading self.ys.{:}.path\')'.format(value))
#         print('\tdf = pd.read_csv(self.ys.{:}.path)'.format(value.title))
#         print('\tself._serial_printer.print_end(\'Complete.\')')
#         print('')
#         print('\tif format_value:')
#         print('\t\tdf = self.format(df)')
#         print('')
#         print('\tself.ys.{:} = df'.format(value.title))
#         print('\treturn self.ys')
#         print('')
Esempio n. 10
0
class YahooSummaryWriter:
    def __init__(self, symbol: str):
        self._symbol = symbol.lower()

        self._serial_printer = SerialPrinter()

        self.directory = os.getcwd(
        ) + '\\data\\' + self._symbol + '\\summary\\'
        if not os.path.isdir(self.directory):
            os.makedirs(self.directory)

    def write(self, df, path, append=True, use_index=False, index_name='date'):
        if os.path.exists(path) and append:
            if use_index:
                temp_df = pd.read_csv(path, index_col=index_name)
            else:
                temp_df = pd.read_csv(path, index_col=None)

            temp_df = temp_df.append(df)
            temp_df.to_csv(path, index=False)
        else:
            if use_index:
                df.to_csv(path, index=index_name)
            else:
                df.to_csv(path, index=None)

    def write_all(self, ys: YahooSummary, append=False):
        self.write_profile(ys, append=append)
        self.write_company_officers(ys, append=append)
        self.write_income_statements(ys, append=append)
        self.write_income_statements_quarterly(ys, append=append)
        self.write_balance_sheets(ys, append=append)
        self.write_balance_sheets_quarterly(ys, append=append)
        self.write_cash_flow_statements(ys, append=append)
        self.write_cash_flow_statements_quarterly(ys, append=append)
        self.write_earnings_estimates(ys, append=append)
        self.write_earnings_estimates_quarterly(ys, append=append)
        self.write_financials_quarterly(ys, append=append)
        self.write_financials_yearly(ys, append=append)
        self.write_earnings_history(ys, append=append)
        self.write_financial_data(ys, append=append)
        self.write_default_key_statistics(ys, append=append)
        self.write_institution_ownership(ys, append=append)
        self.write_insider_holders(ys, append=append)
        self.write_insider_transactions(ys, append=append)
        self.write_fund_ownership(ys, append=append)
        self.write_major_direct_holders(ys, append=append)
        self.write_major_direct_holders_breakdown(ys, append=append)
        self.write_recommendation_trend(ys, append=append)
        self.write_earnings_trend(ys, append=append)
        self.write_industry_trend(ys, append=append)
        self.write_index_trend_info(ys, append=append)
        self.write_index_trend_estimate(ys, append=append)
        self.write_sector_trend(ys, append=append)
        self.write_calendar_events_earnings(ys, append=append)
        self.write_calendar_events_dividends(ys, append=append)
        self.write_sec_filings(ys, append=append)
        self.write_upgrade_downgrade_history(ys, append=append)
        self.write_net_share_purchase_activity(ys, append=append)

    def write_profile(self, ys: YahooSummary, append=False):
        """
        Method for writing the profile to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing profile')
        self.write(ys.profile, ys.profile_path, use_index=False, append=append)
        self._serial_printer.print_end('Complete!')

    def write_company_officers(self, ys: YahooSummary, append=False):
        """
        Method for writing the company officers to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing company officers')
        self.write(ys.company_officers,
                   ys.company_officers_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_income_statements(self, ys: YahooSummary, append=False):
        """
        Method for writing the income statements to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing income statements')
        self.write(ys.income_statements,
                   ys.income_statements_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_income_statements_quarterly(self,
                                          ys: YahooSummary,
                                          append=False):
        """
        Method for writing the income statements quarterly to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing income statements quarterly')
        self.write(ys.income_statements_quarterly,
                   ys.income_statements_quarterly_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_balance_sheets(self, ys: YahooSummary, append=False):
        """
        Method for writing the balance sheets to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing balance sheets')
        self.write(ys.balance_sheets,
                   ys.balance_sheets_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_balance_sheets_quarterly(self, ys: YahooSummary, append=False):
        """
        Method for writing the balance sheets quarterly to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing balance sheets quarterly')
        self.write(ys.balance_sheets_quarterly,
                   ys.balance_sheets_quarterly_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_cash_flow_statements(self, ys: YahooSummary, append=False):
        """
        Method for writing the cash flow statements to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing cash flow statements')
        self.write(ys.cash_flow_statements,
                   ys.cash_flow_statements_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_cash_flow_statements_quarterly(self,
                                             ys: YahooSummary,
                                             append=False):
        """
        Method for writing the cash flow statements quarterly to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin(
            'Writing cash flow statements quarterly')
        self.write(ys.cash_flow_statements_quarterly,
                   ys.cash_flow_statements_quarterly_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_earnings_estimates(self, ys: YahooSummary, append=False):
        """
        Method for writing the earnings estimates to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing earnings estimates')
        self.write(ys.earnings_estimates,
                   ys.earnings_estimates_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_earnings_estimates_quarterly(self,
                                           ys: YahooSummary,
                                           append=False):
        """
        Method for writing the earnings estimates quarterly to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin(
            'Writing earnings estimates quarterly')
        self.write(ys.earnings_estimates_quarterly,
                   ys.earnings_estimates_quarterly_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_financials_quarterly(self, ys: YahooSummary, append=False):
        """
        Method for writing the financials quarterly to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing financials quarterly')
        self.write(ys.financials_quarterly,
                   ys.financials_quarterly_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_financials_yearly(self, ys: YahooSummary, append=False):
        """
        Method for writing the financials yearly to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing financials yearly')
        self.write(ys.financials_yearly,
                   ys.financials_yearly_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_earnings_history(self, ys: YahooSummary, append=False):
        """
        Method for writing the earnings history to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing earnings history')
        self.write(ys.earnings_history,
                   ys.earnings_history_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_financial_data(self, ys: YahooSummary, append=False):
        """
        Method for writing the financial data to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing financial data')
        self.write(ys.financial_data,
                   ys.financial_data_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_default_key_statistics(self, ys: YahooSummary, append=False):
        """
        Method for writing the default key statistics to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing default key statistics')
        self.write(ys.default_key_statistics,
                   ys.default_key_statistics_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_institution_ownership(self, ys: YahooSummary, append=False):
        """
        Method for writing the institution ownership to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing institution ownership')
        self.write(ys.institution_ownership,
                   ys.institution_ownership_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_insider_holders(self, ys: YahooSummary, append=False):
        """
        Method for writing the insider holders to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing insider holders')
        self.write(ys.insider_holders,
                   ys.insider_holders_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_insider_transactions(self, ys: YahooSummary, append=False):
        """
        Method for writing the insider transactions to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing insider transactions')
        self.write(ys.insider_transactions,
                   ys.insider_transactions_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_fund_ownership(self, ys: YahooSummary, append=False):
        """
        Method for writing the fund ownership to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing fund ownership')
        self.write(ys.fund_ownership,
                   ys.fund_ownership_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_major_direct_holders(self, ys: YahooSummary, append=False):
        """
        Method for writing the major direct holders to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing major direct holders')
        self.write(ys.major_direct_holders,
                   ys.major_direct_holders_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_major_direct_holders_breakdown(self,
                                             ys: YahooSummary,
                                             append=False):
        """
        Method for writing the major direct holders breakdown to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin(
            'Writing major direct holders breakdown')
        self.write(ys.major_direct_holders_breakdown,
                   ys.major_direct_holders_breakdown_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_recommendation_trend(self, ys: YahooSummary, append=False):
        """
        Method for writing the recommendation trend to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing recommendation trend')
        self.write(ys.recommendation_trend,
                   ys.recommendation_trend_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_earnings_trend(self, ys: YahooSummary, append=False):
        """
        Method for writing the earnings trend to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing earnings trend')
        self.write(ys.earnings_trend,
                   ys.earnings_trend_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_industry_trend(self, ys: YahooSummary, append=False):
        """
        Method for writing the industry trend to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing industry trend')
        self.write(ys.industry_trend,
                   ys.industry_trend_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_index_trend_info(self, ys: YahooSummary, append=False):
        """
        Method for writing the index trend info to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing index trend info')
        self.write(ys.index_trend_info,
                   ys.index_trend_info_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_index_trend_estimate(self, ys: YahooSummary, append=False):
        """
        Method for writing the index trend estimate to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing index trend estimate')
        self.write(ys.index_trend_estimate,
                   ys.index_trend_estimate_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_sector_trend(self, ys: YahooSummary, append=False):
        """
        Method for writing the sector trend to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing sector trend')
        self.write(ys.sector_trend,
                   ys.sector_trend_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_calendar_events_earnings(self, ys: YahooSummary, append=False):
        """
        Method for writing the calendar events earnings to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing calendar events earnings')
        self.write(ys.calendar_events_earnings,
                   ys.calendar_events_earnings_path,
                   use_index=True,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_calendar_events_dividends(self, ys: YahooSummary, append=False):
        """
        Method for writing the calendar events dividends to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing calendar events dividends')
        self.write(ys.calendar_events_dividends,
                   ys.calendar_events_dividends_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_sec_filings(self, ys: YahooSummary, append=False):
        """
        Method for writing the sec filings to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing sec filings')
        self.write(ys.sec_filings,
                   ys.sec_filings_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_upgrade_downgrade_history(self, ys: YahooSummary, append=False):
        """
        Method for writing the upgrade downgrade history to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing upgrade downgrade history')
        self.write(ys.upgrade_downgrade_history,
                   ys.upgrade_downgrade_history_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_net_share_purchase_activity(self,
                                          ys: YahooSummary,
                                          append=False):
        """
        Method for writing the net share purchase activity to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing net share purchase activity')
        self.write(ys.net_share_purchase_activity,
                   ys.net_share_purchase_activity_path,
                   use_index=False,
                   append=append)
        self._serial_printer.print_end('Complete!')


# print('def write_all(self, append=False)
# for value in YahooSummary('aapl').as_list():
#     print('\tself.write_{:}(append=append)'.format(value.title))

# for value in YahooSummary('aapl').as
# _list():
#     print('def write_{:}(self, append=False):'.format(value.title))
#     print('\t"""')
#     print('\tMethod for writing the {:} to a file.'.format(
#         value.title.replace('_', ' ')))
#     print(
#         '\t:param append: Whether or not to append or overwrite existing file.')
#     print('\t"""')
#     print('')
#     print('\tself._serial_printer.print_begin(\'Writing {:}\')'.format(
#         value.title.replace('_', ' ')))
#     print('\tself.write(ys.{:},'.format(value.title))
#     print('\t\t\t   ys.{:}_path,'.format(value.title))
#     print('\t\t\t   use_index={:}, append=append)'.format(value.uses_index))
#     print('\tself._serial_printer.print_end(\'Complete!\')')
#     print('')
Esempio n. 11
0
class YahooQuoteWriter:

    def __init__(self, symbol: str):
        self._symbol = symbol.lower()

        self._quote = None
        self._dividends = None
        self._splits = None

        self._yq = YahooQuote(self._symbol)
        self._serial_printer = SerialPrinter()

    def write(self, df, path, append=True):
        """
        Method to write the data to a file.
        :param df: The data in dataframe form.
        :param path: The path to where the data needs to be written.
        :param append: Whether or not to append the data.
        """

        if os.path.exists(path) and append:
            temp_df = pd.read_csv(path, index_col='date')

            temp_df = temp_df.append(df)
            temp_df.to_csv(path, index=False)
        else:
            df.to_csv(path, index='date')

    def write_quote(self, append=False):
        """
        Method for writing the quote to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing quote')
        self.write(self._yq.quote,
                   self._yq.quote.path,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_dividends(self, append=False):
        """
        Method for writing the dividends to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing dividends')
        self.write(self._yq.dividends,
                   self._yq.dividends.path,
                   append=append)
        self._serial_printer.print_end('Complete!')

    def write_splits(self, append=False):
        """
        Method for writing the splits to a file.
        :param append: Whether or not to append or overwrite existing file.
        """

        self._serial_printer.print_begin('Writing splits')
        self.write(self._yq.splits,
                   self._yq.splits.path,
                   append=append)
        self._serial_printer.print_end('Complete!')


# for value in YahooQuote('aapl').as_list():
#     print('def write_{:}(self, append=False):'.format(value.title))
#     print('\t"""')
#     print('\tMethod for writing the {:} to a file.'.format(value.title.replace('_', ' ')))
#     print('\t:param append: Whether or not to append or overwrite existing file.')
#     print('\t"""')
#     print('')
#     print('\tself._serial_printer.print_begin(\'Writing {:}\')'.format(value.title.replace('_', ' ')))
#     print('\tself.write(self._summary.{:},'.format(value.title))
#     print('\t\t\t   self._summary.{:}.path,'.format(value.title))
#     print('\t\t\t   use_index={:}, append=append)'.format(value.uses_index))
#     print('\tself._serial_printer.print_end(\'Complete!\')')
#     print('')
Esempio n. 12
0
class YahooQuoteProcessor(BaseProcessor):
    def __init__(self,
                 symbol: str,
                 response: object,
                 reader: YahooQuoteReader,
                 include_events: bool = False,
                 include_prepost: bool = False):

        self._yq = YahooQuote(symbol)
        self._serial_printer = SerialPrinter()

        super().__init__(symbol, response, reader)

    def process(self):
        response_json = self.response.json()
        yahoo_quote = YahooQuote(self.symbol)

        modules = response_json['chart']['result'][0]

        self._serial_printer.print_begin('Parsing quote objects...')
        self._yq.quote = self.parse_quote(modules)
        self._yq.dividends = self.parse_dividends(modules)
        self._yq.splits = self.parse_splits(modules)
        self._serial_printer.print_end('Complete.')

        return self._yq

    def parse_quote(self, modules):

        self._serial_printer.print_begin('Parsing quote from response...')

        if 'indicators' in modules and \
                'quote' in modules['indicators'] and \
                len(modules['indicators']['quote']) > 0 and \
                'timestamp' in modules and \
                'indicators' in modules and \
                'adjclose' in modules['indicators'] and \
                len(modules['indicators']['adjclose']) > 0:

            self._serial_printer.print_begin('Finding quote in response...')
            quotes = modules['indicators']['quote'][0]
            dates = modules['timestamp']
            adj_close = modules['indicators']['adjclose'][0]
            self._serial_printer.print_end('Complete.')

            self._serial_printer.print_begin('Creating dataframe...')
            # Combine the two dictionaries.
            dict = {**quotes, **adj_close}

            # Turn the dictionary into a dataframe.
            df = pd.DataFrame.from_dict(dict)
            self._serial_printer.print_end('Complete.')

            # Get the timestamp (datetime) for each quote entry in the pipelines and parse it.
            self._serial_printer.print_begin('Formatting columns...')
            df['date'] = dates
            df['date'] = pd.to_datetime(df['date'], unit='s')

            df['volume'] = pd.to_numeric(df['volume'])

            df = df.reindex(columns=[
                'date', 'open', 'high', 'low', 'close', 'adjclose', 'volume'
            ])

            df = df.set_index('date').sort_index()
            self._serial_printer.print_end('Complete.')

        else:
            self._serial_printer.print_begin('Creating empty dataframe...')
            df = pd.DataFrame()
            self._serial_printer.print_end('Complete.')

        self._serial_printer.print_end('Complete.')

        return df

    def parse_dividends(self, modules):

        self._serial_printer.print_begin('Parsing dividends from response...')

        if 'events' in modules and \
            'dividends' in modules['events']:
            # Get the splits dictionary from the JSON API output.
            self._serial_printer.print_begin(
                'Finding dividends in response...')
            dict = modules['events']['dividends']
            self._serial_printer.print_end('Complete.')

            # Convert the splits dictionary to a Dataframe.
            self._serial_printer.print_begin('Creating dataframe...')
            df = pd.DataFrame.from_dict(dict, orient='index')
            self._serial_printer.print_end('Complete.')

            self._serial_printer.print_begin('Formatting columns...')
            df['date'] = pd.to_datetime(df['date'], unit='s')
            df = df.set_index('date').sort_index()
            self._serial_printer.print_end('Complete.')

        else:
            self._serial_printer.print_begin('Creating empty dataframe...')
            df = pd.DataFrame()
            self._serial_printer.print_end('Complete.')

        self._serial_printer.print_end('Complete.')

        return df

    def parse_splits(self, modules):

        self._serial_printer.print_begin('Parsing splits from response...')

        if 'events' in modules and \
            'splits' in modules['events']:

            # Get the splits dictionary from the JSON API output.
            self._serial_printer.print_begin(
                'Finding dividends in response...')
            dict = modules['events']['splits']
            self._serial_printer.print_end('Complete.')

            self._serial_printer.print_begin('Creating dataframe...')
            df = pd.DataFrame.from_dict(dict, orient='index')
            self._serial_printer.print_end('Complete.')

            self._serial_printer.print_begin('Formatting columns...')
            df['date'] = pd.to_datetime(df['date'], unit='s')
            df = df.set_index('date').sort_index()
            self._serial_printer.print_end('Complete.')

        else:
            self._serial_printer.print_begin('Creating empty dataframe...')
            df = pd.DataFrame()
            self._serial_printer.print_end('Complete.')

        self._serial_printer.print_end('Complete.')

        return df