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

[amibroker] Re: Portfolio rotation



PureBytes Links

Trading Reference Links

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