Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Make a security list and grab the data
- # Notice the "field" arguement, we are only grabing the prices here (same as closing prices)
- # Check out the last 5 rows using .tail()
- security_list = ['spy','xlk','xly','vnq','xlp','xlv','xli','xlf','xlb']
- df = get_pricing(security_list, start_date='2017-01-01', end_date='2019-09-18', frequency='daily', fields='price')
- df.tail()
- # Calculate rolling 12 month percent changes and check out last 5 days
- rolling_12_month_momentum = df.pct_change(252)
- rolling_12_month_momentum.tail()
- # If you only want the most recent day (momentum as of 09/18/2019) use iloc[-1]:
- most_recent_momentum_measures = df.pct_change(252).iloc[-1]
- most_recent_momentum_measures
Add Comment
Please, Sign In to add comment