The Thomson Reuters Eikon Data API Proxy is a new modern desktop API geared towards Quants and Data Scientists.
The API Proxy is completely integrated in Eikon 4 (Windows) or can be installed as a standalone package in Mac.
import eikon as ek # Data Source
import pandas as pd # Data Management
import cufflinks as cf # Data Visualization
The app id can be obtained from the API Key Generator
ek.set_app_id('AD2833XXXXXXXX')
We can convert across all types of symbology
sedols = ['B1YW440', '0673123', 'B02J639', 'B1XZS82', '0045614', '0053673',
'0989529', '0216238', '0969703', '0263494']
ek.get_symbology(sedols,to_symbol_type=['ISIN','RIC'])
ISIN | RIC | primaryRIC | |
---|---|---|---|
0045614 | GB0000456144 | ANTO.L | ANTO.L |
0053673 | GB0000536739 | AHT.L | AHT.L |
0216238 | GB0002162385 | AV.L | AV.L |
0263494 | GB0002634946 | BAES.L | BAES.L |
0673123 | GB0006731235 | ABF.L | ABF.L |
0969703 | GB0009697037 | BAB.L | BAB.L |
0989529 | GB0009895292 | AZN.L | AZN.L |
B02J639 | GB00B02J6398 | ADML.L | ADML.L |
B1XZS82 | GB00B1XZS820 | AAL.L | AAL.L |
B1YW440 | GB00B1YW4409 | III.L | III.L |
Getting the top news for Apple where Trump is mentioned
ek.get_news_headlines('R:.SPX AND "Comey" AND Language:LEN',count=5)
versionCreated | text | storyId | sourceCode | |
---|---|---|---|---|
2017-05-10 15:25:27 | 2017-05-10 15:25:27 | US STOCKS-Wall St weighed down by weak earning... | urn:newsml:reuters.com:20170510:nL4N1IC4KW:1 | NS:RTRS |
2017-05-10 13:56:42 | 2017-05-10 13:56:42 | US STOCKS-Disney results, Comey sacking weigh ... | urn:newsml:reuters.com:20170510:nL4N1IC4E9:1 | NS:RTRS |
2017-05-10 13:32:37 | 2017-05-10 13:32:37 | US STOCKS SNAPSHOT-Wall St opens slightly lowe... | urn:newsml:reuters.com:20170510:nL4N1IC4FL:1 | NS:RTRS |
2017-05-10 12:44:16 | 2017-05-10 12:44:16 | US STOCKS-Wall St to open slightly lower after... | urn:newsml:reuters.com:20170510:nL4N1IC3XM:1 | NS:RTRS |
2017-05-10 11:32:06 | 2017-05-10 11:32:06 | US STOCKS-Futures fall after FBI Chief Comey s... | urn:newsml:reuters.com:20170510:nL4N1IC3GN:1 | NS:RTRS |
And then we can retrieve the actual story. The stories are delivered in HTML - which means we can display them formatted in our Notebook.
from IPython.display import display,HTML
display(HTML(ek.get_news_story('urn:newsml:reuters.com:20170510:nL4N1IC4KW')))
Adds details, comments, updates prices
By Yashaswini Swamynathan
May 10 (Reuters) - U.S. stocks slipped on Wednesday, weighed down by a string of weak corporate earnings, while investors turned cautious after President Donald Trump fired his FBI chief.
Trump said he fired FBI Director James Comey, who had been leading an investigation into his 2016 presidential campaign's possible collusion with Russia, over his handling of an email scandal involving then-Democratic presidential nominee Hillary Clinton. (Full Story)
Analysts say the development could distract Trump from pursuing his promises, including the highly anticipated reform of the U.S. tax code.
"I think the market is probably going to work past the Comey news unless it spirals into a bigger issue where it starts to threaten the Trump agenda," Robert Pavlik, chief market strategist at Boston Private Wealth.
Demand for safe-haven assets like gold, bonds and the Japanese yen rose, while the dollar fell.
At 10:59 a.m. ET (1459 GMT), the Dow Jones Industrial Average .DJI was down 34.4 points, or 0.16 percent, at 20,941.38, the S&P 500 .SPX was down 1.67 points, or 0.07 percent, at 2,395.25 and the Nasdaq Composite .IXIC was down 14.35 points, or 0.23 percent, at 6,106.23.
Six of the 11 major S&P 500 sectors were lower, with healthcare .SPXHC and consumer discretionary .SPLRCD sectors dropping the most. Energy .SPNY was up 1.4 percent on the back of higher oil prices.
Disney DIS.N fell 2.5 percent and was the top drag on the Dow and the S&P 500 after the media company reported lower-than-expected quarterly revenue and a decline in the number of ESPN subscribers. (Full Story)
Allergan AGN.N dropped 3.2 percent to $230.75 after the Botox-maker posted a quarterly loss as it took a write down on the value of its stake in Teva Pharmaceutical TEVA.TA. (Full Story)
Priceline PCLN.O tumbled 5 percent to $1,815 after the travel website operator forecast current-quarter earnings below analysts' expectations.
One bright spot was Nvidia NVDA.O, which surged 14 percent after the chipmaker reported a better-than-expected jump in quarterly revenue. Shares of rival AMD AMD.O also rose. (Full Story)
Advancing issues outnumbered decliners on the NYSE by 1,599 to 1,177. On the Nasdaq, 1,483 issues fell and 1,130 advanced.
The S&P 500 index showed 19 52-week highs and one low, while the Nasdaq recorded 85 highs and 46 lows.
(Reporting by Yashaswini Swamynathan in Bengaluru; Editing by Anil D'Silva)
(( yashaswini.swamynathan@thomsonreuters.com ; within U.S. +1 646 223 8780, outside U.S. +91 80 6749 2405; Reuters Messaging: yashaswini.swamynathan.thomsonreuters.com@reuters.net ))
Keywords: USA-STOCKS/ (UPDATE 3)
Using ek.get_timeseries
to retrieve 2 years of Microsoft Data
msft=ek.get_timeseries('MSFT.O',fields='CLOSE',start_date='2015-05-04',end_date='2017-05-04')
msft.head()
MSFT.O | CLOSE |
---|---|
Date | |
2015-05-04 | 48.24 |
2015-05-05 | 47.60 |
2015-05-06 | 46.28 |
2015-05-07 | 46.70 |
2015-05-08 | 47.75 |
Getting a best fit line
msft.iplot(kind='lines',color='blue',width=2,bestfit=True,title='Bestfit')
Adding a Quarterly Results Event to a Microsoft Chart
# All annotations have basic support for HTML tags
ann={'2016-01-29':'Microsoft Reports Quarterly Results Above Expectations' \
'<BR>Lowering Outlook, Price Target and Rating.'}
msft.iplot(kind='lines',annotations=ann,textangle=0,title='Microsoft - Estimate Revisions')
We would like to retrieve Net (Adjusted) Dividends and overlay this information over the price chart of Microsoft.
# We will retreive Net and Gross Dividend for From May 2015 to April 2017
fields=['TR.DivExDate','TR.DivAdjustedGross','TR.DivAdjustedNet']
divs,err=ek.get_data('MSFT.O',fields=fields,
parameters={'SDate':'05May15','EDate':'30Apr17','DateType':'AD'})
Plotting the results
cf.tools.merge_figures([msft_price,msft_divs]).iplot(legend=False)
We will retrieve data from 2015 for both Microsoft and SPX
performance=ek.get_timeseries(['MSFT.O','.SPX'],
fields='CLOSE',
start_date='2015-05-04',
end_date='2017-05-04')
performance.head()
CLOSE | MSFT.O | .SPX |
---|---|---|
Date | ||
2015-05-04 | 48.24 | 2114.49 |
2015-05-05 | 47.60 | 2089.46 |
2015-05-06 | 46.28 | 2080.15 |
2015-05-07 | 46.70 | 2088.00 |
2015-05-08 | 47.75 | 2116.10 |
Normalizing (Percent change from day 0) the values for both instruments and charting the performance.
performance.normalize().iplot(kind='spread',title='Microsoft Performance vs SPX',
width=2,showgrid=False)
We will get the 600 companies and the 1 month return for each of them
# Support for chains
df,err=ek.get_data('0#.STOXX',['TR.HQCountryCode','TR.TRBCEconomicSector','TR.TotalReturn1Mo'])
df.head()
Instrument | Country ISO Code of Headquarters | TRBC Economic Sector Name | 1 Month Total Return | |
---|---|---|---|---|
0 | III.L | GB | Financials | 8.661417 |
1 | A2.MI | IT | Utilities | 9.224012 |
2 | AAAA.L | GB | Consumer Non-Cyclicals | -4.866270 |
3 | AALB.AS | NL | Industrials | 4.973059 |
4 | ARLG.DE | DE | Financials | 10.725643 |
Group them by Country/Sector
group=df.groupby(['Country ISO Code of Headquarters','TRBC Economic Sector Name'])
matrix=group.mean().unstack()['1 Month Total Return']
And plot the results
matrix.iplot(kind='heatmap',colorscale='rdylgn',margin={'l':200},
title='1 Month Mean Returns in Europe')
amz_chg=get_estimates('AMZN.O',fields=['EPS','Revenue'],periods=4)
amz_chg
EPS | Revenue | |
---|---|---|
FY1/FY0 | 36.604490 | 22.162373 |
FY2/FY1 | 70.051631 | 20.796608 |
FY3/FY2 | 63.353133 | 18.761467 |
FY4/FY3 | 44.277113 | 16.447569 |
amz_chg.iplot(kind='bar',title='Amazon Estimates YoY Changes',colorscale='-brbg',
yTitle='Percent Change',theme='ggplot')
We first retrieve the peers of Amazon (including Amazon)
peers,err=ek.get_data(['PEERS(AMZN.O)','AMZN.O'],['TR.CommonName','TR.CompanyMarketCap'])
And get the top 10 by Market Cap
peers=peers.sort_values(by='Company Market Cap',ascending=False)[:10]
peers
Instrument | Company Common Name | Company Market Cap | |
---|---|---|---|
29 | AAPL.OQ | Apple Inc | 7.990731e+11 |
10 | GOOGL.OQ | Alphabet Inc | 6.514673e+11 |
50 | AMZN.O | Amazon.com Inc | 4.535748e+11 |
11 | FB.OQ | Facebook Inc | 4.355670e+11 |
1 | BABA.N | Alibaba Group Holding Ltd | 2.968219e+11 |
2 | WMT.N | Wal-Mart Stores Inc | 2.325204e+11 |
15 | PCLN.OQ | Priceline Group Inc | 8.974246e+10 |
17 | NFLX.OQ | Netflix Inc | 6.908139e+10 |
30 | PYPL.OQ | PayPal Holdings Inc | 5.981066e+10 |
19 | YHOO.OQ | Yahoo! Inc | 4.733169e+10 |
peers_df.iplot(kind='bar',colorscale='-purples',title='Amazon Peers - EPS Est % Change YoY',
yTitle='Percentage')
First we define the Universe over which the screening will be performed
# From the Russell 1000 Growth Index as strarting universe
# With a Market Cap between 5B and 20B USD
# With Analyst recommendations greater than 80 and Price to Mid Term component greater than 30
# And EPS >=10 and Revenue >=5 Smart Estimates (All in USD)
universe='SCREEN(U(IN(indices(4387903/*Russell 1000 Growth*/))), ' \
'TR.CompanyMarketCap>=5000000000, TR.CompanyMarketCap<20000000000, ' \
'TR.ARM100Region>=80, TR.PriceMoMidTermComponent>=30, ' \
'TR.EPSSmartEstLastYrGrowth>=10, TR.RevenueSmartEstLastYrGrowth>=5, CURN=USD)'
fields=['TR.CommonName','TR.PricePctChg52W',
'TR.CompanyMarketCap','TR.Revenue(Period:FY0)',
'TR.ARM100Region','TR.TRBCEconomicSector']
df,err=ek.get_data(universe,fields=fields)
We get the top 50 companies by Market Cap
df=df.sort_values(by='Company Market Cap',ascending=False)[:50]
df.head()
Instrument | Company Common Name | 52-week Price PCT Change | Company Market Cap | Revenue | Analyst Revisions Model Region Rank | TRBC Economic Sector Name | |
---|---|---|---|---|---|---|---|
3 | SWKS.OQ | Skyworks Solutions Inc | 58.032686 | 1.891377e+10 | 3.289000e+09 | 88 | Technology |
22 | CFG.N | Citizens Financial Group Inc | 66.413238 | 1.884859e+10 | NaN | 98 | Financials |
25 | WDAY.N | Workday Inc | 24.183997 | 1.856076e+10 | 1.569407e+09 | 80 | Technology |
10 | KLAC.OQ | KLA-Tencor Corp | 44.251969 | 1.579540e+10 | 2.984493e+09 | 82 | Technology |
9 | IDXX.OQ | IDEXX Laboratories Inc | 85.639449 | 1.436500e+10 | 1.775423e+09 | 91 | Healthcare |
df.iplot(kind='bubble',x='52-week Price PCT Change',y='Revenue',size='Company Market Cap',
text='text',categories='TRBC Economic Sector Name',xTitle='52-week Price PCT Change',
yTitle='Revenue',zerolinewidth=2,zerolinecolor='darkgrey',colorscale='set3')
We can add another axis (z) and see them in a 3D form
df.iplot(kind='bubble3d',x='52-week Price PCT Change',y='Revenue',z='Analyst Revisions Model Region Rank',
size='Company Market Cap',text='Company Common Name',categories='TRBC Economic Sector Name',
xTitle='52-week Price PCT Change',yTitle='Revenue',zTitle='Analyst Recs',zerolinewidth=3,
zerolinecolor='darkgrey',colorscale='set3',width=0)
We retrieve the analysts' recommendations for the FTSE
recs,err=ek.get_data('0#.FTSE',['TR.CompanyName','TR.NumOfBuy','TR.NumOfHold','TR.NumOfSell'])
recs.head()
Buy | Hold | Sell | |
---|---|---|---|
Company Name | |||
Pearson PLC | 0.058824 | 0.647059 | 0.294118 |
Intu Properties PLC | 0.062500 | 0.437500 | 0.500000 |
WM Morrison Supermarkets PLC | 0.066667 | 0.533333 | 0.400000 |
Next PLC | 0.095238 | 0.666667 | 0.238095 |
Standard Chartered PLC | 0.105263 | 0.368421 | 0.526316 |
And we chart the results for all companies
recs.iplot(kind='barh',barmode='stack',margin={'l':300},dimensions=(1000,600),
colors=['green','blue','pink'])
Plotting the sector results
recs.iplot(kind='barh',barmode='stack',margin={'l':200},colors=['green','blue','pink'],
title='FTSE Analyst Recommendations by Sector')
Presidential Inauguration Dates
potus={'Barack Obama': '2009-01-20',
'Donald J. Trump': '2017-01-20',
'George Bush': '1989-01-20',
'William J. Clinton': '1993-01-20',
'George W. Bush': '2001-01-20'}
potus_df={}
for p in potus:
# Getting the SPX closing values for the first 100 days
df=ek.get_timeseries('.SPX','CLOSE',
start_date=potus[p],
end_date=cf.date_tools.getDatefromDate(potus[p],100,'%Y-%m-%d'))
potus_df[p]=df['CLOSE'].values
df.pct_change(1).iplot(kind='histogram',colorscale='set1',width=0.5,legend='bottom',
title='Potus First 100 Days<br>1d Returns Distribution')
df.pct_change(1).iplot(kind='histogram',colorscale='set1',width=0.5,legend='bottom',
title='Potus First 100 Days<br>1d Returns Distribution',subplots=True,
shared_xaxes=True)
df.normalize().iplot(colorscale='set1',width=2,legend='bottom',title='First 100 Days POTUS Returns (SPX)')
Analyzing USD/GBP
# 7 Years of OHLC Weekly data
gbp=ek.get_timeseries('gbp=',fields='*',start_date='2010-01-01',interval='weekly')
Optimized for immediate charting
qf.iplot()
SPX Long Term
spx=ek.get_timeseries('.spx',fields='*',start_date='2010-01-01',interval='weekly')
qf.iplot()
Technical Analysis over Apple
aapl=ek.get_timeseries('aapl.o',fields='*',start_date='2015-01-01')
qf=cf.QuantFig(aapl,legend='top',name='Apple')
qf.add_volume(colorchange=True)
qf.add_sma([21,55,144],colors=['green','orange','blue'],width=1)
Simple Moving Averages
qf.iplot()
Adding Bollinger Bands, Volume, MACD and RSI
qf.iplot(showlegend=False,title='Apple')
Retrieving all Dry Bulk (Bulkers) currently transporting Iron Ore alongside with its geographical coordinates and tonnage information.
fields=['TR.AssetName','TR.AssetLocationLatitude','TR.AssetLocationLongitude',
'TR.AssetDestinationPort','TR.AssetDWT']
df,err=ek.get_data('SCREEN(U(IN(lists(337598580))))',fields)
df.head()
Instrument | Name | Latitude | Longitude | Destination Port | Dead weight tonnage | |
---|---|---|---|---|---|---|
0 | C}BL7309523849 | AANYA | -20.228800 | -11.335228 | Singapore | 179628 |
1 | C}BT7309789907 | ABOY KARLIE | -7.460428 | 77.895513 | Singapore | 207566 |
2 | C}BT7309791966 | ABOY LAETITIA | -9.392873 | 74.640693 | Singapore | 208000 |
3 | C}BL7309510257 | ABY SCARLETT | -7.972047 | 151.849827 | Cigading (Banten) | 175649 |
4 | C}BO7309729008 | ABY VIRGINIA | -21.803158 | -9.528020 | Port Louis | 81061 |
Plotting all vessels Colorscale indicated Dead Weight Tonnage
fig.iplot()