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

Re: [amibroker] Re: Newbie Array / Looping Question



PureBytes Links

Trading Reference Links



Hi Brian,

Hmmmm... could be a typo in the manual
I certainly had no idea that MA() could do this.

    myX = MA(C, 1);                  // AFL happy
    myX = Median(C, 1);             // AFL happy
    myX = MA(C, Cum(1));        // AFL happy
    myY = Median(C, Cum(1));   // "Argument has incorrect type"

You must have a huge amout of hands on with AFL!
Some of the functions in AFL take either arrays, or
numbers, and a few seem to be able to take both:
Not sure what language AB is written in suspect its
probably C++ which allows you to do this sort of
thing.

    Looking at the entry for "int()"

    INT
    − integer part
    SYNTAX int( NUMBER )
                     int( ARRAY)

    I suspect the manual entry for MA() should be the
    same!

I'm currently looking at the "_TRACE()" command to try
and garner some insight into the execution process.

I'm keener on your suggestion regarding using the arithmetic
now that I now that MA(array, array) works! And yes,
I'd prefer the faster option every time! But I also like to
think that I'll find other, and perhaps more meaningful
"profile attributes" which have nothing to do with the
old distributions! That's why I've been looking for a
generic solution

The R package looks intriging too. But I still have to
learn how AB works in it's basic mode before I
unduly complicate my life with other packages etc...

The following construct works - but it is very, very
slow.....

function myMedian( array, i )
    {      
        x = array[i];
        return x;
    }

    mp2   = 1;
    for( i = 1; i < BarCount; i++ )        
    {
        mp2[ i ] = myMedian(Median(C,i),i);   
    }


Thanks for your help once again!

Robert Z



From: brian_z111 <brian_z111@xxxxxxxxx>
To: amibroker@xxxxxxxxxxxxxxx
Sent: Friday, 5 June, 2009 5:00:41 PM
Subject: [amibroker] Re: Newbie Array / Looping Question

<snip>Median( ) wants a number as its second argument. (The manual is clear!)<snip>

To help me understand next time ... how did you decide that Median)array, period) wants a number from what is written in the manual?

MA(array,periods) ; accepts an array and the only differential in the manual is plurality of the periods (do you think Tomasz intended the plurality to be significant? )

MA(C,Cum(1)) ;//this is OK?

<snip> When are the "for" loops executed in the block of code? Knowing some more about the AFL execution order might be helpful.<snip>

Sorry, don't know anything about execution.

Recently Siddhartha said that learning the AFL execution was the best thing we can ever do ... I don't know where to find it though.

You are not keen on my suggestion that calcs for the moments are arithmetic and so should fly in AFL without looping?
I am a lay programmer but my instinct is to start there - looping will slow you down in RT indicators?? ?

Plan C - use the RMath Plugin ... advanced stats available there.

