Moving Streaks

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,640
Office Version
  1. 365
Platform
  1. Windows
Can someone please help me?

I wish to calculate the number of occurrences for each trader where the streak of the declared number of trades (I used the variable 5 here) resulted in a winning percentage greater than the hurdle rate (I used 60% here). So for Dan, there was only one time (transactions 1 through 5) where any string of 5 trades resulted in at least 60% of the points available (which is 5x2=10 pts). Cam succeeded in all 16 of the possible 5-transaction strings.

I manually reckoned the answers in ColumnV by selecting every possible string of 5 transactions for each trader and then determining from the status bar at the bottom of Excel how many strings summed to 6 or greater. But I would really like a single formula in ColumnV to report the number of successes for each trader; in this example that number is between 0 and 16.

ABCDEFGHIJKLMNOPQRSTUV
1trader // transaction1234567891011121314151617181920surpass hurdle?
2abe11120210011210222120yes, 8 times
3bob00111001200011110202no
4cam22122221202222112221yes, all 16 times
5dan11220000000000000000yes, 1 time
6edd20201021120102102212yes, 4 times
7
8hurdle60%
9for trades5
10max points per trade2

<tbody>
</tbody>
Sheet14
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Maybe:

ABCDEFGHIJKLMNOPQRSTUVW
1trader // transaction1234567891011121314151617181920surpass hurdle?
2abe11120210011210222120yes, 6 times8
3bob00111001200011110202no0
4cam22122221202222112221yes, all 16 times16
5dan11220000000000000000yes, 1 time1
6edd20201021120102102212yes, 4 times5
7
8hurdle60%
9for trades5
10max points per trade2

<tbody>
</tbody>
Sheet4

Array Formulas
CellFormula
W2{=SUM(IF(SUBTOTAL(9,OFFSET(B2,0,ROW(INDIRECT("1:"&21-$B$9))-1,1,$B$9))>=$B$9*$B$10*$B$8,1))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



My totals are slightly different from your example, if mine are wrong, let me know. Also note that the 21 in the formula is 1 more than the number of columns, so if you add more columns, that will need to be changed.
 
Last edited:
Upvote 0
Solution
Eric, thanks very much for the quick reply.

Yes, I made a mistake in my manual reckoning: the proper results are 8, 0, 16, 1, 5. For too many hours I banged my head in the wall with OFFSET and INDIRECT and finally decided to seek help.

I see that SUBTOTAL is the key but I can't understand it. I evaluate ref1 inside SUBTOTAL and it reports the array of values from columns B through U. Then I try to evaluate the entire SUBTOTAL portion and it reports error. But when I evaluate the logical_test argument of IF it reports meaningful TRUES and FALSES. I evaluate the SUBTOTAL portion without evaluating its internal arguments first and I get an accurate array of performance percentages. So I guess SUBTOTAL is one of those functions that can't be dissected, right? There must be a reason you chose SUBTOTAL instead of SUM or AGGREGATE.

In any event, you are extremely clever...what a simple solution to something so seemingly complex. THANKS Eric!
 
Upvote 0
You are correct, SUBTOTAL is the key. It has some nice properties. In order to check multiple ranges in a single formula, it needs to be an array formula. We can use the array inside of an OFFSET to calculate the various ranges. But that's where it usually breaks downs. Arrays usually don't play nice with LOOKUP type functions, OFFSET, INDIRECT, INDEX, VLOOKUP, etc. But there is an exception, if the array OFFSET is inside SUBTOTAL, it will work. But as you noticed, it's still a bit odd. If you run it through the Evaluate Formula tool, it generates a lot of #VALUE errors. But if you go one more step, the right totals show up. This makes it hard to debug sometimes. I had 2 parameters reversed in my first version of the OFFSET, and it was hard to figure out, since the step where I would have found the problem didn't show up. You really have to make sure that you code the OFFSET correctly.

Anyway, glad I could help! :cool:
 
Upvote 0
Thanks for expanding on this concept for us, Eric. This algorithm is working just right on my massive data.
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,572
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top