def fetchds_update(self):
        quandl.ApiConfig.api_key = self.apiK

        for code in self.qdcodes:
            logger.info("Debug: code: " + code)
            if self.dtype == 'tb':
                ext = code.split("_")
                logger.info("Debug: ext: " + str(ext[1]))
                qdata = quandl.Datatable(str(ext[0]) + '/' +
                                         str(ext[1])).data()
                latest = str(qdata.meta['end_date'])
                logger.info("Debug: latest: " + latest)
                qdata = quandl.Datatable(str(ext[0]) + '/' + str(ext[1])).data(
                    params={'start_date': latest})
            else:
                dtable = self.tgtdata
                if len(dtable) < 3:
                    dtable = dtable + str(dtable)[-1]
                table = self.dynamodb.Table(dtable)
                resp = table.scan(FilterExpression=Key('type').eq(code))
                qdata = quandl.Dataset(self.tgtdata + '/' + code).data()
                count = int(resp['Count'])

                if count < 1:
                    last = str(qdata.meta['start_date'])
                else:
                    last = resp['Items'][-1]['date']
                latest = str(qdata.meta['end_date'])
                qdata = quandl.Dataset(self.tgtdata + '/' +
                                       code).data(params={
                                           'start_date': last,
                                           'end_date': latest
                                       })
            headers = qdata.column_names
            logger.info("Debug: headers: " + str(headers))
            qdata_list = qdata.to_list()
            qlen = len(qdata_list)
            qidx = 0  #qdata index

            if self.dtype == 'ts':  #set the date type fields and update index
                headers[0] = 'date'

            for i in range(qidx, qlen):  #for each q data index
                item = {}
                if self.dtype == 'ts':
                    item = {"type": code}
                hlen = len(headers)
                for h in range(0, hlen):
                    item[headers[h]] = str(qdata_list[i][h])

                # Define dtable to table name meets 3 char minimum
                dtable = self.tgtdata
                if len(dtable) < 3:
                    dtable = dtable + str(dtable)[-1]
                table = self.dynamodb.Table(dtable)
                item = json.dumps(item)
                resp = table.put_item(Item=json.loads(item))
                logger.info("put_item response...")
                logger.info(json.dumps(resp, indent=4, cls=DecimalEncoder))
Пример #2
0
def before_trading_start(context, data):
    # May need to increase the number of stocks
    num_stocks = 50
    context.fundamental_df = pipeline_output('fundamentals')
    # Get blacklist of companies which returns a list of SIDs
    blacklist = context.contract.getBlacklist()
    set_do_not_order_list(blacklist)
    # get current balance to determine capital_base
    context.capital_base = context.contract.getBalance()
    # update quandl fundamentals
    context.fundamentals_quandl = quandl.Datatable('SF0').data().to_numpy()
Пример #3
0
    def apply(self):
        
        if self._subparser_name == 'test':
            self._manager = WatchlistManager()
            
            self._manager.addStock("ABC")
            self._manager.addStock("123")
            self._manager.addStock("UTR")
            
            self._manager.showStockDf()
            
            self._manager.removeStock("ABC")
            self._manager.addStock("XYZ")
            
            self._manager.showStockDf()
        
        elif self._subparser_name == 'apikey':
            
            yaml_dict = yaml.load(open('config/api_key.yaml'), Loader=yaml.CLoader)
        
            print(yaml_dict['api_key'])
            
        elif self._subparser_name == 'quandl':
            
            yaml_dict = yaml.load(open('config/api_key.yaml'), Loader=yaml.CLoader)
            
            key = yaml_dict['api_key']
            
            if key == 'YOUR_KEY_HERE':
                print('Error: The user needs to put their API Key for this software in config/api_key.yaml. See README.')
                _sys.exit()
            else:
                quandl.ApiConfig.api_key = key

            #data = quandl.Dataset('WIKI/AAPL').data(params={ 'limit': 1, 'page' : 2 })[0]
            data = quandl.Datatable('ZACKS/P').data(params={'ticker': 'AAPL'})
            
            for i in data.column_names:
                print(i)
                
            #print(data.data_fields())
            
            print(data)
        
        elif self._subparser_name == 'gui':
            self._run_gui = True
Пример #4
0
    def get_qmj():
        today = datetime.today()
        daily_data_date = (today - timedelta(100)).strftime('%Y-%m-%d')

        data_list = []
        cursor_id = None
        while True:
            data = quandl.Datatable('SHARADAR/SF1').data(
                params={
                    'dimension': 'ARQ',
                    'datekey': {
                        'gte': daily_data_date
                    },
                    'qopts': {
                        'columns':
                        ['datekey', 'ticker', 'revenue', 'cor', 'assets']
                    }
                })
            cursor_id = data.meta['next_cursor_id']
            data_list.append(data)
            if cursor_id is None:
                break
        data = data.to_pandas()
        data = data.loc[data.groupby('ticker').datekey.idxmax(), :]
        data['qmj'] = (data.revenue - data.cor) / data.assets
        qmj = data.qmj**(1 / 3)
        data.qmj = qmj
        data.index = data['ticker'].values
        data = data.drop(['datekey', 'revenue', 'cor', 'assets'], axis=1)
        data = data.rename(columns={'ticker': 'symbol'})
        qmjdf = pd.DataFrame(index=data.symbol,
                             data={
                                 'qmj_t01': data.qmj,
                                 'qmj_t02': data.qmj,
                                 'qmj_t03': data.qmj,
                                 'qmj_t04': data.qmj,
                                 'qmj_t05': data.qmj,
                                 'qmj_t06': data.qmj,
                                 'qmj_t07': data.qmj,
                                 'qmj_t08': data.qmj,
                                 'qmj_t09': data.qmj,
                                 'qmj_t10': data.qmj,
                                 'symbol': data.symbol
                             })
        return qmjdf
    def fetchds(self):
        quandl.ApiConfig.api_key = self.apiK

        for code in self.qdcodes:
            logger.info("Debug: code: " + code)
            if self.dtype == 'tb':
                ext = code.split("_")
                logger.info("Debug: ext: " + str(ext[1]))
                qdata = quandl.Datatable(str(ext[0]) + '/' +
                                         str(ext[1])).data()
            else:
                qdata = quandl.Dataset(self.tgtdata + '/' + code).data()
            headers = qdata.column_names
            logger.info("Debug: headers: " + str(headers))
            qdata_list = qdata.to_list()
            qlen = len(qdata_list)

            qidx = 0  #qdata index

            if self.dtype == 'ts':  #set the date type fields and update index
                headers[0] = 'date'

            for i in range(qidx, qlen):  #for each q data index
                item = {}
                if self.dtype == 'ts':
                    item = {"type": code}
                hlen = len(headers)

                for h in range(0, hlen):
                    item[headers[h]] = str(qdata_list[i][h])

                # Define dtable to table name meets 3 char minimum
                dtable = self.tgtdata
                if len(dtable) < 3:
                    dtable = dtable + str(dtable)[-1]

                table = self.dynamodb.Table(dtable)
                item = json.dumps(item)
                resp = table.put_item(Item=json.loads(item))
                logger.info("put_item response...")
                logger.info(json.dumps(resp, indent=4, cls=DecimalEncoder))
Пример #6
0
 def get_table_metadata(self):
     '''Make a metadata requestfor a specific table'''
     metadata = quandl.Datatable(self.datatable_code).data().meta
     return metadata