Looking for an error in Supernovas code

Hello everyone.

I'm here again.

Now I'm triying to understand a code, I think it's a good way to learn how to code in AFL, I get that code from a paper of JB. Darwood , Shorting supernovas, it's about get short in highly overbought stocks.

I've been copy the code and when I send it to backtest it don't works. My "friend" Amibroker says "error 701", that means "Missing buy/sell variable assignaments".

I tried to place into the code the variables buy and sell, equal to zero, and equal to true, but still with succes.

Anybody knows what's happend here?

here the paper: http://jbmarwood.com/wp-content/uploads/2015/12/Shorting-Supernovas.pdf

here the code:

 SetOption("InitialEquity", 10000);
 SetOption("MinShares", 0.01);
 SetOption("MarginRequirement", 100);
 SetOption("UsePrevBarEquityForPosSizing", True);
 SetTradeDelays(1,1,1,1);
 SetOption("MaxOpenpositions", 10);
 SetOption("SeparateLongShortRank", True);
 MOL=0;
 MOS=10;
 SetOption("Maxopenlong", MOL);
 SetOption("Maxopenshort", MOS);
 SetOption("Allowsamebarexit", True);
 Numberpositions=10;
 SetOption("Maxopenpositions", numberpositions);
 SetPositionSize(1,spsShares);
 PositionSize=-100/20;
 SetOption("CommissionMode", 3);
 SetOption("CommissionAmount", 0.02);
 Delisting=GetFnData("delistingdate");
 Thisislastbar= BarIndex()==LastValue(BarIndex());
 Exitlastbar= DateTime()>=GetFnData("DelistingDate");
 Cond= IIf(IsNull(delisting), 1, DateTime()<delisting);
 
 Increase = 80;
 Holdingtime=5;
 Short = ROC(C,5)>Increase AND Cond AND OpenInt>2 AND OpenInt <20 AND V> 500000;
 Cover= 0 OR thisislastbar OR exitlastbar;
 Sellperiod= Holdingtime;
 ApplyStop(stopTypeNBar, stopModeBars, sellperiod);
 ApplyStop(stopTypeProfit, stopModePercent, 20, 1, 1);
 
 ShortPrice= 0;
 CoverPrice= 0;

Thanks to all.

There are two ways for you to fix this problem. One is to go into the Analysis Settings window and change your Positions to "Short" instead of "Long and short". That will tell AB that you don't need Buy and Sell variables to be defined.

The other method is to actually assign those variables, which you said that you did but which I do not see in your code. You just need to add:

Buy = 0;
Sell = 0;
1 Like

Hello Mradtke.

I did both things, right now, and the code works, more or less, but the results it shows are very far away from the results Darwood says in his paper. In fact I launched it in Nasdaq, from 2000 to 2017, and the code shows a loos of -4'66%.

Do you think this is right?

Captura

@Monday I am not familiar with the paper nor the underlying strategy. Perhaps you should go back and ask JB Marwood for his feedback as there are lots of things that could be affecting the performance metrics: trading universe, date range, commissions, data provider, adjusted vs. unadjusted prices, etc.

1 Like

JB Marwood is also a member of this forum as @marwood

1 Like

Thanks a lot buddies. But I think the problem is mine, with the settings in my backtester. It should be an error anywhere.

Ok, I'm still working on understand the code.

Anybody can tell me what means this:

PositionSize= -100/20;

To me it's just a -5... :sweat_smile:

Why the code need another "number" for the position size if we already write it in the upper code line?

@Monday, PositionSize is now no longer the preferred method to indicate the desired position size for each trade.
Negative values are interpreted as a percentage, so in the above example, that means to use a 5% of the portfolio that is invested in any single trade.

Details about its use (and about a lot of other related predefined reserved variables) is explained on this page titled Back-testing your trading ideas

Now it is recommended to use the SetPositionSize to avoid any ambiguity.

5 Likes

ok, thanks a lot for your explanation Beppe.

I own the rights to this document. And actually, this document was not meant to be publicly shared (as stated in clear terms in the document itself).

You probably knew this which is why you ask for help on this forum instead of contact me directly. I have removed the document from my servers so the link above should not work anymore. If you want help with my work why not contact me directly.

Hello Mr.Marwood.

I'm so sorry not to ask you directly, but I was pretty sure that the "error" was in my settings not in your code, and keeping in mind that your are a professional I thought that better not disturb you with such little thing. I never thought about "the rights".

Anyway I'm so sorry to use your code, I found it on the net, and I have no bad intentions except to learn Amibroker. I thought understand some good programs could help me to do so.

I beg your pardon and If you want to, I will erase the post here, (I hope I can) and your code from my database.

My apologies.

No worries mate, you can keep the post up.

Just if you could let me know next time? I usually don't mind people posting stuff if they ask first.

Cheers

Deal. Thanks a lot for your kindness.