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

[amibroker] Re: need more watchlists, or another approach, or both



PureBytes Links

Trading Reference Links

Dave
I've included AFL that ranks and sorts the top 200 stocks in a given 
watchlist based on Turnover.  It is necessary to have the Osaka 
Plugin to run AFL.  The AFL is easily customisable to your own 
needs, just replace the ranking calculation, set watchlist, depth to 
rank and AddToComposite name. 
>do you try to only calculate dates more recent than what you 
>already have saved in the composite, or recalculate the whole thing 
>always?
No, but that would be more desirable in certain circumstances, is 
there an easy way to do this?  As it stands a change in the selected 
watchlist will effect the whole composite (probably not desirable in 
most situations).  The other issue not addressed is stocks that 
don't trade every day, these "Data Holes" can cause results that you 
don't expect. Especially if you use a "Reference Symbol" (ie set to 
current stock) during the calculation of AddToComposite and then 
Apply to All Stocks or Use Filter during subsequent use of composite 
values.  I'm not saying don't do this but be aware of the posibility 
of differences (Use screens to remove stocks with excessive "holes" 
or "Pad" holes would be possible options to solve this problem.  The 
first option is probably the best,  I don't trade shares that Don't 
Trade daily.)    
Hope this helps
Andrew
ps. Haven't had time to play with your Auto-Optimizer AFL but will 
do soon.

//////////////////////////////////////////////////////////////////
//  Add To Composite RankValue based on Ranking calculation.
//////////////////////////////////////////////////////////////////

// ****************************************************************
// APPLY TO - CURRENT STOCK -  Set to an index (no data holes).
// RANGE - FROM -  "set date"  TO - "set date",
// SCAN or EXPLORE
// ****************************************************************

osInitialize();
#pragma nocache
//#include "afl/AP_Functions.afl";

//////////////////////////////////////////////////
// 	User Variables - enter here       //
/////////////////////////////////////////////////
	sWatchlist = 4;  	// set to desired watchlist.
	Rank_No = 200;		// set the depth to rank to.
// ----------------------------------------------
// USER variables - Used for consistency & Ease 
// ----------------------------------------------
	sov1 = 250;
	sov2 = 0;    // not currently used
	sov3 = 0;    // not currently used
	sov4 = 0;    // not currently used 
	
// -----------------------------------------------
// AddToComposite name
// -----------------------------------------------

ATCName = "~TurnoverTop200";


/////////////////////////////////////////////////
// 		Ranking Calculation            //
/////////////////////////////////////////////////

function Ranking(Sov1,Sov2,Sov3,Sov4)
{
		TO = MA(V,sov1) * Close;

return TO;
}

/////////////////////////////////////////////////
//    End Ranking Calculation                  //
/////////////////////////////////////////////////

/////////////////////////////////////////////////
//            End User Variables               //
/////////////////////////////////////////////////
	StartBar = LastValue( ValueWhen( Status("firstbarinrange"), 
BarIndex() ) );
	FinishBar = LastValue( ValueWhen( Status("lastbarinrange"), 
BarIndex() ) );	
	RankValue = 0;  // initialise Rank Value array
	List = GetCategorySymbols( categoryWatchlist, sWatchlist);

// ---------------------------------------
// Create Ranking Table
// ---------------------------------------

   sRank = osTabCreate();
   // Initialize Ranking Columns
	// Use loop to add columns to cover # of bars ranked.
   i = StartBar;
   while (i <= FinishBar)
   {
    osTabAddColumn("RROR",     1, sRank);
    i = i + 1;
   }

// -----------------------------------------
// Load table with Ranking data
// -----------------------------------------

	for (j=0; (sTicker = StrExtract( List,j)) != ""; j++)
		{
		SetForeign(sTicker);
		Rank = Ranking(Sov1,Sov2,Sov3,Sov4);
		k = StartBar;
		i = 0;
		while (k <= Finishbar)
			{
			osTabSetNumber(Rank[k], j, i, sRank);
			i = i + 1;
			k = k + 1;
			}
		RestorePriceArrays();
		}

// ----------------------------------
// Sorting rank calculations
// ----------------------------------
		
		k = StartBar;
		i = 0;
		while (k <= Finishbar)
			{
			osTabSort(sRank, i, False, True); 
			RankValue[k] = osTabGet(Rank_No-1, i, sRank);
			i = i + 1;
			k = k + 1;
			}

// ---------------------------------------
// clean up - delete srank table
// ---------------------------------------		
	osTabDelete(srank);

AddToComposite(rankvalue, ATCName, "x",23);

Buy=Sell=1;
Filter=1;
AddColumn(RankValue, "Rank value",1.0); 

				
--- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx> 
wrote:
> thanks andrew, nice idea, hadn't thought of that (:-).
> 
> would you mind sharing some sample code to build the ticker? do 
you try to
> only calculate dates more recent than what you already have saved 
in the
> composite, or recalculate the whole thing always?
> 
> thanks,
> 
> dave
> 
>   Dave
>   A different approach might be to write an AFL (incorporating 
Osaka
>   Plugin) to determine your top ranked stocks each month.  If for
>   example you wanted the top 20 stocks for 6 mth ROC.  Use Osaka to
>   determine the 20th highest 6 mth ROC.  Use ADDTOCOMPOSITE to save
>   this value to ~Top20ROC ticker.  In subsequent backtest just 
compare
>   stock 6 mth ROC to ~Top20ROC value.  ie Top20 = ROC(Close,125) >=
>   foreign("~Top20ROC","C");
>   Hope this helps, I use this method myself.
>   Andrew
> 
>   --- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx>
>   wrote:
>   > I wonder if we might get the ability to have more watchlists at
>   some point,
>   > especially now that we can fill them from AFL code.
>   >
>   > or maybe there's another way to do what I'm thinking about. 
(not
>   that 255
>   > watchlists wouldn't still be useful, it would, even if there's
>   another way.)
>   >
>   > suppose you want to run some strategy on the set of stocks that
>   rank the
>   > highest by some criteria over the previous month. for any given
>   day, you
>   > could run a backtest, sort the results however you wanted, put 
the
>   top
>   > ranked stocks in a watchlist, then run your analysis on that.
>   >
>   > but how can you backtest this concept, as if you'd done that
>   repeatedly each
>   > month for a number of years? the only way I could think of was 
to
>   define a
>   > set of watchlists that will hold the highest ranking stocks for
>   each month
>   > of the test period, run a scan that fills them, then run an
>   analysis that
>   > knows which list to check against for each month.
>   >
>   > we can't do the ranking on the fly, since as far as I know, we
>   can't find
>   > out what other stocks are being tested besides the current 
one. am
>   I missing
>   > some other approach to this? am I being clear about what I'm
>   trying to do?
>   >
>   > so two questions really: can we get more watchlists, and how 
else
>   can I
>   > approach backtesting this kind of strategy.
>   >
>   > thanks,
>   >
>   > dave


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

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