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

[amibroker] Re: Need some math help to code NORMSDIST into AB.



PureBytes Links

Trading Reference Links

I'm a minor enthusiast of macroeconomics, and can sum up all you need to
know about this indicator:  When the probabilities get up into the
mid-60's or so there's a strong likelihood of economic recession within
4-6 quarters, and it has serious implications for the general stock
market during that lead-time.  By "serious implications" I mean flat
LTBH returns and either larger, sharper or larger and sharper
corrections than the typical ones that occur in the normal course of
markets doing what they do.  The signals are infrequent though, and the
reading is currently around 43%-44% (not significant, regardless of
lead-time).

I use it as a simple, all-around macro indicator so that I don't have to
permanently maintain a huge database of individual economic indicators.

May I ask you one more (very embarrassing) question?:)  I didn't realize
before that the function code you gave me could be entered directly
as-is into an indicator ( I lifted out the formulas and supplied the
inputs, being unsure what to do with what you gave me).   But even
knowing that now, how do you get the function code to display values? 
"Plot", of course, but plot...what?  TIA.



Luck,

Sebastian



---- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@xxx> wrote:
>
> I was just checking the Wright model (out of curiosity, I'm not too
> familiar with macroeconomics :) and noticed the argument in the "F"
> functions perhaps may become negative(?). Just in case then you'd
> need to adjust the HAS function because as such it is only valid for
> x>0.
>
> Also it is a good idea to cap off possible large values to prevent
> useless processing time.
>
> The one below should safely handle both pos/neg and large/small nrs.
> This probably solves your problem, if not let me know and give me an
> input value that causes trouble. Good luck.
>
> function t(x)
> { return 1 / (1+0.2316419*x); }
>
> function HASpre(x)
> { return 1 - (exp(-0.5*x^2)/sqrt(2*3.141592654))*(0.31938153*t(x)-
> 0.356563782*t(x)^2+1.781477937*t(x)^3-1.821255978*t(x)
> ^4+1.330274429*t(x)^5); }
>
> function HAS(x)
> { return IIf(x<-6, 0, IIf(x>6, 1, IIf( x>0, HASpre(x), 1 - HASpre(-
> x)))) ; }
>
> -treliff
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "sebastiandanconia"
> sebastiandanconia@ wrote:
> >
> >
> > Treliff, am I doing something wrong or does HAS have a weakness with
> > limits? NORMSDIST() only generates probabilities between 0% and
> 100%,
> > but HAS is generating numbers outside of that range and some of
> them are
> > clearly wrong. (Mathematically correct, I'm sure, but clearly
> wrong in
> > terms of what it's supposed to be indicating. )
> >
> >
> >
> > Luck,
> >
> > Sebastian
> >
> >
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@> wrote:
> > >
> > > You're welcome. Rest assured I didn't figure out the numbers
> myself :)
> > >
> > > Essence is that NORMSDIST is an integral that cannot be coded in
> AB.
> > > HAS is a polynomial that does a very good approximation.
> > >
> > > A while ago I submitted to TJ suggestion to include NORMSDIST and
> > > NORMSINV (its inverse) as native AB functions. These are essential
> > > functions for any statistical approach.
> > >
> > > I don't know how Tomasz would code 'm, but in any case it would
> speed
> > > up things, I assume. So far no luck.
> > >
> > > So Sebastian, or anyone using these functions, feel free to
> endorse
> > > this effort by submitting a similar request at the feedback
> center.
> > >
> > > http://www.amibroker.com/feedback/
> > >
> > > Thanks :)
> > >
> > > -treliff
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "sebastiandanconia"
> > > sebastiandanconia@ wrote:
> > > >
> > > >
> > > > A sincere thank-you for the response, I know it's a pretty
> arcane
> > > > subject. This is the nearly unintelligible math part I was
> talking
> > > > about when I said in a subsequent post that I didn't realize how
> > > much I
> > > > was asking for, LOL! I don't understand this enough to apply it
> to
> > > > what I want to do. I assume it's just a formula where I plug in
> the
> > > > values, but the "where", "how" and "why" plumb evade me.:) I'll
> > > work
> > > > on it, though.
> > > >
> > > >
> > > >
> > > > Luck
> > > >
> > > > Sebastian
> > > >
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@> wrote:
> > > > >
> > > > > Sebastian,
> > > > >
> > > > > The HAS function below (based on Hasting's polynomial
> > > approximation)
> > > > > gives 7-decimal accuracy of NORMSDIST.
> > > > >
> > > > > function t(x)
> > > > > { return 1 / (1+0.2316419*x); }
> > > > >
> > > > > function HAS(x)
> > > > > { return 1 - (exp(-0.5*x^2)/sqrt(2*3.141592654))*(0.31938153*t
> (x)-
> > > > > 0.356563782*t(x)^2+1.781477937*t(x)^3-1.821255978*t(x)
> > > > > ^4+1.330274429*t(x)^5); }
> > > > >
> > > > > -treliff
> > > > >
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "sebastiandanconia"
> > > > > sebastiandanconia@ wrote:
> > > > > >
> > > > > >
> > > > > > I came across what I consider to be a valuable stock
> > > market/economic
> > > > > > indicator, the Wright Model "B" yield-curve indicator. Using
> > > this
> > > > > > formula in Excel:
> > > > > >
> > > > > >
> > > > > > Probability = NORMSDIST(-2.17 - 0.76 x S + 0.35 x R)
> > > > > >
> > > > > > where "S" is the spread (10-Year Treasury yield minus 3-
> month T-
> > > Bill
> > > > > > yield) and "R" is the Fed Funds rate, it gives the
> probability
> > > of
> > > > > > economic recession within the next 4 quarters. (Only about
> 44%
> > > > > right
> > > > > > now, so there's some good news. I envision using this as a
> > > market-
> > > > > exit
> > > > > > indicator, warning when conditions are about to turn really
> > > ugly for
> > > > > > both the stock market and the economy. )
> > > > > >
> > > > > > This formula:
> > > > > >
> > > > > >
> > > > > > Z(x) = (1/(sqrt(2*pi()))*exp(-x^2/2))
> > > > > >
> > > > > > appears to be the actual math represented by the NORMSDIST
> > > > > function. I
> > > > > > believe AB supports all the operations in this formula.
> > > > > >
> > > > > > My problem is that I'm not math-savvy enough to make the
> leap
> > > from
> > > > > here
> > > > > > to turn this into a complete AB formula. I don't know what
> > > > > operation
> > > > > > the NORMSDIST formula performs on the Wright Model part, I
> don't
> > > > > know
> > > > > > what the "x" variable is supposed to be...there's no end to
> > > what I
> > > > > don't
> > > > > > know.:)
> > > > > >
> > > > > > Any help from my superiors in the math field (undoubtedly a
> VERY
> > > > > large
> > > > > > club) would be greatly appreciated.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Luck to all,
> > > > > >
> > > > > > Sebastian
> > > > > >
> > > > >
> > > >
> > >
> >
>




Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.34/679 - Release Date: 2/10/2007 4:08 PM