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?


Best Answer

  • aramyan.h
    Answer ✓

    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

Answers