Skip to main content
inlined screenshot
Source Link
karel
  • 6k
  • 63
  • 59
  • 60

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.

Problem visualization

How can I possibly do this?

Thanks for your help!

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.

How can I possibly do this?

Thanks for your help!

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.

Problem visualization

How can I possibly do this?

added 1339 characters in body; edited title
Source Link

Track the historic of a time series for a market sentiment trading strategy. Error: argument of type 'numpy.bool_' is not iterable

 for i in range(data.shape[0]) :

 list1       
        Zone_1 = []data.loc[i,"Market Sentiment"] > data.loc[i,'Upper Bound']
    tracker    Zone_2 = []data.loc[i,"Market Sentiment"] > data.loc[i,'Average Sentiment'] and data.loc[i,"Market Sentiment"] <= data.loc[i,'Upper Bound']
    for i in range( Zone_3 = data.shape[0])loc[i,"Market :Sentiment"] > data.loc[i,'Lower Bound'] and data.loc[i,"Market Sentiment"] <= data.loc[i,'Average Sentiment']
        ifZone_4 = data.loc[i,"Market Sentiment"] <= data.loc[i,'Lower Bound']
        
        if Zone_1:
            tracker = "n"
            list1.append(data.loc[i,'HS300'risk Indexfree Return']rate']) #category 
 4           
        elif Zone_2 and data.loc[i-1,"Market Sentiment"] >in Zone_1:
            tracker = 'down'
            list1.append(data.loc[i,'Lower'risk Bound']free rate']) 
        elif Zone_2 and data.loc[i-1,"Market Sentiment"] <=in Zone_2:
            if data.loc[i-1,'Average'tracker'] Sentiment']== 'down':
                list1.append(data.loc[i,"risk'HS300 Index Return'])
            else:
                list1.append(data.loc[i,'risk free rate"]rate']) 
 #category 3      
        elif Zone_2 and data.loc[i-1,"Market'Market Sentiment"]Sentiment'] >in Zone_3:
            tracker = 'up'
            list1.append(data.loc[i,'Average'HS300 Index Return'])
            
        elif Zone_3 and data.loc[i-1,'Market Sentiment'] in Zone_2:
            tracker = 'down'
            list1.append(data.loc[i,"risk free rate"])
            
        elif Zone_3 and data.loc[i-1,"Market'Market Sentiment"]Sentiment'] <=in Zone_3:
            if data.loc[i-1,'Upper'tracker'] Bound']== 'down':
                list1.append(data.loc[i,'risk free rate'])
            else:
                list1.append(data.loc[i,'HS300 Index Return']) 
 #category 2          list1.append(data.loc[i,'HS300 Index Return'])
            
        elif Zone_3 and data.loc[i-1,"Market'Market Sentiment"]Sentiment'] >in Zone_4:
            tracker = 'up'
            list1.append(data.loc[i,'Upper'HS300 Bound']Index Return'])
            
        elif Zone_4:
            list1.append(data.loc[i,"risk"HS300 freeIndex rate"]Return"]) #category 

 1   data['Strategy Return'] = list1
    data['Tracker'] = tracker
    pd.options.display.float_format = '{:.4f}'.format
    return data

Track the historic of a time series for a market sentiment trading strategy


 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

Track the historic of a time series for a market sentiment trading strategy. Error: argument of type 'numpy.bool_' is not iterable

 for i in range(data.shape[0]) :

        
        Zone_1 = data.loc[i,"Market Sentiment"] > data.loc[i,'Upper Bound']
        Zone_2 = data.loc[i,"Market Sentiment"] > data.loc[i,'Average Sentiment'] and data.loc[i,"Market Sentiment"] <= data.loc[i,'Upper Bound']
        Zone_3 = data.loc[i,"Market Sentiment"] > data.loc[i,'Lower Bound'] and data.loc[i,"Market Sentiment"] <= data.loc[i,'Average Sentiment']
        Zone_4 = data.loc[i,"Market Sentiment"] <= data.loc[i,'Lower Bound']
        
        if Zone_1:
            tracker = "n"
            list1.append(data.loc[i,'risk free rate'])  
            
        elif Zone_2 and data.loc[i-1,"Market Sentiment"] in Zone_1:
            tracker = 'down'
            list1.append(data.loc[i,'risk free rate']) 
        elif Zone_2 and data.loc[i-1,"Market Sentiment"] in Zone_2:
            if data.loc[i-1,'tracker'] == 'down':
                list1.append(data.loc[i,'HS300 Index Return'])
            else:
                list1.append(data.loc[i,'risk free rate']) 
        
        elif Zone_2 and data.loc[i-1,'Market Sentiment'] in Zone_3:
            tracker = 'up'
            list1.append(data.loc[i,'HS300 Index Return'])
            
        elif Zone_3 and data.loc[i-1,'Market Sentiment'] in Zone_2:
            tracker = 'down'
            list1.append(data.loc[i,"risk free rate"])
            
        elif Zone_3 and data.loc[i-1,'Market Sentiment'] in Zone_3:
            if data.loc[i-1,'tracker'] == 'down':
                list1.append(data.loc[i,'risk free rate'])
            else:
                list1.append(data.loc[i,'HS300 Index Return']) 
            list1.append(data.loc[i,'HS300 Index Return'])
            
        elif Zone_3 and data.loc[i-1,'Market Sentiment'] in Zone_4:
            tracker = 'up'
            list1.append(data.loc[i,'HS300 Index Return'])
            
        elif Zone_4:
            list1.append(data.loc[i,"HS300 Index Return"])  

    data['Strategy Return'] = list1
    data['Tracker'] = tracker
    pd.options.display.float_format = '{:.4f}'.format
    return data
Source Link

Track the historic of a time series for a market sentiment trading strategy

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