[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: positionscore problem



PureBytes Links

Trading Reference Links

Not so weird. What you describe is essentially what was being done in 
the thread that I included with my last response.

The easiest way to speed it up what you already had is to use 
AddToComposite in a first pass then refer to the composites on a 
second pass. Requires two runs instead of one. But, it would still 
probably be faster, particularly for larger wathclists.

Script1 (untested):

MyValue = ROC(C,NumBars)/ATR(250);

CurrentHigh = Foreign("~CurrentHigh", "X");
AddToComposite(
IIF(MyValue > CurrentHigh, MyValue - CurrentHigh, 0),
"~CurrentHigh",
"X");

CurrentLow = Foreign("~CurrentLow", "X");
AddToComposite(
IIF(MyValue < CurrentLow, (CurrentLow - MyValue) * -1, 0),
"~CurrentLow",
"X");

Script 2 (untested):

FirstHourUp = IIf (TimeNum() == 103000,True,False); 
NumBars = 13;
MaxRelPerf = Foreign("~CurrentHigh", "X");
MinRelPerf = Foreign("~CurrentLow", "X");
Buy = FirstHourUp AND ROC(C,NumBars)/ATR(250)==MaxRelPerf;
Short = FirstHourUp AND ROC(C,NumBars)/ATR(250)==MinRelPerf;

This way you are not iterating through the entire watchlist for each 
and every member of the list. Instead you are doing it once up front, 
then a second time for the final pass.

But, again, if you ever want more than a single long/short, then you 
have to start doing sorting rather than just tracking the single 
highest/lowest.

Try it out. I suspect that you will see a marked speed improvement, 
albeit at the cost of convenience. You could adopt BatMan in the 
Files section of this group and create a batch of the two runs then 
just fire the single batch run each time.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "claudecaruana" <claudecaruana@xxx> 
wrote:
>
> I agree this seems like the only solution. It is a pity however, as 
I
> would have expected to be able to pick up the weakest signal as a
> short position. In fact at this point I don't really understand how
> the new functionality SeparateLongShortRank actually works.
> 
> In reality I was trying to use positionscore to speed up an earlier
> code which directly computed the minimum and maximum values for the
> watchlist, and went long/short on those. Worked perfectly, but very
> slow. By having to calculate a median value in a similar way I'm 
back
> to square one :)
> 
> Here is my earlier code, for reference. I guess it's a bit of a 
weird
> way to do it, but it does work..
> 
> FirstHourUp = IIf (TimeNum() == 103000,True,False); 
> TickerList = CategoryGetSymbols(categoryWatchlist, 16); ;
> NumBars = 13;
> MaxRelPerf = -10000;
> MinRelPerf = 10000;
> for( i = 0; ( symbol = StrExtract( TickerList, i ) ) != ""; i++ )
> {
> SetForeign(symbol); 
> MaxRelPerf = Max(ROC(C,NumBars)/ATR(250),MaxRelPerf);
> MinRelPerf = Min(ROC(C,NumBars)/ATR(250),MinRelPerf);
> }
> RestorePriceArrays(); 
> Buy = FirstHourUp AND ROC(C,NumBars)/ATR(250)==MaxRelPerf;
> Short = FirstHourUp AND ROC(C,NumBars)/ATR(250)==MinRelPerf;
> 
> 
> cheers,
> Claude
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> > Deducting an average derived from anything other than the values 
of 
> > the watch list in question (e.g. deducting average of S&P500) 
would 
> > still be prone to the same problem since the elements of the 
watch 
> > list might all be on the high side of the average and thus still 
all 
> > end up positive (or conversely all be on the low side and all end 
up 
> > negative).
> > 
> > Similarly, deducting an average of the watchlist itself would 
only be 
> > guaranteed to correctly handle the single long/single short 
scenario. 
> > If the strategy were to be expanded to handle 2 or more longs or 
2 or 
> > more shorts, then a single extreme value could drag the average 
> > up/down such that only that single extreme value was above/below 
the 
> > average and the subsequent longs/shorts would never get 
recognized. If 
> > you're sure that you only ever want a single long and a single 
short, 
> > this can easily be accomplished by first running an AFL that uses 
> > AddToComposite with which to later derive an average in the main 
AFL 
> > on the second pass.
> > 
> > The more robust solution would be to calculate the *median* value 
and 
> > subtract that from the individual ROC(C,NumBars)/ATR(250) values 
> > giving an equal number of positive results as negative results. 
You 
> > could then successfully employ your original logic for taking 
longs 
> > when > 0 and shorts when < 0 with the assurance that there will 
always 
> > be an equal number of each, thereby allowing any combination of 
longs 
> > and shorts.
> > 
> > e.g.
> > 
> > PositionScore = ROC(C,NumBars)/ATR(250) - MedianValue;
> > Buy=FirstHourUp AND PositionScore > 0;
> > Short=FirstHourUp AND PositionScore < 0;
> > 
> > So, the question becomes how to get the median value? For that 
you 
> > would need to rank and sort the ROC(C,NumBars)/ATR(250) 
calculation 
> > across all members of the watch list, then pull out the value 
> > appearing in the center of the ordered list (if odd number of 
items in 
> > watch list) or the average of the two center items (if even 
number of 
> > items in watch list).
> > 
> > So, how do you rank and sort across a watch list? You can refer 
to the 
> > following link for a solution where there are not too many items 
in 
> > the list:
> > 
> > http://finance.groups.yahoo.com/group/amibroker/message/126400
> > 
> > Mike
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "vlanschot" <vlanschot@> wrote:
> > >
> > > One way of solving this would be to deduct an average ROC from 
some 
> > > aggregate index from each of your individual scores, e.g. if 
your 
> > > stocks belong to the S&P500, deduct its ROC from each of your 
> > > individual ROCs (you can also create one yourself). You are 
correct 
> > > in using the new functionality to seperate your shorts from 
your 
> > > longs via the MaxOpenLong and MaxOpenShort functions.
> > > 
> > > Hope this helps.
> > > 
> > > PS
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "claudecaruana" 
<claudecaruana@> 
> > > wrote:
> > > >
> > > > Hi,
> > > > 
> > > > Actually the code I supplied on my original message already 
does
> > > > this.. Works ok if the positionscores for each iteration 
contain 
> > > both
> > > > positive and negative values. If they are all positive or all 
> > > negative
> > > > the code below would fail.
> > > > 
> > > > BR
> > > > C
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Joe" <j0etr4der@> wrote:
> > > > >
> > > > > Hi,
> > > > > 
> > > > > This bit me, too.  From the AFL Reference Manual, section 
on 
> > Using
> > > > > Position Score, "...AmiBroker will use the absolute value of
> > > > > PositionScore variable to decide which trades are 
preferred."  
> > > > > 
> > > > > Try this (untested):
> > > > > 
> > > > > PS = ROC(C,NumBars)/ATR(250);
> > > > > PositionScore = PS;
> > > > > .
> > > > > .
> > > > > .
> > > > > Buy=FirstHourUp AND PS > 0;
> > > > > Short=FirstHourUp AND PS < 0;
> > > > > 
> > > > > 
> > > > > Good luck,
> > > > > 
> > > > > Joe 
> > > > > 
> > > > > 
> > > > > 
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "claudecaruana" 
> > <claudecaruana@>
> > > > > wrote:
> > > > > >
> > > > > > hi All,
> > > > > > 
> > > > > > I am trying to implement a very simple intraday system 
using
> > > > > > PositionScore, which buys the strongest symbol at a 
particular 
> > > time
> > > > > > and shorts the weakest. Exit is at some particular time 
later. 
> > > > > > 
> > > > > > I am using ROC to determine strength. The code below 
works 
> > fine 
> > > when
> > > > > > the symbols backtested have mixed positive and negative 
ROC's, 
> > > but if
> > > > > > on a particular day all ROC's are positive, the short 
trade is 
> > > missed
> > > > > > and vice versa for all ROC's negative.
> > > > > > 
> > > > > > I think I understand why this is happening, however I 
cannot 
> > get
> > > > > > around solving it! 
> > > > > > 
> > > > > > Here is the code: (I am using V5.17)
> > > > > > 
> > > > > > FirstHourUp = IIf (TimeNum() == 103000,True,False);  
> > > > > > numbars=13;
> > > > > > 
> > > > > > SetOption("SeparateLongShortRank", True ); 
> > > > > > SetOption("MaxOpenPositions", 2);
> > > > > > SetOption("MaxOpenLong", 1 );
> > > > > > SetOption("MaxOpenShort",1);
> > > > > > 
> > > > > > PositionScore = ROC(C,NumBars)/ATR(250);
> > > > > > 
> > > > > > Buy=FirstHourUp AND PositionScore > 0;
> > > > > > Short=FirstHourUp AND PositionScore < 0;
> > > > > > 
> > > > > > Sell = TimeNum() == 113000;
> > > > > > Cover = TimeNum() == 113000;
> > > > > > 
> > > > > > 
> > > > > > Note: If I replace the buy/sell lines with the following:
> > > > > > 
> > > > > > Buy=FirstHourUp ;
> > > > > > Short=FirstHourUp ;
> > > > > > 
> > > > > > then I get no short signals at all. I am not sure why.
> > > > > > 
> > > > > > Any ideas on what I can do to resolve the issue?
> > > > > > 
> > > > > > Thanks for any feedback,
> > > > > > Claude
> > > > > >
> > > > >
> > > >
> > >
> >
>



------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/