Given rows:
symbol_id profit date
1 100 2009-08-18 01:01:00
1 100 2009-08-18 01:01:01
2 80 2009-08-18 01:01:02
2 -10 2009-08-18 01:01:03
1 156 2009-08-18 01:01:04
2 98 2009-08-18 01:01:05
1 -56 2009-08-18 01:01:06
1 18 2009-08-18 01:01:07
3 234 2009-08-18 01:01:08
3 167 2009-08-18 01:01:09
3 34 2009-08-18 01:01:10
I'm looking for average and largest runs/streaks of wins (profit >= 0) and losses (profit < 0) per symbol_id.
Looking at just symbol_id = 1:
symbol_id profit date
1 100 2009-08-18 01:01:00
1 100 2009-08-18 01:01:01
1 156 2009-08-18 01:01:04
1 -56 2009-08-18 01:01:06
1 18 2009-08-18 01:01:07
you can see there are 3 consecutive "wins", then a "loss", then a "win"
average of 2 wins ((3 + 1) / 2)
largest streak is 3
average of 1 loss (1 / 1)
largest streak is 1
Desired Query Result:
symbol_id avg_winning_streak largest_winning avg_losing_streak largest_losing_streak
1 2 3 1 1
2 1 1 1 1
3 3 3 0 0