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

Re: [amibroker] Re: Constructing a return-based composite



PureBytes Links

Trading Reference Links



Thanks as always.  A follow up question ...
 
The code you provided is for a known number of securities.  What if I just want to equal weight based on however many securities are trading at that date?
 
I could average the returns using AddToComposite, but is there a way to avoid that step?

--- On Sun, 11/8/09, Bruce <brucer@xxxxxxxxx> wrote:

From: Bruce <brucer@xxxxxxxxx>
Subject: [amibroker] Re: Constructing a return-based composite
To: amibroker@xxxxxxxxxxxxxxx
Date: Sunday, November 8, 2009, 10:29 PM

 
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@xxxxxxxxx ps.com, Nick de Peyster <nickdepeyster@ ...> 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___