Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
43 2 5 8

Computation of the correlation between a stock return and a given benchmark

Hi guys,

This is a general question following this thread.

Given a stock (let's say VOWG_p.DE) and a reference index (let's say .STOXX), a customer wants to compute/retrieve the correlation between the day to day return of the stock and the reference index price on a timeframe. Of course the stock returns include the dividends

what does a a python function which uses refinitiv.data library look like?


eikon-data-apiexcelcodebookrefinitiv-data-libraries
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
5.6k 18 2 7

Hi @yaokoffi.kouassi ,


I am afraid there is no direct way of computing the correlation coefficient from the library. If I got your question correct, these are the steps I would take to calculate the coefficient:

1. Get the prices of the stock and the benchmark from Refinitiv.data:

index_price = rd.get_history(universe = '.STOXX', fields='TRDPRC_1', start = '2023-07-01', end = '2023-08-14')
stock_price = rd.get_history(universe =  'VOWG_p.DE', fields='OFF_CLOSE', start = '2023-07-01', end = '2023-08-14')

2. Calculate daily returns:

index_return = index_price['TRDPRC_1'].pct_change().dropna()
stock_return = stock_price['OFF_CLOSE'].pct_change().dropna()

3. Calculate the required correlation coefficient (e.g. Pearson, spearman) using Scipy library:

import scipy.stats
scipy.stats.pearsonr(index_return.values, stock_return.values)

This returns the the coefficient and the p-value:

(0.45796402563762706, 0.012482344923260497)

Hope this helps and please let me know if I missed anything while building my answer.


Best regards,

Haykaz

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
43 2 5 8

Thank you so much @haykaz.aramyan .

This is exactly what I was looking for

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
1.4k 5 3 6

Hi @yaokoffi.kouassi

You can also take the approach with the ADC computation capabilities to calculate beta:

rd.get_data("VOWG_p.DE","RSLOPE('.STOXX',PERCENT_CHG(TR.PriceClose(Sdate=-5Y,Edate=0D,Curn=EUR,Frq=M),Lag=-1M))")

1692003729737.png



1692003729737.png (6.0 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.