PureBytes Links
Trading Reference Links
|
Don't
know if it can be improved but i'll think about it; I like this kind of
challenges. Coding is more fun than trading, ooops: i should have said that in
public :-)
<FONT face=Arial color=#0000ff
size=2>
For
comparison you may look at the code below which performs a similar action, it
calculates the correllation between each of a group of stocks. Run it on your
700 and see how long it takes. If it is much shorter than the time-consuming
code is not the StrExtract() and you should look at your other lines of code. I
would be interested to know how that compares on your computer. It take less
than 10 seconds to correlate 100x100 stocks for me.
<FONT face=Arial color=#0000ff
size=2>
SetOption(<FONT color=#ff00ff
size=2>"NoDefaultColumns",True);Filter =
Status(<FONT
color=#ff00ff size=2>"LastBarInTest");list =
GetCategorySymbols(
categoryWatchlist, 0<FONT
size=2>);AddTextColumn<FONT
size=2>(Name<FONT
size=2>(),"Correlation"<FONT
size=2>,1.0);Ticker1=
Name();<FONT
color=#800000 size=2>for( Col=<FONT color=#ff00ff
size=2>0; (Ticker2=<FONT color=#0000ff
size=2>StrExtract( List, Col))!= <FONT color=#ff00ff
size=2>""; Col++){Var2 = <FONT color=#0000ff
size=2>Foreign(Ticker2,<FONT color=#ff00ff
size=2>"C");Corr = <FONT color=#0000ff
size=2>Correlation( C, Var2, <FONT
color=#ff00ff size=2>8);Color = <FONT
color=#0000ff size=2>IIf(Corr><FONT color=#ff00ff
size=2>0, colorBrightGreen, <FONT
color=#0000ff size=2>IIf(Corr<<FONT color=#ff00ff
size=2>0, colorRed,colorWhite));Color =
IIf(Ticker1==Ticker2,
1, Color);<FONT
color=#0000ff size=2>AddColumn( Corr, Ticker2, <FONT
color=#ff00ff size=2>1.3, <FONT color=#ff00ff
size=2>1, Color);}
<FONT face=Arial
color=#0000ff>1) You may have calculations inside your loop that are repeated
for each comparison but that need only be calculated one time for each stock,
outside the loop. You could use an additional loop through the watchlist to
create these variables using SetVar. That way they would be calculated 700x
instead of 700^2 x... that would give a 700x improvement for those lines of
code. Your selfRelStrength function comes to mind
...
<FONT face=Arial color=#0000ff
size=2>
2)
some things that come to mind is that you are retrieving 700 x 700 x 3000
(assuming 10 yrs data) bars from your hard disk. You can observe this by noting
the status line at the bottom of the AB screen. The AA doesn't use QuickAFL so
perhaps it would work faster to run this indicator in an indicator using
two loops.
<FONT face=Arial color=#0000ff
size=2>
3)
Your code could also create a OSAKA-like table for all stocks and work from
there, with the same objective.
<FONT face=Arial color=#0000ff
size=2>
<FONT face=Arial color=#0000ff
size=2>interesting problem, let me know how you progress, I'll let you know if
something else comes to mind.
<FONT face=Arial color=#0000ff
size=2>
<FONT face=Arial color=#0000ff
size=2>herman
<FONT face=Arial color=#0000ff
size=2>
<FONT face=Arial color=#0000ff
size=2>
<FONT face=Arial color=#0000ff
size=2>
<FONT face=Tahoma
size=2>-----Original Message-----From: firstview2000
[mailto:firstview2000_1999@xxxxxxxxx]Sent: Wednesday, August 04,
2004 1:32 AMTo: amibroker@xxxxxxxxxxxxxxxSubject:
[amibroker] Re: any ideas to reduce runtime for the price RS ranking
code?Herman,I need all available values for
the RS ranking for backtesting purpose. I could plot a chart showing the
rs ranking if I need so.My code performs the following
loops:the outer loop is for all 700 stocks in database to have their
rankings;the inner loop is for comparing one stock to every other 700
stocksSo, there are 700x700=490,000 loops. I don't know if we can
reduce the number of loops here.In addition, if stock quotes are
1000 bars in length, this ranking formula will have 490K x 1000 = 490
million calculations to complete.It takes over 40 minutes to complete,
which suggests about 10 million RS calculations per minute. I don't know
if this is a reasonable rate, but I just think 40minutes is too
long.Thank for your help.Charles--- In
amibroker@xxxxxxxxxxxxxxx, "Herman van den Bergen" <psytek@xxxx>
wrote:> can you outline the action in a few words? I would save me from
having to> study your code in detail...> > When you
say "I need to compare the price performance of each stock to
all> other> stocks in order to rank the relative performance
strength."> do you mean a simple sort? The best of the group?>
> Do you want only the last value of the RS?> Or do you want a
chart showing historical RS?> > I have had some codes that took
many hours to complete and in the end I> managed to have them run
in minutes, it is worthwhile to explore different>
approaches.> > herman> > > >
> -----Original Message-----> From: firstview2000
[mailto:firstview2000_1999@xxxx]> Sent: Tuesday, August 03, 2004 12:47
AM> To: amibroker@xxxxxxxxxxxxxxx> Subject: [amibroker] Re: any
ideas to reduce runtime for the price RS> ranking code?>
> > Herman,> > I need to
compare the price performance of each stock to all
other> stocks in order to rank the relative performance
strength. I an not> sure how I can avoid the
StrExtract() to make comparisons with other> stocks in
the database. Can you explain a bit more on how to
avoid> the StrExtract() loop?> >
> Thanks> > Charles>
> --- In amibroker@xxxxxxxxxxxxxxx, "Herman van den
Bergen"> <psytek@xxxx> wrote:>
> The StrExrtract() is slow and you may do better to run a
single> Explore of> > your 700 stock
watch list, i.e. remove the StrExtract() loop from>
your code.> > if your code only generates two result
arrays you should be able> to use>
> composites for those. Create you 700 watchlist and develop
your> code one> > section at a time,
i find using DebugView nice to give me a>
relative> > indication of where the code takes too much
time. I haven't> analyzed your> >
code in detail but i expect getting rid of the StrExtract()
will> speed up> > your code a
hundred times, well, just being hopeful here ;-)>
>> > herman.>
>> >> >
-----Original Message-----> > From:
firstview2000 [mailto:firstview2000_1999@xxxx]>
> Sent: Sunday, August 01, 2004 6:46 PM>
> To: amibroker@xxxxxxxxxxxxxxx>
> Subject: [amibroker] any ideas to reduce runtime for the
price> RS ranking> >
code?> >> >>
> Hi,> >>
> With the following code, it takes me over 40 minutes to run
a> > database of 700 tickers. This code
calculates 2 ratings, one for> > stocks
and one for indices.> >>
> Can anyone suggest some good ways to reduce the runtime
?> >> >
TIA.> > Charles>
>> > /*>
> ** Price Relative Strength Ranking>
> **> >
*/> >> > // use this
function to calculate self relative strength>
> // The funciton takes care of stocks with several quote
length> > // It returns the calculated
relative strength array> > function
selfRelStrength (myArray)> >
{> >
sRelStren = IIf((IsNull(ROC(myArray, 260)) == False),>
>>
>
ROC(myArray,> > 260) + ROC(myArray, 195) +
ROC(myArray, 130) + 2 * ROC(myArray,>
65),> >>
>
IIf ( (IsNull(ROC(myArray, 195)) ==
False),> >> >>
> ROC(myArray, 195) + 2 *
ROC(myArray, 130) + 2 * ROC> > (myArray,
65),> >>
> 2 * ROC(myArray, 130) + 3
* ROC(myArray, 65) ));> >>
>> >
return sRelStren;> > }>
>> >> > //replace
your watchlist number with 0> > //list =
CategoryGetSymbols( categoryWatchlist, 0 );>
> list = CategoryGetSymbols( categoryMarket , 0 )
+> CategoryGetSymbols> >
( categoryMarket , 1 );> >>
>> > Count = 0;>
> rank = 0;> > relval =
0;> > n = 0;>
>> > CountIdx = 0;>
> rankIdx = 0;> > relvalIdx =
0;> > nIdx = 0;>
>> > // price change for the current
symbol> > OwnVal =
selfRelStrength(C);> >>
> for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++
)> > {>
>> >
SetForeign(sym);> >>
> if (IsIndex())
{>
>
relValIdx =
Nz(selfRelStrength(C));> >>
>
RestorePriceArrays();> >>
>
nIdx
= Nz(IIf(relValIdx != 0, 1, 0));>
>
// count if there is a price change>
>>
>
// now, add up counts for all symbols with price>
> change in the specified period>
>
CountIdx = CountIdx + nIdx;> >>
>
rankIdx = IIf (relValIdx > OwnVal, rankIdx + 1,>
> rankIdx);>
> }>
> else
{> >>
>
relVal =
Nz(selfRelStrength(C));> >>
>
RestorePriceArrays();> >>
>
n
= Nz(IIf(relVal != 0, 1, 0));>
>
// count if there is a price change>
>>
>
// now, add up counts for all symbols with price>
> change in the specified period>
>
Count = Count + n;> >>
>
rank = IIf (relVal > OwnVal, rank + 1, rank);>
> }>
> }> >>
> rankPerc = int(100 * (Count - rank) /
Count);> >> >
rankPercIdx = int(100 * (CountIdx - rankIdx) / CountIdx);>
>> > // filter out any stocks that dont
have recent quotes (1 month)> > // this
is done via comparing with $compx> >
CurrentDay =
Now(3); //
get system date with dateNum> >
format> > CurrDayAgo = CurrentDay -
100;> >> > LastDay =
LastValue(DateNum());> >>
> // donot rank DATAONLY tickers (in Market
#3)> > Filter = (CurrDayAgo <= LastDay)
AND (MarketID() != 3);> >>
> if (Status("action") == 4) {>
> // code running in exploration>
> SetOption("nodefaultcolumns", True );>
> AddTextColumn(Name(),"Ticker");>
> AddColumn(Close,"Close", 1.2);>
> // AddColumn(Count,"count", 1.0);>
> AddColumn(rank,"rank#", 1.0);>
>> >
AddColumn(Ownval,"Perf",1.2);> >
AddColumn(rankPerc,"rank%",1.0);> >
AddTextColumn(IndustryID(1),"Industry");>
>> > AddColumn(rankIdx,"rankIdx#",
1.0);> >
AddColumn(rankPercIdx,"rankIdx%",1.0);> >
}> >> >>
>> >> > Check
AmiBroker web page at:> > <A
href="">http://www.amibroker.com/>
>> > Check group FAQ
at:> > <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>
>> >>
> Yahoo! Groups
Sponsor>
>
ADVERTISEMENT> >>
>> >> >>
>> >
------------------------------------------------------------------->
---------> > --> >
Yahoo! Groups Links> >>
> a.. To visit your group on the web, go
to:> > <A
href="">http://groups.yahoo.com/group/amibroker/>
>> > b.. To unsubscribe from
this group, send an email to:> >
amibroker-unsubscribe@xxxxxxxxxxxxxxx>
>> > c.. Your use of Yahoo!
Groups is subject to the Yahoo! Terms> of
Service.> > > > Check AmiBroker web
page at:> <A
href="">http://www.amibroker.com/>
> Check group FAQ at:> <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html>
> > Yahoo!
Groups
Sponsor>
ADVERTISEMENT> > > > > >
---------------------------------------------------------------------------->
--> Yahoo! Groups Links>
> a.. To visit your group on the web, go
to:> <A
href="">http://groups.yahoo.com/group/amibroker/>
> b.. To unsubscribe from this group, send an
email to:>
amibroker-unsubscribe@xxxxxxxxxxxxxxx> >
c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.> > > > [Non-text portions of this message
have been removed]Check AmiBroker web page at:<A
href="">http://www.amibroker.com/Check
group FAQ at: <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Sponsor
ADVERTISEMENT
Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
|