Advertisement
cjc5013

Week One Homework

Sep 14th, 2019
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. # Get data for the security “XLK” (Technology Sector SPDR) in the research environment
  2. # Pull data from the beginning of 2017 to the end of 2018 (2 years)
  3. df = get_pricing('xlk' , start_date='2017-01-01' , end_date= '2018-12-31' , frequency='daily' )
  4.  
  5.  
  6. #What was the average daily Low for “XLK” in 2017-2018?
  7. df['low'].mean()
  8.  
  9.  
  10. #What was the highest Close over these 2 years?
  11. df['close_price'].max()
  12.  
  13.  
  14. # What was the lowest Open over these 2 years?
  15. df['open_price'].min()
  16.  
  17.  
  18. # Add a column calculating the 10-day and 50-day moving averages
  19. df['SMA_10_day'] = df['close_price'].rolling(10).mean()
  20. df['SMA_50_day'] = df['close_price'].rolling(50).mean()
  21.  
  22.  
  23. # Create a plot of the closing price, 10-day MA and 50-day MA for 2017-2018.
  24. df[['close_price','SMA_10_day','SMA_50_day']].plot()
  25.  
  26.  
  27. # Calculate the 4-period RSI on your birthday (or the first trading day after your birthday).
  28. # My birthday is September 7th
  29. import talib as ta
  30. df['RSI_4_Period'] = ta.RSI(df['close_price'] , 4)
  31. df['RSI_4_Period'].loc['2018-09-07']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement