Re: [amibroker] Re: Rebalance a portfolio

 


Hi,



How can the program be modified for an unequal portfolio e.g. 50%, 30%, 20% ?




Thanks,
Amarjit





----Original message----
From : amibroker@yahoogroups.com
Date : 20/04/2016 - 05:48 (GMTDT)
To : amibroker@yahoogroups.com
Subject : [amibroker] Re: Rebalance a portfolio

 

This code should do it. Just set up a watchlist with the three ETFs that you want to rebalance weekly, use that as your Apply to Filter, set up the daterange and hit backtest.

EnableRotationalTrading();
SetTradeDelays( 0,0,0,0 );
firstdayofweek = DayOfWeek() < Ref( DayOfWeek(), -1 );
EachPosPercent = 33.333;
PositionScore = IIf( firstdayofweek, 1, scoreNoRotate );
PositionSize = -EachPosPercent;
SetOption( "InitialEquity", 100000 );
SetOption( "WorstRankHeld", 3 );
SetOption( "MaxOpenPositions", 3 );

SetOption( "UseCustomBacktestProc", True );

if( Status( "action" ) == actionPortfolio )
{
    bo = GetBacktesterObject();
    bo.PreProcess();
    for( bar = 0; bar < BarCount; bar++ )
    {
        bo.ProcessTradeSignals( bar );
        CurEquity = bo.Equity;
        if( firstdayofweek[bar] == 1 )
        {
            for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
            {
                posval = pos.GetPositionValue();
                diff = posval - 0.01 * EachPosPercent * CurEquity;
                price = pos.GetPrice( bar, "O" );
                if( diff != 0 AND abs( diff ) > price )
                {
                    bo.ScaleTrade( bar, pos.Symbol, diff < 0, price, abs( diff ) );
                }
            }
        }
    }
    bo.PostProcess();
}



__._,_.___

Posted by: "a.chandhial@btinternet.com" <a.chandhial@btinternet.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (7)

Upgrade your account with the latest Yahoo Mail app
Get organized with the fast and easy-to-use Yahoo Mail app. Upgrade today!

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/


.

__,_._,___


EmoticonEmoticon