sector_list = ['XLY', # XLY Consumer Discretionary
'XLF', # XLF Financial SPDR Fund
'XLK', # XLK Technology SPDR Fund
'XLE', # XLE Energy SPDR Fund
'XLV', # XLV Health Care SPRD Fund
'XLI', # XLI Industrial SPDR Fund
'XLP', # XLP Consumer Staples SPDR Fund
'XLB', # XLB Materials SPDR Fund
'XLU'] # XLU Utilities SPRD Fund
# Price history of each sector etf
p_hist = data.history(sector_list,"price",200,"1d")
#Sort sector_list according to price_history performance
4week_perf = p_hist.iloc[20]-p_hist.iloc[0]
12week_perf = p_hist.iloc[60]-p_hist.iloc[0]
26week_perf = p_hist.iloc[130]-p_hist.iloc[0]
52week_perf = p_hist.iloc[260]-p_hist.iloc[0]
sector_perf_df = pd.dataframe({ '4week_perf' : 4week_perf,
'12week_perf' : 12week_perf,
'26week_perf' : 26week_perf,
'52week_perf' : 52week_perf,})
I am trying to build a dataframe that uses stock symbols for the indexes and 4,12,26, and 52week-performance for the column headings.
I start with a list of sector etfs. sector_list.....
I generate a price history series for each etf. p_hist.....
Then I calculate each performance factor using the locations in the series. 4week_perf = p_hist.iloc[20]-p_hist.iloc[0]......
Finally, I try to place them into the sector performance dataframe. sector_perf_df......
Once my sector dataframe is built, I can find the best performing sectors. Am I on the right track?