-2

I have equity time series and I am trying to update the high of the daya based on the recent trade. For example, if the last trade is higher than the known high, than update the high of the day to be the last trade etc.

I have tried to implement the solution here and read few other solutions to update raw by raw with an IF function but I am failing and getting an error after running this code:

df = pd.read_csv('C:/2017-11-20.csv')
df.set_index('dateTime', inplace=True)

df['high'] = 0
high = 0
for dateTime, row in enumerate(df.iterrows()):
    if df['tradePrice'] > df['high']:
        df['high'] = df['tradePrice']
    else:
        df['high'] = df['high']

the error is:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

the data (top 5 lines) is:

SecurityID,dateTime,ask1,ask1Volume,bid1,bid1Volume,ask2,ask2Volume,bid2,bid2Volume,ask3,ask3Volume,bid3,bid3Volume,tradePrice,tradeVolume,isTrade 2318276,2017-11-20 08:00:09.052240,12869.0,1,12868.0,3,12870.0,19,12867.5,2,12872.5,2,12867.0,1,0.0,0,0 2318276,2017-11-20 08:00:09.052260,12869.0,1,12868.0,3,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,1 2318276,2017-11-20 08:00:09.052260,12869.0,1,12868.0,2,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,0 2318276,2017-11-20 08:00:09.052270,12869.0,1,12868.0,2,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,1 2318276,2017-11-20 08:00:09.052270,12869.0,1,12868.0,1,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,0

Giladbi
  • 1,822
  • 3
  • 19
  • 34
  • There's an indentation in front of `for` that does not line up with the previous line (assuming you copied-pasted your code correctly). –  Jan 15 '18 at 21:16
  • Other than that, I'm not sure what your problem or question is, since the error message is quite clear. The error is certainly not related to anything you're trying to do (given the title of the question). –  Jan 15 '18 at 21:17
  • Can you share 5-10 rows of your data? There are like, 5 ways to do this, but faster. – cs95 Jan 15 '18 at 21:18
  • @COLDSPEED I added a sample in the original post. – Giladbi Jan 16 '18 at 06:19

1 Answers1

0
df['high'] = df.tradePrice.rolling(window=df.__len__(),min_periods=1,center=False).max()
Giladbi
  • 1,822
  • 3
  • 19
  • 34