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

[amibroker] Re: Constructing a return-based composite



PureBytes Links

Trading Reference Links

Nick - 

This is something that the FastTrack group has done for many years in a language called "Trade".  Trade is actually a matrix processing language where the rows are tickers and the columns are bars.  Very powerful for bulk operations on watchlists, but somewhat primitive in other areas.  For example, it has no looping, so it made everyone get inventive in coming up with array based solutions.

So let's take the mixing of the daily ROC's of tickers.  FIRST RECOGNIZE THAT THIS IS EQUIVALENT TO A DAILY RE-BALANCE.  This is fine for the majority of portfolio modeling applications.  There are some caveats for spreads though, that are too much to go into now.

This is a powerful technique, though, for modeling portfolios.  I'll eventually do an article on AmibrokerU and show how to re-balance on other periods, or on any signal.

But for now, lets say that you want to mix two tickers 60/40 and scale it to a start value of 1000.  Here's the traditional approach to that -

rocmix = Nz( ROC( data1, 1 ) ) * 0.60 + Nz( ROC( data2, 1 ) ) * 0.40;
dailyfact = 1 + ROCmix / 100;
res = 0;
res[ 0 ]= 1000;
for ( i = 1; i < BarCount; i++ )
    res[ i ] = res [ i - 1 ] * dailyfact[ i ];

Now, this works fine, but can be slow.  There is a better way.  Remember from Algebra that addition in the log domain converts to multiplication in the linear domain.  So, we can replace the above with array logic -

rocmix = Nz( ROC( data1, 1 ) ) * 0.60 + Nz( ROC( data2, 1 ) ) * 0.40;
dailyfact = 1 + ROCs / 100;
res2 = exp( Cum( log( dailyfact ) ) ) * 1000;

(There is even a faster was to do this with another AB function, but that is probably too fine a point.)

Lastly, as always, the devil is in the details.  Just to mention a one fairly major issue - Mixing data that has different start dates requires a little more work to get a weighted mix where the sum of the weights can vary over time.

Hope this helps.

-- BruceR





--- In amibroker@xxxxxxxxxxxxxxx, Nick de Peyster <nickdepeyster@xxx> wrote:
>
> I searched the documentation but couldn't find an answer on this.
>  
> Let's say I have ten stocks and I want to create a composite index of how those stocks are performing.  The documentation on AddToComposite shows how to combine closing prices into a composite, but this is a bad solution:  a high-priced stock will dominate the performance of the index.
>  
> A better calculation would be to calculate the daily return of each stock in the index, average the individual returns and record the daily return values.  Then compound them out into a cumulative time series return ... has any one tried this?
>  
> It would seem pretty easy to use ROC(Close,1) with AddToComposite to get the weighted average prices.  What's missing is compounding them out daily into a cumulative return curve.
>  
>  
>  
>  
>




------------------------------------

**** 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/

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/