--- In amibroker@xxxxxxxxx ps.com, i cs <ics4mer@xxx > wrote:
>
> Hi Brian,
>
> Thanks for getting back to me.
>
> Unfortunately, Cum() returns array, Median() wants a number as its
> second argument. (The manual is clear!)
>
> I used median as an example because it's relatively easy to understand,
> and I will be using it, but I will also be plotting the growth factor in the same
> way - as well as the other moments of distribution - just one step at a time.
>
> Its possible to derive a lot of the moments of distribution from other the
> parts, but it comes back to the same problem - I'd have to write functions
> to derive kurtosis, mode etc.
>
> Some of the historic emails in the group included the following solutions:
> - code the functions myself - which I'm trying to avoid.
> - create a dynamic set of variables using VarSet - this seems a bit brutish
> especially if you are playing with a number of "profile attributes".
>
> When are the "for" loops executed in the block of code? Knowing some more
> about the AFL execution order might be helpful. Might go down that track for
> a while....and check out the other 1500 references to "loop" in the email
> group.
>
> Thanks again...
> Robert Z
>
>
>
>
>
> ____________ _________ _________ __
> From: brian_z111 <brian_z111@ ...>
> To: amibroker@xxxxxxxxx ps.com
> Sent: Friday, 5 June, 2009 2:57:43 PM
> Subject: [amibroker] Re: Newbie Array / Looping Question
>
>
>
>
>
> I am not sure about this one now ... I think we need some help from the code/maths experts.
>
> Median() doesn't appear to accept an array as input (the manual doesn't say one way or another?) ... it might be demanding a constant (that wouldn't surprize me since mean/mode/median are moments of a distribution so massive calcs might be required to find them for skewed dists without having the distriution at hand) ... AB doesn't do that distributions off the shelf ... not AFAIK.
>
> I think you can calc Skewness from N, StDev, arithmetic mean etc ... once you have S you can back calc the Median or the Mode from the Mean and the StDev.
>
> Another brute method might be an algorithmic trial and error test for the Mode (loops required)... I forget what it is called in programming but if the value to the right of the mean has a higher frequency than the mean value the mode is somewhere to the right .. by halving the range between the freq test you will zero in on the mode and then you can calc the median by using the mean and mode values..... AFAIK array processing will always be more timely than looping though.
>
> --- In amibroker@xxxxxxxxx ps.com, "brian_z111" <brian_z111@ ...> wrote:
> >
> > Median(array, periods)
> >
> > I assume you are measuring, say ROC(C,1) or similar for % price change.
> > I guess you just need to get a progressive count, of the number of ROC datapoints, to make the function work.
> >
> > Things to look out for (if the AB function is going to work for you):
> >
> > - every element in the array you are measuring needs a value (nulls or zeros might trip up the math e.g. STDev, mean) ... I guess if you are interested in daily bars you will first create a daily ROC(C,1) or ROC of some other point of interest from within the bar HL range
> > - the number of periods, in your array count, is range dependent i.e. in AB it can vary with mode ... QuickAFL can be used to change the range (in AA) and QickAFL will autoset the range in charts (or might ... I am not the full bottle on QuickAFL but there is an article by Tomasz in the AB KnowledgeBase)
> > - BarsSince type functions might count one less period than you expect ... depending if the function is a zerobased count and how you want to use the count.... sometimes I have to add 1 to make the adjustment manually
> > - BarIndex() is the bar by bar count since the start of the range, where range == the range of the database ... AB gets a bit tricky with when and where it uses the complete database range as the default .... probably to do with fast array processing etc ...sometimes I prefer to use Cum(1) as my count ... I seem to get more visually stable indicators in the charts because it doesn't reference the chart range it references from the start of the database.
> >
> > - so, making a few assumptions, and if Median works for you as required, Median(ROC(C, 1),Cum(1) ); // because Cum(1) is progressive and counts bars from the beginning
> >
> > - mathematically I find ROC is not as stable as GrowthFactor where ROC == 3% is expressed as 1.03
> >
> > Haven't done it though.
> >
> > If that doesn't work maybe someone else in the forum knows more.
> >
> > In case of emergency RVince book two has the maths for median, mode, mean interelationships (possibly for advanced, or custom use, you could calculate the median from other values).... mean == median == mode for normal distributions (you should be so lucky!)
> >
> >
> >
> >
> > --- In amibroker@xxxxxxxxx ps.com, "ics4mer" <ics4mer@> wrote:
> > >
> > > Hi all,
> > >
> > > I'm after a general form for doing a particular type of algorithm
> > > in AFL - and I'm happy to admit that I might be going about it
> > > the totally wrong way...
> > >
> > > I am attempting to extract an evolving "profile" of a stock over
> > > time.
> > >
> > > Using "median" as an example, lets say I want calculate the median
> > > percentage price change for the life of the stock. To give an
> > > example:
> > >
> > > The 1st trading day - do nothing.
> > > The 2nd trading day - calc median for 2 days
> > > The 3rd trading day - calc median for 3 days
> > > Last traded day - calc median for n days.
> > >
> > > For simple functions, I have used a construct similar to;
> > > for ( i=0; i < BarCount; i++ ){
> > > myArray[ i ] = simpleFunc( i );
> > > .....
> > > }
> > >
> > > However, in this case, I would have to write a new median function,
> > > and this is irritating, since there is a perfectly good one
> > > taunting me from the users manual! That's why I suspect that I
> > > might be doing something in the wrong way.
> > >
> > > Any help or pointers would be much appreciated. A pointer to
> > > a message in the user group would be fine too! ( Yes I am still
> > > trawling through the email group as I write this....)
> > >
> > > TIA
> > >
> > > Robert Z
> > >
> >
>
>
>
>
>
> Need a Holiday? Win a $10,000 Holiday of your choice. Enter now.http://us. lrd.yahoo. com/_ylc= X3oDMTJxN2x2ZmNp BF9zAzIwMjM2MTY2 MTMEdG1fZG1lY2gD VGV4dCBMaW5rBHRt X2xuawNVMTEwMzk3 NwR0bV9uZXQDWWFo b28hBHRtX3BvcwN0 YWdsaW5lBHRtX3Bw dHkDYXVueg- -/SIG=14600t3ni/ **http%3A/ /au.rd.yahoo. com/mail/ tagline/creative holidays/ *http%3A/ /au.docs. yahoo.com/ homepageset/ %3Fp1=other% 26p2=au%26p3= mailtagline
>



Need a Holiday? Win a $10,000 Holiday of your choice. Enter now..

__._,_.___


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

__,_._,___