Skip to content

Instantly share code, notes, and snippets.

@erykml
Created October 29, 2018 11:52
Show Gist options
  • Save erykml/4db01af47e03045847ae9c2bf73ce84f to your computer and use it in GitHub Desktop.
Save erykml/4db01af47e03045847ae9c2bf73ce84f to your computer and use it in GitHub Desktop.
import quandl
# authentication ----
quandl_key = 'key' # paste your own API key here :)
quandl.ApiConfig.api_key = quandl_key
df = quandl.get('WIKI/MSFT', start_date="2000-01-01", end_date="2017-12-31")
df = df.loc[:, ['Adj. Close']]
df.columns = ['adj_close']
# create simple and log returns, multiplied by 100 for convenience
df['simple_rtn'] = 100 * df.adj_close.pct_change()
df['log_rtn'] = 100 * (np.log(df.adj_close) - np.log(df.adj_close.shift(1)))
# dropping NA's in the first row
df.dropna(how = 'any', inplace = True)
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment