Esempio n. 1
0
class streamer(object):
    def __init__(self):
        """
        Reads in credentials from the user's .netrc file and creates
        a Datastream object to be used in fetching data.
        """
        rc = netrc()
        uname, account, passwd = rc.authenticators('datastream')
        self.DWE = Datastream(username=uname, password=passwd)

    def _fetch_individual_code(self, code, fields=None, **kwargs):
        """
        Internal function to fetch the data.
        It offers two advantages to the original:
            (1) It raises a warning, not an Exception when it has problems.
                This is primarily useful when you have a list of codes and
                want to know when one fails, but move on.
            (2) It renames the colums so that they have the code as a part
                of the column name, not just the field.  This 
        """
        print(code) #TEMP
        try:
            df = self.DWE.fetch(code, fields=fields, **kwargs)
        except Exception, e:
            df = None
            warnings.warn(("Unable to load {} \n".format(code) 
                + str(e.message) + '\n'))
        else:
Esempio n. 2
0
 def __init__(self):
     """
     Reads in credentials from the user's .netrc file and creates
     a Datastream object to be used in fetching data.
     """
     rc = netrc()
     uname, account, passwd = rc.authenticators('datastream')
     self.DWE = Datastream(username=uname, password=passwd)
import pydatastream
from pydatastream import Datastream
import os
import csv

credentials = {}
with open('credentials.txt', 'r') as credentials_file:
  line = credentials_file.readline().split(',')
  credentials['username'] = line[0]
  credentials['password'] = line[1]

DWE = Datastream(username=credentials['username'], password=credentials['password'])
DWE.raise_on_error = False
INACTIVE_DATE = ['WC07015']

DATATYPES = ['P', 'MV', 'PE', 'VA', 'VO', 'PTBV', 'MTBV']

shenzhen_equities_symbols = []

with open('shenzhen-equities-rmb.csv', 'r') as shenzhen_equities_csv:
    reader = csv.DictReader(shenzhen_equities_csv)
    shenzhen_equities_symbols = [line['Symbol'] for line in reader]

    for stock_mnem in shenzhen_equities_symbols:
      filename = 'stock_%s_%s.csv' % ('shenzhen', stock_mnem)
      filename = filename.replace(':', '-')

      if os.path.isfile('csvs/%s' % filename):
        print 'Stock data already exists for %s' % (stock_mnem)
        continue
Esempio n. 4
0
import pandas as pd
from datetime import datetime
from pydatastream import Datastream
from utils import write_pickle
from private import DS_USERNAME, DS_PASSWORD

DWE = Datastream(username=DS_USERNAME, password=DS_PASSWORD)


def get_prices(mnem, date_from, date_to):
    template = '{}(RI)~~USD'.format(mnem)
    data = DWE.fetch(template, date_from=date_from, date_to=date_to)
    return data['P'].rename(mnem)


holdings = pd.read_csv('assets/holdings.csv')
date_from = datetime(2016, 12, 31)
date_to = datetime(2017, 12, 31)
prices = []
exceptions = []
for i, row in holdings.iterrows():
    try:
        print(i / len(holdings))
        prices.append(get_prices(row['ISIN'], date_from, date_to))
    except Exception as error:
        print(error)
        print(row['ISIN'])
        exceptions.append(row['ISIN'])

print('Re-download exceptions')
for isin in exceptions:
Esempio n. 5
0
File: x2a.py Progetto: gfolgori/x1
__author__ = 'gio'

from sqlalchemy import create_engine
engine = create_engine('postgresql://localhost/gio')
import matplotlib.pyplot as plt
from pydatastream import Datastream
DWE = Datastream(username="******", password="******")

data = DWE.get_price('@AAPL', date_from='2008', date_to='2016')
print data.head()

plt.plot(data['P'])
plt.ylabel('Apple')
plt.show()
Esempio n. 6
0
def DatastreamInit():
    from pydatastream import Datastream
    key = getkey("datastream")
    return Datastream(username=key.user, password=key.password)
Esempio n. 7
0
File: x3a.py Progetto: gfolgori/x1
import pg8000
from pydatastream import Datastream

DWE = Datastream(username="******", password="******")

conn = pg8000.connect(user="******", password="")
cursor = conn.cursor()
cursor.execute("SELECT isin FROM TRIAL1")
results = cursor.fetchall()
print(results)

b = type(results)
print (b)

for item in results:
    print (item)
    DWE.raise_on_error = False
    data = DWE.get_price(item, date_from='2008', date_to='2016')
    a = type (data)
    print (a)
    print(data)
Esempio n. 8
0
if numOfArgs != 3:
		print "Please run this python script with username,password and input file location in that order respectively."
		exit()

#Setup login credentials and input file location
username = str(sys.argv[1])
pw = str(sys.argv[2])
input_file_loc = dir_input + str(sys.argv[3])

#Ensure that the input file location exists
if ( not os.path.isfile(str(input_file_loc)) ):
	print "The file " + str(input_file_loc) + " does not exist."
	exit()

#login credentials to datastream
DWE = Datastream(username=username,password=pw)
#other info from datastream
info = DWE.system_info()
subscribed_sources = DWE.sources()

#replace missing data with NaNs
DWE.raise_on_error = False

#get all codes, groups, start dates from input file 
with open(input_file_loc,'r') as input_file:
    symbol_ref = json.load(input_file)

#download timestamp
download_date = {'Custom_Download_Date' : datetime.datetime.now().isoformat()}

#calculate time taken for entire process