Beispiel #1
0
    def TickerInsideTrader(self):
        """Get insider information table.

        Returns:
            df(pandas.DataFrame): insider information table
        """
        inside_trader = self.soup.find('table', class_='body-table')
        rows = inside_trader.findAll('tr')
        table_header = [i.text for i in rows[0].findAll('td')]
        table_header += ['Insider_id']
        df = pd.DataFrame([], columns=table_header)
        rows = rows[1:]
        num_col = ['Cost', '#Shares', 'Value ($)', '#Shares Total']
        num_col_index = [
            table_header.index(i) for i in table_header if i in num_col
        ]
        for row in rows:
            cols = row.findAll('td')
            info_dict = {}
            for i, col in enumerate(cols):
                if i not in num_col_index:
                    info_dict[table_header[i]] = col.text
                else:
                    info_dict[table_header[i]] = numberCovert(col.text)
            info_dict['Insider_id'] = cols[0].a['href'].split('oc=')[1].split(
                '&tc=')[0]
            df = df.append(info_dict, ignore_index=True)
        self.info['inside trader'] = df
        return df
Beispiel #2
0
    def getInsider(self):
        """Get insider information table.

        Returns:
            df(pandas.DataFrame): insider information table
        """
        insider_trader = self.soup.findAll('table')[5]
        rows = insider_trader.findAll('tr')
        table_header = [i.text.strip() for i in rows[0].findAll('td')]
        df = pd.DataFrame([], columns=table_header)
        rows = rows[1:]
        num_col = ['Cost', '#Shares', 'Value ($)', '#Shares Total']
        num_col_index = [
            table_header.index(i) for i in table_header if i in num_col
        ]
        for row in rows:
            cols = row.findAll('td')
            info_dict = {}
            for i, col in enumerate(cols):
                if i not in num_col_index:
                    info_dict[table_header[i]] = col.text
                else:
                    info_dict[table_header[i]] = numberCovert(col.text)
            df = df.append(info_dict, ignore_index=True)
        self.df = df
        return df
Beispiel #3
0
    def ScreenerView(self, group='Sector', order='Name'):
        """Get screener table.

        Args:
            group(str): choice of group option.
            order(str): sort the table by the choice of order.
        Returns:
            df(pandas.DataFrame): group information table.
        """
        if group not in self.group_dict:
            raise ValueError()
        if order not in self.order_dict:
            raise ValueError()
        self.url = self.BASE_URL.format(
            group=self.group_dict[group]) + '&' + self.order_dict[order]

        soup = webScrap(self.url)
        table = soup.findAll('table')[5]
        rows = table.findAll('tr')
        table_header = [i.text for i in rows[0].findAll('td')][1:]
        df = pd.DataFrame([], columns=table_header)
        rows = rows[1:]
        num_col_index = [i for i in range(2, len(table_header))]
        for row in rows:
            cols = row.findAll('td')[1:]
            info_dict = {}
            for i, col in enumerate(cols):
                # check if the col is number
                if i not in num_col_index:
                    info_dict[table_header[i]] = col.text
                else:
                    info_dict[table_header[i]] = numberCovert(col.text)

            df = df.append(info_dict, ignore_index=True)
        return df
Beispiel #4
0
    def TickerFundament(self, raw=True):
        """Get ticker fundament.

        Args:
            raw(boolean): if True, the data is raw.

        Returns:
            fundament(dict): ticker fundament.
        """
        fundament_info = {}

        table = self.soup.findAll('table')[5]
        rows = table.findAll('tr')

        fundament_info['Company'] = rows[1].text
        fundament_info['Sector'], fundament_info['Industry'], fundament_info[
            'Country'] = rows[2].text.split(' | ')

        fundament_table = self.soup.find('table', class_='snapshot-table2')
        rows = fundament_table.findAll('tr')

        for row in rows:
            cols = row.findAll('td')
            cols = [i.text for i in cols]
            header = ''
            for i, value in enumerate(cols):
                if i % 2 == 0:
                    header = value
                else:
                    if header == 'Volatility':
                        fundament_info = self._parse_volatility(
                            header, fundament_info, value, raw)
                    elif header == '52W Range':
                        fundament_info = self._parse_52w_range(
                            header, fundament_info, value, raw)
                    elif header == 'Optionable' or header == 'Shortable':
                        if raw:
                            fundament_info[header] = value
                        elif value == 'Yes':
                            fundament_info[header] = True
                        else:
                            fundament_info[header] = False
                    else:
                        if raw:
                            fundament_info[header] = value
                        else:
                            try:
                                fundament_info[header] = numberCovert(value)
                            except ValueError:
                                fundament_info[header] = value
        self.info['fundament'] = fundament_info
        return fundament_info
Beispiel #5
0
 def _parse_value(self, header, fundament_info, value, raw, info_header,
                  info_value):
     try:
         value = value.split()
         if raw:
             for i, value_index in enumerate(info_value):
                 fundament_info[info_header[i]] = value[value_index]
         else:
             for i, value_index in enumerate(info_value):
                 fundament_info[info_header[i]] = numberCovert(
                     value[value_index])
     except:
         fundament_info[header] = value
     return fundament_info
Beispiel #6
0
    def _get_table(self, rows, df, num_col_index, table_header, limit=-1):
        """Get screener table helper function.

        Returns:
            df(pandas.DataFrame): screener information table
        """
        rows = rows[1:]
        if limit != -1:
            rows = rows[0:limit]

        for index, row in enumerate(rows):
            cols = row.findAll('td')[1:]
            info_dict = {}
            for i, col in enumerate(cols):
                # check if the col is number
                if i not in num_col_index:
                    info_dict[table_header[i]] = col.text
                else:
                    info_dict[table_header[i]] = numberCovert(col.text)
            df = df.append(info_dict, ignore_index=True)
        return df