Skip to content

Instantly share code, notes, and snippets.

@SajidLhessani
Created September 6, 2021 00:56
Show Gist options
  • Select an option

  • Save SajidLhessani/23cde459d9a2cc789468809fb0e1e030 to your computer and use it in GitHub Desktop.

Select an option

Save SajidLhessani/23cde459d9a2cc789468809fb0e1e030 to your computer and use it in GitHub Desktop.
# Create a column 'Ret' with the calculation of returns
df['Ret'] = (df['Open'].shift(-1)-df['Open'])/df['Open']
# Create n columns and assign
for i in range(1, n):
df['return%i' % i] = df['Ret'].shift(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment