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

Re: [amibroker] Re: How to calculate a slope % with Rsquared without a loop?



PureBytes Links

Trading Reference Links

Hello,
 
R-squared is calculated straightforward from correlation.
Constant period Correlation is built-in in AB.
 
Variable period correlation can be easily coded as well as variable period
R-squared. The slope can is just LinRegSlope - built in function that supports variable periods already.
Not a single loop required.
 
// variable-period Correlation
function
CorrV( x, y, range  )
{

  avX =
MA
( x, range );
  avY =
MA
( y, range );
  avXY =
MA
( x * y, range );
  
  ssqrX =
Sum
( x * x, range );
  ssqrY =
Sum
( y * y, range );

  VarX =
Max( ssqrx/range - avX * avX, 0
);
  VarY =
Max( ssqry/range - avY * avY, 0
);

  
return ( avXY - avX * avY  ) / sqrt
( VarX * VarY );
}

// variable-period R squared

function
RSquaredV( array, range )
{
   
return   CorrV( BarIndex()+1, array, range ) ^ 2
;
}


Graph0 = RSquaredV( C, 10
);


Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: Louis P.
Sent: Friday, September 05, 2008 9:03 PM
Subject: Re: [amibroker] Re: How to calculate a slope % with Rsquared without a loop?

Hi,

Ok I will try to look at this (or maybe someone else can help?)  but how to do this without a loop. To what would such a code look like?

Thanks,

Louis



2008/9/5 sidhartha70 <sidhartha70@xxxxxxxxx>

Louis,

I have no experience of doing this in AFL. Perhaps others can guide.
But LinRegSlope() looks like it will do the trick.

Look at this...

http://www.amibroker.com/library/detail.php?id=233&hilite=LINREGSLOPE



--- In amibroker@xxxxxxxxxxxxxxx, "Louis P." <rockprog80@xxx> wrote:
>
> Hi,
>
> How would you write this in AFL? I mean: Let's say I want a gradient at
> about 10 degrees... How would you do that? And how to measure the
> dispersion along this line? Can Rsquared be used?
>
> Thanks,
>
> Louis
>
> 2008/9/5 sidhartha70 <sidhartha70@xxx>

>
> > Well, clearly the gradient of the slope will depend on the time
> > interval you are looking at for the price move.
> >
> > But the basic formula is,
> >
> > Change in Y (price) / Change in X (Time)
> >
> > It's very simple... If you are asking for what I think you are
asking for.
> >
> > Look at this,
> >
> >
> >
http://www.teacherschoice.com.au/Maths_Library/Gradient/gradient_-_two_fixed_points.htm
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%40yahoogroups.com>,
"Louis P."
> > <rockprog80@> wrote:
> > >
> > > Hmm.. I am not sure... But I want the data to be as close to
> > possible to a
> > > straight line and the slope to be not too steep but enough...
> > >
> > > 2008/9/5 sidhartha70 <sidhartha70@>
> > >
> > > > Louis,
> > > >
> > > > you mean you want the 'gradient' of the slope...?? Straight lines
> > > > can't be 'smooth' or otherwise.
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%

