cseinstein
New Member
- Joined
- Jan 2, 2015
- Messages
- 6
I am trying to evaluate a stock-picking strategy based on signals for when to buy and sell. My start-date is January of 1998. Due to the nature of the signals, we sometimes start with a short position (i.e., sell without buying first), and we sometimes end with a long position (i.e., buy and never sell). I would like to eliminate both of those transactions from my totals. The problem is that the strategy results in some stocks being traded never, some being traded occasionally, and some being traded many times. So I would like to create a formula that allows me to ignore first trades that result in short positions, last trades that result in long positions, and that ignores other numbers interspersed in the same column.
I have a sample at the bottom of this post, 3 columns wide, 36 rows tall. Each transaction consists of 5 rows. If you consider the cell labeled "Price" as C1, then this is the data in the rest of the cells in the first transaction:
C2: Purchase price (expressed as an outflow, and therefore negative)
The other transactions follow the same pattern. (I have just noticed that C2 and C3 are in General format, C4 in Currency, C5 in Currency, and C6 in Percentage, in case any of that matters - though changing C2 & C3 to Currency does not seem to change anything.)
And finally, calculating manually, the sum I would hope to get from the sample column is $56.50, which would indicate a profitable strategy (for that stock, at least). In this case, we do not need to exclude the first transaction (because it starts out with a purchase) but do need to exclude the last transaction (because it ends without a sale). Sometimes we will need to do neither, sometimes both, and we will never exclude any intermediate transactions.
I have tried summing sumif's:
I continue entering sumif's until C62-64, because that is the length of the longest transaction series. I know it is possible to sum formulas because I summed MAX() formulas effectively. Unfortunately, here I get zero everytime. I am not sure if that is because I am trying to add single cells, but that shouldn't be a problem.
I have also tried to come up with a nested if-then, but that seems unduly complicated given the variety in number of transactions. I have also tried to investigate arrays, in case that might hold a solution, but I am not familiar at all with those, and have failed to find anything there. (I've used excel for a long time, but only in relatively uncomplicated ways.)
I have searched extensively online, but as I am not sure what to look for, I may have missed something that can help me.
Thank you for any help you can give!
[TABLE="class: grid, width: 315"]
<tbody>[TR]
[TD][/TD]
[TD]
[TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]2/28/1997[/TD]
[TD="align: right"]-0.84375[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]9/30/1999[/TD]
[TD="align: right"]1.83929[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]$1.00[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]1/31/2001[/TD]
[TD="align: right"]-1.76571[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]7/31/2001[/TD]
[TD="align: right"]1.09[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]-$0.68[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]6/30/2002[/TD]
[TD="align: right"]-1.36143[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]8/31/2005[/TD]
[TD="align: right"]9.69286[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]$8.33[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]9/30/2005[/TD]
[TD="align: right"]-10.99714[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]4/30/2007[/TD]
[TD="align: right"]24.85[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]$13.85[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]5/31/2007[/TD]
[TD="align: right"]-26.96429[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]9/30/2007[/TD]
[TD="align: right"]16.23714[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]-$10.73[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]6/30/2008[/TD]
[TD="align: right"]-20.34714[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]1/31/2012[/TD]
[TD="align: right"]65.07[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]$44.72[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]10/31/2012[/TD]
[TD="align: right"]-74.67171[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]1/0/1900[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]-$74.67[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: center"]#DIV/0![/TD]
[/TR]
</tbody>[/TABLE]
I have a sample at the bottom of this post, 3 columns wide, 36 rows tall. Each transaction consists of 5 rows. If you consider the cell labeled "Price" as C1, then this is the data in the rest of the cells in the first transaction:
C2: Purchase price (expressed as an outflow, and therefore negative)
C3: Sale price
C4: Profit or Loss on Sale
C5: Lowest close after that sale (to be entered manually, and garbage data as far as this calculation is concerned)
C6: Percent decline from C3 to C5 (all at 100% because "Lowest Close" squares are empty currently, and also garbage data for this calculation).
The numbers in Column B are either self-explanatory or irrelevant to this calculation.
C4: Profit or Loss on Sale
C5: Lowest close after that sale (to be entered manually, and garbage data as far as this calculation is concerned)
C6: Percent decline from C3 to C5 (all at 100% because "Lowest Close" squares are empty currently, and also garbage data for this calculation).
The numbers in Column B are either self-explanatory or irrelevant to this calculation.
The other transactions follow the same pattern. (I have just noticed that C2 and C3 are in General format, C4 in Currency, C5 in Currency, and C6 in Percentage, in case any of that matters - though changing C2 & C3 to Currency does not seem to change anything.)
And finally, calculating manually, the sum I would hope to get from the sample column is $56.50, which would indicate a profitable strategy (for that stock, at least). In this case, we do not need to exclude the first transaction (because it starts out with a purchase) but do need to exclude the last transaction (because it ends without a sale). Sometimes we will need to do neither, sometimes both, and we will never exclude any intermediate transactions.
I have tried summing sumif's:
=sum(sumif(C2:C3,C2:C3<>0,C4),SUMIF(C7:C8,C7:C8<>0,C9))
I continue entering sumif's until C62-64, because that is the length of the longest transaction series. I know it is possible to sum formulas because I summed MAX() formulas effectively. Unfortunately, here I get zero everytime. I am not sure if that is because I am trying to add single cells, but that shouldn't be a problem.
I have also tried to come up with a nested if-then, but that seems unduly complicated given the variety in number of transactions. I have also tried to investigate arrays, in case that might hold a solution, but I am not familiar at all with those, and have failed to find anything there. (I've used excel for a long time, but only in relatively uncomplicated ways.)
I have searched extensively online, but as I am not sure what to look for, I may have missed something that can help me.
Thank you for any help you can give!
[TABLE="class: grid, width: 315"]
<tbody>[TR]
[TD][/TD]
[TD]
Date
[/TD][TD]
Price
[/TD][/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]2/28/1997[/TD]
[TD="align: right"]-0.84375[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]9/30/1999[/TD]
[TD="align: right"]1.83929[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]$1.00[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]1/31/2001[/TD]
[TD="align: right"]-1.76571[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]7/31/2001[/TD]
[TD="align: right"]1.09[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]-$0.68[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]6/30/2002[/TD]
[TD="align: right"]-1.36143[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]8/31/2005[/TD]
[TD="align: right"]9.69286[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]$8.33[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]9/30/2005[/TD]
[TD="align: right"]-10.99714[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]4/30/2007[/TD]
[TD="align: right"]24.85[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]$13.85[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]5/31/2007[/TD]
[TD="align: right"]-26.96429[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]9/30/2007[/TD]
[TD="align: right"]16.23714[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]-$10.73[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]6/30/2008[/TD]
[TD="align: right"]-20.34714[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]1/31/2012[/TD]
[TD="align: right"]65.07[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]$44.72[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: right"]100.0%[/TD]
[/TR]
[TR]
[TD]LONG[/TD]
[TD="align: right"]10/31/2012[/TD]
[TD="align: right"]-74.67171[/TD]
[/TR]
[TR]
[TD]SHORT[/TD]
[TD="align: right"]1/0/1900[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]-$74.67[/TD]
[/TR]
[TR]
[TD]Lowest Close after Sale[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Percent Decline[/TD]
[TD][/TD]
[TD="align: center"]#DIV/0![/TD]
[/TR]
</tbody>[/TABLE]