Problem visualization Hello!
I'm developing a market sentiment trading strategy for my Investment class. Basically, the strategy currently consists of selling the market index in Zone 1 and 3 and buying (holding) the market index on Zones 2 and 4. The zones are divided based on three lines : Upper (avg + std deviation), Lower (avg - std deviation) and Avg of a previous calculated Market Sentiment indicator.
What I want to do is to enhance the program by buying the market index once you enter Zone 4 and exiting the market only once you hit Zone 1 and vice-versa. Zone 2 and 3, therefore, have their results based on the where the trend is coming from (if it entered through zone 1 or through zone 4).
How can I possibly do this?
Thanks for your help!
list1 = []
tracker = []
for i in range(data.shape[0]) :
if data.loc[i,"Market Sentiment"] <= data.loc[i,'Lower Bound'] :
list1.append(data.loc[i,'HS300 Index Return']) #category 4
elif data.loc[i,"Market Sentiment"] > data.loc[i,'Lower Bound'] and data.loc[i,"Market Sentiment"] <= data.loc[i,'Average Sentiment']:
list1.append(data.loc[i,"risk free rate"]) #category 3
elif data.loc[i,"Market Sentiment"] > data.loc[i,'Average Sentiment'] and data.loc[i,"Market Sentiment"] <= data.loc[i,'Upper Bound']:
list1.append(data.loc[i,'HS300 Index Return']) #category 2
elif data.loc[i,"Market Sentiment"] > data.loc[i,'Upper Bound']:
list1.append(data.loc[i,"risk free rate"]) #category 1