> > 40yahoogroups.com>,
> >
> > "Louis P."
> > > > <rockprog80@> wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > @Joe Landry: Thanks for the tips. I'm not sure how the
K-ratio can
> > > > help on
> > > > > this, but if it can help...
> > > > >
> > > > > @Ara: I'm sorry if what I said was not clear. What I want to do
> > is to
> > > > > calculate a % pullback from a HHV of a stock but I want the
> > slope to be
> > > > > "smooth", that is, I am not happy to see a 5 or 10% pullback but
> > > > would like
> > > > > to see a 5 or 10% pullback with a particular slope inclination.
> > > > That is:
> > > > > if the stock dropped 10% in a day is not the same as if it
quietly
> > > > lost 0.5%
> > > > > for 20 days (would not be exactly 10%, but this is an
image). You
> > > > > understand what I mean? I want the slope to be as smooth as
> > > > possible with a
> > > > > particular inclation %. Is this possible?
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Louis
> > > > >
> > > > >
> > > > >
> > > > > 2008/9/5 Ara Kaloustian <ara1@>
> > > > >
> > > > > > Louis,
> > > > > >
> > > > > > I am not quite sure what you mean by "a smooth slope".
> > > > > >
> > > > > > Do you want to have a plot of prices that are smoothed ...
as you
> > > > would gt
> > > > > > with a filter??
> > > > > >
> > > > > > OR do you want a computed value of slope at some
particular point?
> > > > ... if
> > > > > > so at what point ... or do you want a plot of the slope
... etc
> > > > > >
> > > > > > If you can be moe specific that would be halpful!
> > > > > >
> > > > > > A
> > > > > >
> > > > > > **
> > > > > >
> > > > > >
> > > > > > ----- Original Message -----
> > > > > > *From:* Louis P. <rockprog80@>
> > > > > > *To:* amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>
> > > > > > *Sent:* Friday, September 05, 2008 8:41 AM
> > > > > > *Subject:* Re: [amibroker] How to calculate a slope % with
> > Rsquared
> > > > > > without a loop?
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > Linear function is my big problem. I'm so weak using that.
What
> > > > is the
> > > > > > difference between using this and doing it the other way?
> > > > > >
> > > > > > BTW, how would you set the number of bars in the current:
> > > > > >
> > > > > > HHVBars(Var,period); // Find number of bars - distance
from HHV to
> > > > current
> > > > > > bar
> > > > > > %slope = ((Highest high - currentclose) / Highest high) /
number
> > > > of bars *
> > > > > > 100;
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Louis
> > > > > >
> > > > > >
> > > > > > 2008/9/4 Ara Kaloustian <ara1@>
> > > > > >
> > > > > >> You can also use linearray to draw a stright line from HHV to
> > > > current
> > > > > >> point.
> > > > > >>
> > > > > >> Look up LinearReg function
> > > > > >>
> > > > > >> ----- Original Message -----
> > > > > >> *From:* Ara Kaloustian <ara1@>
> > > > > >> *To:* amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>
> > > > > >> *Sent:* Thursday, September 04, 2008 10:37 AM
> > > > > >> *Subject:* Re: [amibroker] How to calculate a slope % with
> > Rsquared
> > > > > >> without a loop?
> > > > > >>
> > > > > >> Try this:
> > > > > >>
> > > > > >> HHV(Var,period); // find value of highest high
> > > > > >> HHVBars(Var,period); // Find number of bars - distance
from HHV
> > > > to current
> > > > > >> bar
> > > > > >> %slope = ((Highest high - currentclose) / Highest high) /
number
> > > > of bars *
> > > > > >> 100;
> > > > > >>
> > > > > >> You may choose to define slope in a different way, but
this is
> > > > the basic
> > > > > >> structure
> > > > > >>
> > > > > >> A
> > > > > >>
> > > > > >> ----- Original Message -----
> > > > > >> *From:* Louis P. <rockprog80@>
> > > > > >> *To:* amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>
> > > > > >> *Sent:* Thursday, September 04, 2008 9:34 AM
> > > > > >> *Subject:* Re: [amibroker] How to calculate a slope % with
> > Rsquared
> > > > > >> without a loop?
> > > > > >>
> > > > > >> Hi,
> > > > > >>
> > > > > >> Thanks for your response. I should have said I want to
calculate
> > > > a slope
> > > > > >> from a high point; I'd like to get a smooth slope from a
HHV...
> > > > How would
> > > > > >> you do that?
> > > > > >>
> > > > > >> Thanks a lot!
> > > > > >> Louis
> > > > > >>
> > > > > >> 2008/9/4 Ara Kaloustian <ara1@>
> > > > > >>
> > > > > >>> %slope = (variable - Ref(Variable,-x) ) / Ref(Variable,-x) *
> > 100;
> > > > > >>>
> > > > > >>> ----- Original Message -----
> > > > > >>> *From:* Louis P. <rockprog80@>
> > > > > >>> *To:* amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>
> > > > > >>> *Sent:* Thursday, September 04, 2008 9:20 AM
> > > > > >>> *Subject:* [amibroker] How to calculate a slope % with
Rsquared
> > > > without
> > > > > >>> a loop?
> > > > > >>>
> > > > > >>> Hi,
> > > > > >>>
> > > > > >>> I was wondering how to calculate the % of a slope without
> > doing any
> > > > > >>> loop. Anybody has any idea?
> > > > > >>>
> > > > > >>> Thanks,
> > > > > >>>
> > > > > >>> Louis
> > > > > >>>
> > > > > >>>
> > > > > >>
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> >
>


__._,_.___

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




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

__,_._,___