I am attempting to build a function that can identify whether or not the trend of the morning session of a NYSE ticker is 'bullish' or 'bearish', based on the current high/low of day, and which one was made most recently.
an exmaple of two rows of data in my dataset would be:
datetime | open | high | low | close |
---|---|---|---|---|
2021-03-30 09:30:00 | 394.41 | 394.73 | 394.24 | 394.41 |
2021-03-30 09:35:00 | 394.42 | 394.47 | 394.02 | 394.23 |
I believe that I have the logic properly worked out to track what I am seeking a store it properly, but I seem to have a datatype error somewhere in my 'high' column and I am unable to find it. The error I'm getting is:
TypeError: '>' not supported between instances of 'NaTType' and 'float'
I have read that NATType is specific to data/time fields, but I from what I can see the column does appear to have only the datatype 'float' within it, so I don't see why this is coming in to play. I've checked for standard NULL values and none exist, and I'm not sure how to check for NATType values, as the same code spits an error that NATType is not defined.
the actual function I'm trying to get to work:
def determine_trend(data):
high_of_day = data.iloc[0]['high']
low_of_day = data.iloc[0]['low']
trend = 'chop'
new_high = False
new_low = False
for i, row in data.iterrows():
if row['high'] > high_of_day:
high_of_day = row['high']
trend = 'up'
elif row['low'] < low_of_day:
low_of_day = row['low']
trend='down'
print(determine_trend(filtered_data))