How to sell when annualized gain > aa

I am trying to code a formula to sell when the annualized gain of a stock is more than a certain number. The formula for annualized gain is (GainPct+1) ^ (1/YearsHeld) - 1. Therefore I tried using the formula:
((GainPct/100)+1) ^ (1/(365.25/NoDays)) -1 > 0.50.
Only a couple of stocks got sold due to this rule. It doesn’t make sense that only a couple of stocks ever gained at a rate of more than 50%. Therefore I deduce that there is something wrong with this rule. Where is the error?

Still looking but equation seems correct. I assume you turned off “Allow sold holdings to be re-bought at current rebalance” or excluded repurchase in the buy rules.

No other ideas for now.

Interesting rule. I simplified it a bit, I think it’s

((GainPct/100)+1) ^ (365.25/NoDays) > 1.5

Had to look it up in our glossary

Annualized Return: This is the annualized total return on an asset. A total return can be annualized in the expression:
Annual ret. = (Tot. Ret. + 1)^(365.25 ⁄ days) - 1

Jim thanks I tried that.

Marco I am not sure about your glossary but I think that you need that ((GainPct/100)+1) ^ ([b]1 / /b) -1 > 0.50 See Investopedia here . You can also try it out in Excel.
(1 + 100%)^(3) - 1 gives a result of 7
while
(1 + 100%)^(1/3) - 1 gives a result of ~26% which is the right answer.

I do agree that it’s simpler to take out the -1 at the end like you did. But I still get the same result with:
((GainPct/100)+1) ^ (1/(365.25/NoDays)) > 1.50

Any other ideas? I hope that it’s not a bug in the system. Out of 184 trades there must be more than a handful that had annualized gains of more than 50% at one point (for example after holding one week).

Try mine as the only sell rule then look at the realized trades and sort by days. Look for something close to 1 year. Mine seemed to work

Marco’s formula is correct. But if you want to calculate with the Total Return, you have to write

((TotalReturn/100)+1)^(365.25/NoDays)>1.5

Matthias

Marco, none of the formulas here are working. Here is another way of writing the formula which is easier to read:
GainPct/100 > 1.50 ^ (365.25/NoDays) - 1
But it’s not working either. True, the handful of transactions with one year holding periods did seem to have approximately the correct returns, however there were some holdings with 3% gains that were sold after ~90 days because of this rule! You don’t need a calculator to figure out that at the rate of 3% in 90 days a stock will not reach 50% by the end of the year.

Could it be a difference in the way dividends are handled? Does GainPct include or exclude dividends? Does the Pct gain in realized transactions include dividends?

P.S. TotalReturn includes dividends but does not measure unrealized gains.

You need parentheses. Did you try exactly this:

s^(365.25/NoDays)>1.5[/s]

((GainPct/100)+1)^(365.25/NoDays)>1.5

NOTE: TotalReturn is 1 year return incl dividends

Marco using your rule exactly actually gave a handful of realized transactions that were at a slight loss! (Transaction price was set to previous close for this study). Besides there is an error in that formula. You need to add “1/”. See the attached excel spreadsheet for the correct formula.

Does GainPct include or exclude dividends?


Convert from Total Return to Annual Return and Back.xlsx (9.9 KB)

Chipper,

I haven’t looked that closely, but I did run some quick tests…and -

This does seem to work for what you want:
((1+(GainPct/100))^(1/(Nodays/365.25))-1)>.5

You will get some companies being sold at losses if a) they have a merger or b) go bankrupt or c) can no longer be ranked for some reason.

Easiest way to test this is with a custom list (like Apple or something). Can test with and without a company with a dividend…something that made big moves.

**EDIT…However, you are right…there are some stocks sold based on this rule even though they show losses. That has to be investigated.

Best,
Tom

Chipper,

I still see this error if I set Yield<=.5 in the buy rules. Still seeing stocks with a loss being sold. Feels like you found an error.

I can actually reproduce the error with just GainPct>5 as a single sell rule. And no OTC universe. I get some stocks showing a minor loss still being sold, where there was a) no bankruptcy and b) no merger and c) the stock’s still around and trading. P123 says the stock was sold based on this rule. But the stock lost money.

Best,
Tom

Chipper, sorry, try it with

((GainPct/100)+1)^(365.25/NoDays)>1.5

Total return is the 1 Year return including dividends regardless of when it was bought. GainPct does not include dividends. Should not be too hard to do a GainPctTot

If you still see problem please indicate which sim.

Thanks

Thanks Marco, I got it to work.

edit: glad its working.

So is it agreed that ((GainPct/100)+1)^(365.25/NoDays)>1.5 works?

I ended using my own formula using Close(0)/Close(NoBars)

I found out the cause of at least some of the discrepancies. GainPct uses Friday’s close, does not deduct slippage and commissions and does not include dividends.

So how does that work?

Crastogi, What do you mean? How does what work?

I am sorry, that was a confusing. I meant then is your formula:

sell when (close(0)/Close(Nobars)^(365.25/NoDays)>1.5 ?

does this adjust for dividends?