Exemplo n.º 1
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:
Exemplo n.º 2
0
def DatastreamInit():
    from pydatastream import Datastream
    key = getkey("datastream")
    return Datastream(username=key.user, password=key.password)