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

[amibroker] auto-optimize experiences



PureBytes Links

Trading Reference Links

while Demitris' was looking into InspectionPoints, I've been investigating
continuous equity feedback as a way of setting parameters for trading
indicators. where InspectionPoints test past performance every specified
number of days, the code below tests performance for this stock and adjusts
parameter settings on every bar. it also skips the trade completely if no
parameter combination was profitable. the performance metric used is
smoothed return over the prior 3 years.

results have been more mixed than I expected. for certain stocks, it works
quite while, for many others, not well at all. testing the NASDAQ 100 from
1/1/94 to present, 51% of stocks made a profit, 42% lost, and 8% didn't
trade at all.

since it does work very well on some stocks, one interesting next step would
be to trade it as a ranked portfolio, using past performance as
PositionScore. however, for PositionScore to have the effect of selecting
only stocks that trade profitably this way, there have to be significantly
more simultaneous entry signals than available positions. this requires
widening the universe of stocks examined well beyond the N100. for other
systems I've done using that principle, I used the whole NASDAQ, but with
bar by bar optimization of each individual stock, this auto-optimization
system is quite slow. the N100 took somewhere upwards of 30 minutes on my
800mHz PIII laptop, so running the whole NASDAQ as a scored portfolio is out
of reach for me I think.

anyway, here's the code, for comments, bug finding, and food for thought.

dave

===========================
// CONFIG
has_min_vol = (MA(v, 50) > 1000000) or (MarketID(1) == "Mutual Funds");
is_min_price_long = c > 1;
is_min_price_short = c > 5;
equity_lookback_bars = 252 * 3;
equity_lookback_smoothing = 5;

// SIGNALS
best_profit = 0;
best_range = 0;
best_smoothing = 0;
for(range = 2; range <= 50; range++) {
	for(smoothing = 2; smoothing <= 50; smoothing++) {
		// calc indicator	 w those settings
		stoD = StochD(range, smoothing, smoothing);
		stoK = StochK(range, smoothing);
		sig = stoD - stoK;
		// calc buy/sell/short/cover w those settings
		long_signal = Cross(sig, 0);
		short_signal = Cross(0, sig);
		buy = cover = long_signal;
		sell = short = short_signal;
		buy = buy and is_min_price_long and has_min_vol;
		short = short and is_min_price_short and has_min_vol;
		// calc performance w those settings
		e = Equity(0, 0);
		e_ref = Ref(e, -equity_lookback_bars);
		profit = MA((e - e_ref) / e_ref, equity_lookback_smoothing) * 100;
		// track settings w best performance and resulting performance
		is_new_best = IIf(profit > best_profit, 1, 0);
		best_profit = IIf(is_new_best, profit, best_profit);
		best_range = IIf(is_new_best, range, best_range);
		best_smoothing = IIf(is_new_best, smoothing, best_smoothing);
	}
}

// calc real signals w optimal settings
stoK =
MA(100*(C-LLV(L,best_range))/(HHV(H,best_range)-LLV(L,best_range)),best_smoo
thing);
stoD = MA(stoK, best_smoothing);
sig = stoD - stoK;

// calc buy/sell/short/cover w optimal settings
long_signal = Cross(sig, 0);
short_signal = Cross(0, sig);
buy = cover = long_signal;
sell = short = short_signal;
buy = buy and is_min_price_long and has_min_vol;
short = short and is_min_price_short and has_min_vol;

// don't buy or short unless profitable
buy = buy and best_profit > 0;
short = short and best_profit > 0;


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs Online - Over 14,500 titles.
No Late Fees & Free Shipping.
Try Netflix for FREE!
http://us.click.yahoo.com/JYdFFC/XP.FAA/ySSFAA/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/