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

[amibroker] Re: auto-optimize experiences



PureBytes Links

Trading Reference Links

Keith,
E1, in my formula, is the Equity value(calculated from the beginning 
of my data, which is Jan3, 2000).
The kpass values match 1-1 to the optimal k values [the beginning of 
the optimization period is the same].
If your COMPX data begin on 1993, for example, then the results will 
not match, because  E1 is calculated from 1993 till the IP.
You will have the same results in Koptimal and Kpass, if the 
optimization begins from the beginning of your data.
Else the code should change to calculate the Eend-Estart or E
(from,to).
Dimitris Tsokakis
--- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx> 
wrote:
> Keith,
> your example is a mono-parametric trading system 
> [the only parameter is the period of MA]
> Replace, in the mono-parametric example, your tading rules instead 
of 
> the StochD example.
> It will looks like this
> // A Hi-pass filter
> START=DateNum()==1000530 ;
> x=100;
> EVENT=BarsSince(START)%x==0;
> G=0;CountER=0;
>  for(K=1;K<=200;K=K+1)// let the MA period be from 1 to 200
> {
> // your trading rules
> Buy = ROC(MA(C,K),1)>0;
> Sell = ROC(MA(C,K),1)<0;
> Buy=ExRem(Buy,Sell);Sell=ExRem(Sell,Buy);
> Short=Sell;Cover=Buy;
> Short=ExRem(Short,Cover);Cover=ExRem(Cover,Short);
> 
> E1=Equity(1,0);
> E11=ValueWhen(EVENT,E1);T11=ValueWhen(EVENT,Cum(1));
> G=IIf(G>E11,G,E11);CountER=CountER+1;
> PG=100*(-1+E1/E11);
> }
> CountER=0;Kpass=0;HIPASS=0;
> for(K=1;K<=200;K=K+1)
> 
> {
> // your trading rules
> Buy = ROC(MA(C,K),1)>0;
> Sell = ROC(MA(C,K),1)<0;
> Buy=ExRem(Buy,Sell);Sell=ExRem(Sell,Buy);
> Short=Sell;Cover=Buy;
> Short=ExRem(Short,Cover);Cover=ExRem(Cover,Short);
> 
> 
> E1=Equity(1,0);
> E11=ValueWhen(EVENT,E1);CountER=CountER+1;
> PASS=IIf(E11==G,E1,0);
> HIPASS=HIPASS+PASS;GAIN=100*(-1+HIPASS/G);
> K1=IIf(E11==G,K,0);Kpass=Kpass+K1;G=IIf(E11==G,0,G);
> }
> // Kpass trading application
> Buy = ROC(MA(C,KPASS),1)>0;
> Sell = ROC(MA(C,KPASS),1)<0;
> Buy=ExRem(Buy,Sell);Sell=ExRem(Sell,Buy);
> Short=Sell;Cover=Buy;
> Short=ExRem(Short,Cover);Cover=ExRem(Cover,Short);
> Plot(Kpass,"kpass",1,1);
> Filter=1;
> AddColumn((kpass),"Kpass");
> 
> 
> The QQQ optimization would be
> k=Optimize("k",1,1,200,1);
> Buy = ROC(MA(C,K),1)>0;
> Sell = ROC(MA(C,K),1)<0;
> Buy=ExRem(Buy,Sell);Sell=ExRem(Sell,Buy);
> Short=Sell;Cover=Buy;
> Short=ExRem(Short,Cover);Cover=ExRem(Cover,Short);
> From Jan2000 till now the profits range is from +185% to -98%
> The Inspection Points would give a +53% for the same period
> [buy, sell, short, cover at +1Open, commission 0.25%]
> Note here that my data begins the Jan3, 2000 and all the Equity 
study 
> is based on this fact.
> Note also that the optimal k=1 for the great 99 days was exactly 
the 
> catastrophic parameter for my period [-98.66% !!]
> To execute the research for more data, do not forget to change the
> START=DateNum()==1000530 ;
> to a new, about 6 months after the start of your data.
> I do not have earlier data for QQQ.
> I tried ^NDX from 1995 to now.
> The optimization gave a range -99% to +2220%.
> The Inspection Points were at +634%.
> One interesting detail : The system was long from 30/12/1996 until 
> 18/9/2000 [!!] in one single trade, profitable by +340%.
> It was working from March96 until Xmas 96 with k=49 and, just after 
> Xmas, at the 26/12/1996 inspection, it "understood" that
> it would be better to use k=181. It didnīt change this excellent 
> decision until 11/12/2000 .
> The worse trade was a -7.3% [Jan-Feb 1996]
> The system keeps on making profits after 2000 decline [nearly 
double 
> price the last 3 years] and it is more than 2x the total B&H for 
this 
> 8-year period.
> [Of course it could offer protection against the so many ruine 
> probabilities...]
> Dimitris Tsokakis
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Keith Bennett" <kbennett@xxxx> 
> wrote:
> > Dave and Dimitris,
> > 
> > Is it possible that Dimitri's InspectionPoints approach, or your 
> > Continuous Equity Feedback method could help in the following 
> > situation:
> > 
> > My trade signals are generated by OB/OS indicators in conjunction 
> > with the underlying market trend. Market trend is determined 
either 
> > by MA crossovers or the one day ROC of a moving average. The 
> problem 
> > of course is what MA to use. One that worked well in 1997 for 
> example 
> > was pretty useless in 1999. This can be seen using the following 
> > simplified code where the MA has been optimized for each year.
> > 
> > period = 
> > IIf(Year() == 1995, 105,
> > IIf(Year() == 1996, 29,
> > IIf(Year() == 1997, 143,
> > IIf(Year() == 1998, 4,
> > IIf(Year() == 1999, 1,
> > IIf(Year() == 2000, 25,
> > IIf(Year() == 2001, 150,
> > IIf(Year() == 2002, 43,33))))))));
> > 
> > Buy = ROC(MA(C,period),1)>0;
> > Sell = ROC(MA(C,period),1)<0;
> > Short=Sell;Cover=Buy;
> > 
> > Run on QQQ with no margin it produces a net% profit of 2677%, but 
> > that is with perfect rear vision. I tried unsuccessfully to 
modify 
> > your code to handle this (must spend more time with the user 
guide) 
> > What do you think? Is it worth pursuing?
> > 
> > Keith
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx> 
> > wrote:
> > > 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 ---------------------~-->
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/