Exemple #1
0
    def __init__(self, broker, cli_args, asset_selector=None, backdate=None):
        """
        :param broker:
        :param cli_args:
        :param asset_selector:
        :param backdate:
        """
        if not broker or broker is None:
            raise IndicatorValidationException('[!] Broker instance required.')

        if asset_selector is not None:
            self.portfolio = asset_selector.portfolio
        else:
            raise IndicatorValidationException('[!] No ticker symbols found to trade.')

        if not backdate or backdate is None:
            backdate = time_from_timestamp(time.time() - (604800 * 54))

        if cli_args.period is not None:
            self.period = cli_args.period
        else:
            self.period = '1D'

        self.all_indicators = True
        self.broker         = broker
        self.backdate       = backdate
        self.indicator_list = None
        self.mode           = cli_args.mode
        self.account        = self.broker.trading_account
        self.buying_power   = self.broker.buying_power
        self.data           = dict()
        self.model_data     = pd.DataFrame()

        # init stage two:
        self._populate_indicators()
Exemple #2
0
    def get_tweets(cls, api_interface, ticker, since=None, search_terms=None):
        """Get tweets about a ticker

        :param api_interface:
        :param ticker:
        :param since: YYYY-MM-DD formatted date
        :param search_terms: optional additional search term
        :return: string consisting of text from tweets
        """
        if not api_interface or api_interface is None:
            raise TwitterInterfaceException

        if not ticker or ticker is None:
            raise ValueError('Invalid ticker symbol')

        if not since or since is None:
            since = time_from_timestamp(time.time() - (604800 * 13),
                                        time_format='%Y-%m-%d')

        if not search_terms or search_terms is None:
            query = '{} stock'.format(ticker)
        else:
            query = '{} stock {}'.format(ticker, search_terms)

        try:
            results = api_interface.GetSearch(query,
                                              result_type='recent',
                                              since=since,
                                              count=100)
        except TwitterActionException:
            raise TwitterActionException(
                '[!] Failed to get Twitter search results for {}.'.format(
                    ticker))
        else:

            result_dicts = [
                dict(created_at=time_from_timestamp(
                    float(result.created_at_in_seconds)),
                     user=result.user.name,
                     text=result.text) for result in results
                if 'RT' not in result.text
            ]

            texts = [res['text'] for res in result_dicts]
            text = '\n\n'.join(texts)

            return text
Exemple #3
0
    def get_edgar_signals(self):
        """Loop through tickers and append EDGAR signals to that ticker's dataframe"""
        if not self.dataframe or self.dataframe is None:
            raise NotImplementedError('[!] Dataframe should only be none if AssetSelector is using it')

        for ticker in self.dataframe.keys():
            fdate = self.dataframe[ticker]['time'].iloc[-7].strftime('%Y-%m-%d')
            tdate = time_from_timestamp(time.time(), time_format='%Y-%m-%d')
            self.edgar_scores[ticker] = self.calculate_edgar_signal(ticker, fdate, tdate)
        return self.edgar_scores
Exemple #4
0
    def _asset_indicators(self, backdate=None):
        """Loop through collection of assets and append their indicators to the dataframe.

        :return: A pandas dataframe of ticker dataframes for each asset.
        """
        if not backdate or backdate is None:
            print('[Debug] Backdate debug', inspect.stack()[0][3])
            backdate = time_from_timestamp(time.time() - (604800 * 13))

        for ticker in self.portfolio:
            try:
                self.data[ticker] = self.get_ticker_indicators(ticker, self.period)
            except EmptyDataError:
                raise EmptyDataError
            except IndicatorException:
                raise IndicatorException
            else:
                continue
        return self.data
Exemple #5
0
 def test_time_from_timestamp(self):
     ts = time.time()
     res = util.time_from_timestamp(time_stamp=ts)
     self.assertIsInstance(res, str)
Exemple #6
0
 def test_get_calendar(self):
     start = time_from_timestamp(time.time() - (604800 * 54))
     end = time_from_timestamp(time.time())
     res = TestBroker.broker.get_calendar(start_date=start, end_date=end)
     self.assertIsInstance(res, list)
     self.assertIsInstance(res[0], Ent.Calendar)