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

RE: [amibroker] New Variable Class



PureBytes Links

Trading Reference Links

not that this actually solves this problem, but for portfolio backtests,
only, variables we create and manage ourselves actually aren't reset at the
start of each new stock. it *appears* that they are, unless your code treats
them as global to the entire backtest run, which it usually doesn't.
typically we set everything that needs to be set every time, for every
stock, erasing anything that might have persisted. to preserve values across
all the stocks in a test, you have to detect when you're on the first stock,
and initialize your vars at that time, only, then continue to add to them or
use them however you want with each stock without resetting them again from
scratch.

for instance, say you want to buy and sell based on an indicator applied
both to the stock itself, and to an overall index. ideally, you don't want
to recreate the index indicator over and over again for every stock, so you
could do something like this in the portfolio backtester (not that this is a
good system):

----------------
period = Optimize("Period", 18, 2, 40, 1);

if(Status("StockNum") == 0) {	// first stock in test
	index_price = Foreign("!COMP", "C");
 	index_EMA = Wilders(index_price, period);
	index_buy = index_price > index_EMA;
	index_sell = index_price < index_EMA;
}

stock_EMA = Wilders(c, period);
stock_buy = c > stock_EMA;
stock_sell = c < stock_EMA;

buy = stock_buy and index_buy;
sell = stock_sell or index_sell;
short = stock_sell and index_sell;
cover = stock_buy or index_buy;
----------------

the if statement block runs only once, when the first stock is being
examined, but the variables it sets stay valid for the whole backtest, so
you can use them to evaluate each stock without recalculating them.


there are some unfortunate problems with this approach for doing on-the-fly
composites; hopefully tomasz will address them at some point in the future:

- Status("StockNum") seems to be undefined in explorations, as it is in the
old backtester. this means you can't detect when you're on the first stock,
to do your initializations. even IsNull(Status("StockNum")) doesn't return
anything.
  besides having Status("StockNum") work in explorations, it would be nice
to have Status("FirstStockInTest") and "LastStockInTest", like we have
FirstBarInTest etc.

- you can't find out which tickers are included in the current test, or how
many there are. this means you can't find out when you're on the last stock,
or convert the sum of values for each stock to an average, in any way I
could figure out. you also can't iterate through them all during the first
stock of a backtest, to, say, find the top N by volume, and use that during
trading of each stock.
  I've suggested a new feature, GetCategorySymbols(categoryTypeAutoAnalysis)
that would return the list of tickers being analyzed; this would make a
variety of things easier.

dave


(btw the index/stock Wilders thing is an example of a distinctly non-robust
system. backtest it on the NASDAQ 100 from 3/1/98 to 3/31/03, and results
are decent-ish, not great MDD. then optimize and look at the returns for the
periods surrounding the default 18. they bite; 18 is a local fluke. try
other time frames, and again, the generic all-market-types period is about
the only one that does as well.)


> Currently, all variables (global and local) reflect information about
> the current symbol only.
>
> To perform calculations against multiple securities, you must use
> AddToComposite which restricts the user to O,H,L,C,V,OI fields along
> with their pre-defined constraining formats which preclude the
> calculation and storage of very large numbers. It also usually
> requires at least two passes against separate AFL or AFL/IB afl code
> to work with the results.  There is certainly a need for
> AddToComposite, but I think there is also a need for a simpler set of
> composite values.
>
> I'd like to see a new variable class within AFL for computations
> across the entire database or watchlist. For lack of a better word, a
> "composite variable" whose value is maintained across multiple
> securities and which the AFL engine does not initialize with each new
> symbol. Also, a composite variable that can be displayed with
> AddColumn just like the other variables using Filter = LastBar logic.
>
> This would allow the user to put together some quick, one-pass
> explorations for calculating multiple issue stats and to display those
> figures in the same afl. No ~Composite files would be created, and
> very large numbers could be calculated and displayed using more
> flexable variable type declarations of float (or others).
>
> I'm posting this here to see if I am alone in wanting this feature, in
> which case I won't pass it along to TJ as a suggestion.
>
> Comments?
>
> Phsst
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
>
>
>
>
> 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 the Yahoo! Terms of Service.


------------------------ 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/