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

[amibroker] Re: Optimize function



PureBytes Links

Trading Reference Links

Picking up your "invitation" under PS I wondered if the suggestion 
below is "do-able" in AB.

I have studied the earlier exchange of messages on walk-forward 
methods but from the contenst I could not construct the way I carry 
out the walk-forward exercise; trying to imitate as much as possible 
the reality.
The sequence I follow is:
-	establish the period for the optimization in nr of bars 
(period)
-	set the range to the point in time where the first 
optimization should end say one week from now: (endtime)
-	optimize
-	place parameters in formula
-	move the range an agreed number of bars (bars) nearer the 
last bar in the system  (endtime - bars)
-	backtest for this period
-	copy the results to Excell
-	set the range to the point in time where the second 
optimization should being (endtime - bars)
-	optimize
-	place parameters in formula 
-	move the range again an agreed number of bars nearer the last 
bar in the system  (endtime - bars - bars)
-	backtest for this period
-	copy the results to Excell
-	set the range to the point in time where the third 
optimization should being endtime - bars - bars)
-	optimize
-	etc.

Subsequently in Excell I combine the entries in one trading track 
record by deleting the overlap in time leaving every time the last 
entries, so the true result of the day after the op[timization 
finished.
 
As you can imagine this is tedious work and of course I wondered if 
with the new functions in AB this can be done automatically. 
Unfortunately I am not  a programmer otherwise I would give it a try.

Willem Jan


--- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx> 
wrote:
> "I don't know whether AA's optimization process works like the 
> Optimize function in IB but suspect it might."
> Bill,
> There is a [probable] confusion here:
> From the definition in 4.40 users guide, 
> "With normal backtesting, scanning, exploration and comentary modes 
> the optimize function returns default value, so the above function 
> call returns default; "
> In other words, a code
> p=Optimize("p",40,10,50,10);
> y=StochD(p);
> Plot(y,"y",1,1);
> would produce the graph of StochD(40) and nothing more.
> 
> "However, the basic question is whether k was optimized for the 
> entire dataset or just 2002."
> The described code [as the older ref] does exactly this : It 
> optimizes k for the restricted period.
> "As far as I can tell it is for the entire dataset, reflecting the 
> fact that the Optimize function does not have a time frame argument
> (s) and, therefore, no way to limit its operation to a specified 
time 
> window."
> Since Optimize function does not have time frame arguments, there 
is 
> *another* way to limit its operation : Apply Optimization to the 
> specified time window and you have the required result. Try any AA 
> test and you will see.
> "As a result, I wondered if anyone had a workaround that would 
force 
> the Optimize function to only use data within a specified time 
frame."
> The described codes do this job. You may disagree with the logic, 
but 
> the result is exactly the requested.
> Some AFL functions/procedures are limited to a range of properties, 
> clealy exposed in the definitions. When we need something out of 
> these limitations, we have to use another way.
> There was a similar discussion with variable periods. Some AFL 
> functions do accept variable period, some others dont. If we want a 
> variable per in EMA(C,per), we can not act directly, EMA does not 
> accept variable period. We have to find another, indirect way, to 
do 
> it.
> You ask from Optimize function some results out of its [current] 
> definition . It is not possible. [Imagine the opposite !!!AFL would 
> become an unreliable set of functions !!!]
> IMO, the only way to get a result through AFL is to follow the 
> definitions "mot a mot". Any other attempt would cause mistakes. 
> Sometimes the mistake is prevented by the AFL Error window, but not 
> always.
> There is no code mistake in the lines
> p=Optimize("p",40,10,50,10);
> y=StochD(p);
> Plot(y,"y",1,1);
> but, dont expect from these lines an optimization procedure similar 
> to the OPTIMIZE button, it is N/A [yet]
> I hope it is clear.
> Thank you for the interesting dialogue, I have nothing more to add.
> Dimitris Tsokakis
> PS For "similar" IB procedures we may use for loops and practically 
> have the same results with optimization procedure. I have solved 
the 
> general problem, I think it may be applied to any case, but it 
would 
> be better to ask a specific question.
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "wavemechanic" <wd78@xxxx> wrote:
> > 
> > ----- Original Message ----- 
> > From: "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx>
> > To: <amibroker@xxxxxxxxxxxxxxx>
> > Sent: Friday, September 12, 2003 2:18 PM
> > Subject: [amibroker] Re: Optimize function
> > 
> > 
> > Bill,
> > 
> > (Initial message)
> > k=Optimize("k",40,30,50,10);
> > > d2002=DateNum()>=1020101 AND DateNum()<1030101;
> > > LastTradingBar=(d2002==0 AND Ref(d2002,-1))*DateNum();
> > > Buy=d2002*Cross(StochD(),k);
> > > Sell=d2002*Cross(StochD(),70) OR DateNum()==LastTradingBar;
> > >
> > > Hit now Optimize for
> > > *current stock
> > > *all quotations
> > > AA will see only 2002 dates.
> > 
> > (Second message)
> > Optimization, by itself, has no restriction property.
> > When we say Optimize, the AA will check the settings or whatever
> > overwrites the settings.
> > In my example, the settings are "all quotations".
> > But, the trading rules are restricted by definition:
> > Buy=d2002*Cross(StochD(),k);
> > Sell=d2002*Cross(StochD(),70) ;
> > This d2002 is a binary quantity, equal to 1 or 0, as definrd in 
the
> > previous lines. The d2002*something will give something or 0.
> > Consequently, when d2002 is true, the AA will read
> > Buy=Cross(StochD(),k);
> > Sell=Cross(StochD(),70);
> > and when d2002 is false, the AA will read
> > buy=0;
> > sell=0;
> > Make a scan for all quotations to see. The trades will be for 2002
> > dates only.
> > In other words, in order to optimize from datenum1 to datenum2, 
just
> > define trades for this period only and thatīs it !!
> > 
> > As I mentioned to Leo a few minutes ago, I am not using AA but 
> rather
> > generating charts with IB.  I don't know whether AA's 
optimization 
> process
> > works like the Optimize function in IB but suspect it might.  
With 
> that
> > uncertainty as background, I think we are talking about apples 
and 
> oranges.
> > Yes your code will produce trades only in 2002 with an optimized 
> value for k
> > (optimized in code from first message), and I use other code at 
the 
> present
> > time to achieve similar results.  However, the basic question is 
> whether k
> > was optimized for the entire dataset or just 2002.  As far as I 
can 
> tell it
> > is for the entire dataset, reflecting the fact that the Optimize 
> function
> > does not have a time frame argument(s) and, therefore, no way to 
> limit its
> > operation to a specified time window.  As a result, I wondered if 
> anyone had
> > a workaround that would force the Optimize function to only use 
> data within
> > a specified time frame.  One could, use brute force and manually 
> change the
> > number of bars and time period loaded, but that is too awkward to 
be
> > seriously considered.
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "wavemechanic" <wd78@xxxx> 
wrote:
> > >
> > > ----- Original Message ----- 
> > > From: "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx>
> > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > Sent: Friday, September 12, 2003 12:48 PM
> > > Subject: [amibroker] Re: Optimize function
> > >
> > >
> > > > Bill,
> > > > I have posted in the past the walk-forward optimization.
> > > > Here is the basic principle, for a restricted period 
> optimization
> > > > [year2002 in the example]
> > >
> > > If I correctly understand, optimization of k is still being
> > established on
> > > the entire dataset, rather than only on 2002 data.  Right?  If 
so,
> > how would
> > > you restrict Optimize to operate only in 2002?
> > >
> > > > of a Stochastic o/b, o/s system :
> > > >
> > > > k=Optimize("k",40,30,50,10);
> > > > d2002=DateNum()>=1020101 AND DateNum()<1030101;
> > > > LastTradingBar=(d2002==0 AND Ref(d2002,-1))*DateNum();
> > > > Buy=d2002*Cross(StochD(),k);
> > > > Sell=d2002*Cross(StochD(),70) OR DateNum()==LastTradingBar;
> > > >
> > > > Hit now Optimize for
> > > > *current stock
> > > > *all quotations
> > > > AA will see only 2002 dates.
> > > > It is important to exit any open trade by the end of the test
> > period,
> > > > else the last probable Open trade will last for ever !!
> > > > The solution is that{  OR DateNum()==LastTradingBar } 
statement.
> > > > Dimitris Tsokakis
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "wavemechanic" <wd78@xxxx>
> > wrote:
> > > > >
> > > > > ----- Original Message ----- 
> > > > > From: "Stephane Carrasset" <nenapacwanfr@xxxx>
> > > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > > > Sent: Friday, September 12, 2003 11:55 AM
> > > > > Subject: [amibroker] Re: Optimize function
> > > > >
> > > > >
> > > > > > Bill,
> > > > > >
> > > > > > do you mean if you Backtest for example NDX on the last 
500
> > bars
> > > > > > do you want optimize an indicator on the 500-400 bars?? 
then
> > keep
> > > > the
> > > > > > optimized value on the 400-1 bars ??
> > > > >
> > > > > I was not thinking of that, but your scenario is along the 
> same
> > > > lines and
> > > > > would be a another important option.  I was actually 
thinking 
> of
> > > > the problem
> > > > > from 180 degrees around.  Specifically, for a dataset of, 
for
> > > > example, 1000
> > > > > bars optimize only over the last 500 and display the equity
> > curve
> > > > for that
> > > > > range.  It is possible to only consider (and display) the 
> equity
> > > > for a
> > > > > specified number of bars (e.g., the last 500 bars), but I 
> don't
> > see
> > > > how to
> > > > > restrict optimization to those bars.  Certainly not with the
> > > > available
> > > > > arguments for Optimize.
> > > > >
> > > > > >
> > > > > > Stephane
> > > > > >
> > > > > > > It is my understanding that the Optimize function 
operates
> > on
> > > > all
> > > > > > data.  So,
> > > > > > > for example, if one is looking at equity for a portion 
of
> > the
> > > > data
> > > > > > (e.g.,
> > > > > > > Equity(0, 1, 100) Optimize still operates on all data.  
> Does
> > > > anyone
> > > > > > have a
> > > > > > > work-around that will force Optimize to only consider a
> > > > specified
> > > > > > range of
> > > > > > > data?
> > > > > > >
> > > > > > > Thanks.
> > > > > > >
> > > > > > > Bill
> > > > > >
> > > > > >
> > > > > >
> > > > > > Send BUG REPORTS to bugs@xxxx
> > > > > > Send SUGGESTIONS to suggest@xxxx
> > > > > > -----------------------------------------
> > > > > > 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/
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > Send BUG REPORTS to bugs@xxxx
> > > > Send SUGGESTIONS to suggest@xxxx
> > > > -----------------------------------------
> > > > 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/
> > > >
> > > >
> > 
> > 
> > 
> > Send BUG REPORTS to bugs@xxxx
> > Send SUGGESTIONS to suggest@xxxx
> > -----------------------------------------
> > 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/


------------------------ 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/l.m7sD/LIdGAA/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/