PureBytes Links
Trading Reference Links
|
My approach should not create any gaps in the account. It probably
has to do with some of the other AA options. I also have:
SetBacktestMode(backtestRotational);
SetTradeDelays(1,1,1,1); // everything delayed 1 day
SetOption("UsePrevBarEquityForPosSizing", True);
SetOption("MinShares", 0);
SetOption("AllowPositionShrinking",True);
LastDayOfMonth = IIf(Day() > Ref(Day(),1),1,0);
PositionScore = IIf(LastDayOfMonth, PositionScore, scoreNoRotate);
--- In amibroker@xxxxxxxxxxxxxxx, "droskill" <droskill@xxx> wrote:
>
> Well, I thought I had it, but I was looking over the trades done
using
> Ron's method below, and it creates gaps in the account. In other
> words, there are times when you get an exit and then there is a
delay
> before the next entry. As a reminder, what I'm trying to do here is
> make it so that rebalancing ONLY happens on the first day of the
month
> - so both entries and exit. I'm including my now greatly simplified
> AFL to see if anyone has any ideas.
>
> EnableRotationalTrading();
> EachPosPercent = 100; //We want to rotate to only one position
>
> PositionScore = 1000 + ROC (C, 20) //Long only
>
> PositionSize = -EachPosPercent;
>
> SetOption("WorstRankHeld", 1 );
> SetOption("MaxOpenPositions", 1 );
> SetOption("UseCustomBacktestProc", True );
>
> if( Status("action") == actionPortfolio )
> {
> bo = GetBacktesterObject();
>
> bo.PreProcess(); // Initialize backtester
>
> mo = Month();
> dy = Day();
> monthchange = mo != Ref( mo, -1 );
> sma = MA(C,200);
> Cls = C;
>
> for(bar=0; bar < BarCount; bar++)
> {
>
> if ( monthchange[ bar ] AND dy[ bar ] < 3 )
> {
> bo.ProcessTradeSignals( bar );
> }
> }
> bo.PostProcess(); // Finalize backtester
> }
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "droskill" <droskill@> wrote:
> >
> > Ron - thanks - that's much simpler - appreciate your help.
> >
> > Question - the Ref(Day(),1) portion of the IIF - is that
referencing
> > the day before or the day after?
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Ron Rowland" <rowland@> wrote:
> > >
> > > I'm sorry I didn't see this thread earlier. I have a simple
two line
> > > approach to this problem:
> > >
> > > LastDayOfMonth = IIf(Day() > Ref(Day(),1),1,0);
> > > PositionScore = IIf(LastDayOfMonth, PositionScore,
scoreNoRotate);
> > >
> > > I also have trade delays set for one day. Using the above then
> > > allows all securities to be analyzed with daily data on the
last day
> > > of the month with the trade taking place on the first day of
the
> > > following month.
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "droskill" <droskill@> wrote:
> > > >
> > > > In the interest of the group which has been so helpful, I'm
posting
> > > > the code change that worked - that makes the rotation happen
only on
> > > > the first trading day of the month - comments/critique
welcome.
> > > >
> > > > EnableRotationalTrading();
> > > > EachPosPercent = 25;
> > > >
> > > > PositionScore = 1000 + ROC (C, 20);
> > > >
> > > > PositionSize = -EachPosPercent;
> > > >
> > > > SetOption("WorstRankHeld", 4 );
> > > > SetOption("MaxOpenPositions", 4 );
> > > > SetOption("UseCustomBacktestProc", True );
> > > >
> > > > if( Status("action") == actionPortfolio )
> > > > {
> > > > bo = GetBacktesterObject();
> > > >
> > > > bo.PreProcess(); // Initialize backtester
> > > >
> > > > mo = Month();
> > > > dy = Day();
> > > > monthchange = mo != Ref( mo, -1 );
> > > >
> > > > for(bar=0; bar < BarCount; bar++)
> > > > {
> > > >
> > > > if ( monthchange[ bar ] AND dy[ bar ] < 3 )
> > > > {
> > > > bo.ProcessTradeSignals( bar );
> > > > }
> > > > if( monthchange[ bar ] AND dy[ bar ] < 3 )
> > > > {
> > > > CurEquity = bo.Equity;
> > > >
> > > > for( pos = bo.GetFirstOpenPos(); pos;
pos =
> > > bo.GetNextOpenPos() )
> > > > {
> > > > posval = pos.GetPositionValue();
> > > >
> > > > diff = posval - 0.01 * EachPosPercent
*
> > > CurEquity;
> > > > price = pos.GetPrice( bar, "O" );
> > > >
> > > > // rebalance only if difference between desired and
> > > > // current position value is greater than 0.5% of equity
> > > > // and greater than price of single share
> > > > if( diff != 0 AND
> > > > abs( diff ) > 0.005 * CurEquity AND
> > > > abs( diff ) > price )
> > > > {
> > > > bo.ScaleTrade( bar, pos.Symbol, diff
< 0,
> > > price, abs( diff ) );
> > > > }
> > > > }
> > > > }
> > > > }
> > > > bo.PostProcess(); // Finalize backtester
> > > > }}
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@>
wrote:
> > > > >
> > > > > Hello,
> > > > >
> > > > > Taking the example and modifying it to fit your
requirements is
> > > just
> > > > a matter
> > > > > of minutes ! Don't be lazy.
> > > > >
> > > > > EnableRotationalTrading();
> > > > > EachPosPercent = 5;
> > > > >
> > > > > PositionScore = ROC( C, 20 );
> > > > >
> > > > > PositionSize = -EachPosPercent;
> > > > >
> > > > > SetOption("WorstRankHeld", 40 );
> > > > > SetOption("MaxOpenPositions", 20 );
> > > > >
> > > > > SetOption("UseCustomBacktestProc", True );
> > > > >
> > > > > if( Status("action") == actionPortfolio )
> > > > > {
> > > > > bo = GetBacktesterObject();
> > > > >
> > > > > bo.PreProcess(); // Initialize backtester
> > > > >
> > > > > mo = Month();
> > > > >
> > > > > monthchange = mo != Ref( mo, -1 );
> > > > >
> > > > >
> > > > > for(bar=0; bar < BarCount; bar++)
> > > > > {
> > > > > bo.ProcessTradeSignals( bar );
> > > > >
> > > > >
> > > > > if( monthchange[ bar ] )
> > > > > {
> > > > > CurEquity = bo.Equity;
> > > > >
> > > > > for( pos = bo.GetFirstOpenPos(); pos; pos =
bo.GetNextOpenPos
> > > () )
> > > > > {
> > > > > posval = pos.GetPositionValue();
> > > > >
> > > > > diff = posval - 0.01 * EachPosPercent * CurEquity;
> > > > > price = pos.GetPrice( bar, "O" );
> > > > >
> > > > > // rebalance only if difference between desired and
> > > > > // current position value is greater than 0.5% of equity
> > > > > // and greater than price of single share
> > > > > if( diff != 0 AND
> > > > > abs( diff ) > 0.005 * CurEquity AND
> > > > > abs( diff ) > price )
> > > > > {
> > > > > bo.ScaleTrade( bar, pos.Symbol, diff < 0, price, abs(
> > > diff ) );
> > > > > }
> > > > > }
> > > > >
> > > > > }
> > > > > }
> > > > > bo.PostProcess(); // Finalize backtester
> > > > > }
> > > > >
> > > > >
> > > > > Best regards,
> > > > > Tomasz Janeczko
> > > > > amibroker.com
> > > > > ----- Original Message -----
> > > > > From: "droskill" <droskill@>
> > > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > > > Sent: Saturday, March 15, 2008 10:34 PM
> > > > > Subject: [amibroker] Re: Portfolio rotation
> > > > >
> > > > >
> > > > > > This example shows rebalancing to a fixed % at any time -
is
> > > there an
> > > > > > example that shows rebalancing on a specific day - I'm
trying to
> > > > > > rebalance on a first trading day of the week or month.
> > > > > >
> > > > > > Any help greatly appreciated Tomasz!
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko"
<groups@>
> > > wrote:
> > > > > >>
> > > > > >> Yes you can and there is an example code posted:
> > > > > >> http://www.amibroker.com/kb/2006/03/06/re-balancing-open-
> > > positions/
> > > > > >>
> > > > > >>
> > > > > >> Best regards,
> > > > > >> Tomasz Janeczko
> > > > > >> amibroker.com
> > > > > >> ----- Original Message -----
> > > > > >> From: "droskill" <droskill@>
> > > > > >> To: <amibroker@xxxxxxxxxxxxxxx>
> > > > > >> Sent: Saturday, March 15, 2008 5:34 PM
> > > > > >> Subject: [amibroker] Portfolio rotation
> > > > > >>
> > > > > >>
> > > > > >> > Hey all - I've been looking at the automatic portfolio
> > > rotation
> > > > > >> > feature of AB, and I had a question - if I want to
control
> > > the time
> > > > > >> > element of the rotation, would I have to use the
regular
> > > > backtester?
> > > > > >> >
> > > > > >> > In other words, let's imagine that instead of
rebalancing
> > > > "on-demand"
> > > > > >> > - let's imagine that I want to only rebalance once per
week
> > > or once
> > > > > >> > per month - can I do this with the rotational
portfolio?
> > > > > >> >
> > > > > >> > Thanks!
> > > > > >> >
> > > > > >> >
> > > > > >> >
> > > > > >
> > > >
> > >
======================================================================
> > > ==
> > > > > >> > Groups related to amibroker
> > > > > >> >
> > > > > >
> > > >
> > >
======================================================================
> > > ==
> > > > > >> >
> > > > > >> > equismetastock (734 common members)
> > > > > >> >
> > > > > >
> > > > http://groups.yahoo.com/group/equismetastock?
> > > v=1&t=ipt&ch=email&pub=groups&slk=aftr0&sec=recg
> > > > > >
> > > > > >> > Investments/General: Established January 15, 1999 this
site
> > > is
> > > > > > open to ...
> > > > > >> >
> > > > > >> > TWSAPI (656 common members)
> > > > > >> >
> > > > > >
> > > > http://groups.yahoo.com/group/TWSAPI?
> > > v=1&t=ipt&ch=email&pub=groups&slk=aftr1&sec=recg
> > > > > >
> > > > > >> > Investments/Software: Not affiliated with Interactive
Brokers
> > > > > > Interactiv...
> > > > > >> >
> > > > > >> > bse-nse2005 (485 common members)
> > > > > >> >
> > > > > >
> > > > http://groups.yahoo.com/group/bse-nse2005?
> > > v=1&t=ipt&ch=email&pub=groups&slk=aftr2&sec=recg
> > > > > >
> > > > > >> > Investments/Online Investing and Trading: We now have
our
> > > very own
> > > > > > website - www.desitraderm...
> > > > > >> >
> > > > > >> > e-mini_traders_anon (364 common members)
> > > > > >> >
> > > > > >
> > > > http://groups.yahoo.com/group/e-mini_traders_anon?
> > > v=1&t=ipt&ch=email&pub=groups&slk=aftr3&sec=recg
> > > > > >
> > > > > >> > Investments/Daytrading: The spirit of this group is
traders
> > > > > > helping trader...
> > > > > >> >
> > > > > >> > quotes-plus (334 common members)
> > > > > >> >
> > > > > >
> > > > http://groups.yahoo.com/group/quotes-plus?
> > > v=1&t=ipt&ch=email&pub=groups&slk=aftr4&sec=recg
> > > > > >
> > > > > >> > Investments/Software: This group is for Quotes Plus
> > > customers.
> > > > > > Others ar...
> > > > > >> >
> > > > > >> >
> > > > > >> > ------------------------------------
> > > > > >> >
> > > > > >> > Please note that this group is for discussion between
users
> > > only.
> > > > > >> >
> > > > > >> > To get support from AmiBroker please send an e-mail
directly
> > > to
> > > > > >> > SUPPORT {at} amibroker.com
> > > > > >> >
> > > > > >> > For NEW RELEASE ANNOUNCEMENTS and other news always
check
> > > DEVLOG:
> > > > > >> > http://www.amibroker.com/devlog/
> > > > > >> >
> > > > > >> > For other support material please check also:
> > > > > >> > http://www.amibroker.com/support.html
> > > > > >> > Yahoo! Groups Links
> > > > > >> >
> > > > > >> >
> > > > > >> >
> > > > > >>
> > > > > >
> > > > > >
> > > > > >
> > > > > > ------------------------------------
> > > > > >
> > > > > > Please note that this group is for discussion between
users
> > > only.
> > > > > >
> > > > > > To get support from AmiBroker please send an e-mail
directly to
> > > > > > SUPPORT {at} amibroker.com
> > > > > >
> > > > > > For NEW RELEASE ANNOUNCEMENTS and other news always check
> > > DEVLOG:
> > > > > > http://www.amibroker.com/devlog/
> > > > > >
> > > > > > For other support material please check also:
> > > > > > http://www.amibroker.com/support.html
> > > > > > Yahoo! Groups Links
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
------------------------------------
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|