Question about the computation in the return of the pair trading strategy

Course Name: Mean Reversion Strategies In Python, Section No: 8, Unit No: 2, Unit type: Notebook

Hi, I do not understand why the daily return is computed as the following:

# Calculate portfolio value
df['portfolio_value'] = df.GLD + abs(model.params[0]) * df.GDX

# Calculate daily returns
df['daily_returns'] = df.spread_diff / df.portfolio_value.shift(1)

Are there more explanation about the above computation? Thanks! 

Hi,



Here's a line by line explanation of how the daily returns are calculated:

 

df['spread_diff'] = df.spread - df.spread.shift(1)

First, we compute the difference between today's spread and yesterday's spread. It helps track how the spread changes from one day to the next.

 

df['portfolio_value'] = df.GLD + abs(model.params[0]) * df.GDX

Then, we get the portfolio value which is the sum of GLD and the absolute value of the hedge ratio, which is stored in model.params, multiplied by GDX. With this you will get the total value of the portfolio.

 

df['daily_returns'] = df.spread_diff / df.portfolio_value.shift(1)

Lastly, this line calculates how much your portfolio has changed in value from one day to the next. It takes the difference in the spread and divides it by the previous day's total portfolio value. This gives you the percentage change in your portfolio value on a daily basis.



So basically, the daily returns give you an idea of how the portfolio is performing on a day-to-day basis, while considering the changes in the spread.



Hope this helps!



Thanks

Rushda