PureBytes Links
Trading Reference Links
|
Q.
Thanks for the response. Yes, I did use (paste) the formula. I'm just
trying to understand the logic behind it. Let me clarify a bit more
on what I was trying to say.
Let me first talk about the second point that I raised. So you do NOT
want a fluctuating min f value? I thought you would, because
otherwise the 95% capture would happen only for last 100 bars, which
is Ok in real time, but not in say, a backtest. For example, when I
plot the formula, I see perc is 95% or greater for last 100 bars, but
not necessarily for bars before that. Was that the intent? If yes,
then its OK.
R.
The code works ONLY as a last bar diagnostic. The info is useful for
tomorrow speculation.
Tomorrow, with the new EOD, f will be different, it will reflect the
new last 100 [or n] bars.
I have not solved yet the f[i] problem. [This would permit
backtesting].
If you select other bars except the last, you will find x readings
different than 95.
So, my question was, what f would give me 95% for the last n bars, in
order to use it for tomorrow. The reasons to write this code were
a. f=2 is not always sufficient for the 95%
b. f resulting 95% is not the same for lookback=100 and lookback=500
According to the timeframe we have in mind, we should adjust properly
our BBands.
It doesnt make sense, for example, to work with 250-bar MA and ask
95% for the last 100 bars, you should ask something similar to 250
Q.
Re. first point, what I was trying to say is that why figure out a
coeff for BBands calcualted over "n" periods that captures 95% of the
values over "Lookback" periods which is greater than n? Even if you
put aside the argument that 2X doesn't always give you 95% (see
below), why not just calculate BBands for Lookback periods and figure
out a coeff for those which capture 95% of the prices for Lookback?
Is there any reason for choosing a "different" n periods to calculate
the coeff for?
R.
In order to include more data, I think lookback should be 5times the
smoothing BB period.
In the posted formula, n=20, lookback=100 fulfills this requirement.
Of course you may change it to suit your needs
Thirdly, and now this is VERY surprising. When I plot a simple 2X of
a BBand like below -
-------------------------------
SetBarsRequired(10000, 10000);
n=20;
newbB=BBandBot(C,n,2);
newbT=BBandTop(C,n,2);
newperc=100*Sum(C>=newbB AND C<=newbT,n)/n;
Plot(C,"C",1,64);
Plot(newbB,"BB",colorLightYellow,8);
Plot(newbT,"BT",colorLightYellow,8);
Plot(newperc,"Perc",colorLightBlue,8);
--------------------------------
- you are right that newperc sometimes dips below 95? How come? Isn't
2 times standard deviation supposed to capture 95% of the values in a
given dataset, which is values over last n periods? Does anyone know
why it would dip below 95%?
R.
In my calculations over the whole N100 database, the result for
newperc was 95%, as it should be. Some stocks gave 94%, but it was a
matter of f step. Since in the code I stop the loop below 95%, an
f=2.32 gives 94% and the next f=2.33 gives 96%. If we allow 3rd digit
accuracy, we will have x10 cycles but we shall approximate 95% better.
I think 2nd digit is cute for this job.
Another [interesting] application.
Suppose todays f=2.31 and tomorrows f=2.29.
The new BBands will be tighter and, perhaps, 3 bars ago a Sell[or a
Buy] signal appears, non existing 3 bars ago !! It means we should
Sell 3 bars ago, according to more recent data. Which means it is
dangerous to stay in, it would be better to shrink our position
Dimitris Tsokakis
Jitu
--- In amibroker@xxxxxxxxxxxxxxx, "jtelang" <jtelang@xxxx> wrote:
> Thanks for the response. Yes, I did use (paste) the formula. I'm
just
> trying to understand the logic behind it. Let me clarify a bit more
> on what I was trying to say.
>
> Let me first talk about the second point that I raised. So you do
NOT
> want a fluctuating min f value? I thought you would, because
> otherwise the 95% capture would happen only for last 100 bars,
which
> is Ok in real time, but not in say, a backtest. For example, when I
> plot the formula, I see perc is 95% or greater for last 100 bars,
but
> not necessarily for bars before that. Was that the intent? If yes,
> then its OK.
>
> Re. first point, what I was trying to say is that why figure out a
> coeff for BBands calcualted over "n" periods that captures 95% of
the
> values over "Lookback" periods which is greater than n? Even if you
> put aside the argument that 2X doesn't always give you 95% (see
> below), why not just calculate BBands for Lookback periods and
figure
> out a coeff for those which capture 95% of the prices for Lookback?
> Is there any reason for choosing a "different" n periods to
calculate
> the coeff for?
>
> Thirdly, and now this is VERY surprising. When I plot a simple 2X
of
> a BBand like below -
>
> -------------------------------
> SetBarsRequired(10000, 10000);
>
> n=20;
> newbB=BBandBot(C,n,2);
> newbT=BBandTop(C,n,2);
> newperc=100*Sum(C>=newbB AND C<=newbT,n)/n;
>
> Plot(C,"C",1,64);
> Plot(newbB,"BB",colorLightYellow,8);
> Plot(newbT,"BT",colorLightYellow,8);
> Plot(newperc,"Perc",colorLightBlue,8);
> --------------------------------
>
> - you are right that newperc sometimes dips below 95? How come?
Isn't
> 2 times standard deviation supposed to capture 95% of the values in
a
> given dataset, which is values over last n periods? Does anyone
know
> why it would dip below 95%?
>
> Jitu
>
> --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS"
<TSOKAKIS@xxxx>
> wrote:
> > Find some comments below:
> > --- In amibroker@xxxxxxxxxxxxxxx, "jtelang" <jtelang@xxxx> wrote:
> > > Hi Dimitris,
> > >
> > > A bit confused about couple of things here... Hope you can
> clarify.
> > >
> > > 1. BBands are calculated as standard deviation, so by
definition,
> 2
> > > times BBands is supposed to capture 95% of the values over
> periods
> > > specified.
> >
> > No, it is not true.
> > The percentage x is given by
> >
> > Lookback=100;n=20;
> > bB=BBandBot(C,n,2);
> > bT=BBandTop(C,n,2);
> > x=100*Sum(C>=bB AND C<=bT,Lookback)/Lookback;
> >
> > Explore your database and you will see that x is not equal to 95.
> > This is exactly what my code searches: to find the proper f that
> will
> > make this percentage equal to 95%.
> >
> > >In your formula below, if you make Lookback equal to n,
> > > then theorotically the f min value should always be equal to 2,
> no
> > > less, no more. Is that assumption correct? If yes, then
couldn't
> > you
> > > simply calculate BBands over Lookback periods with 2 as
> multiplier,
> > > giving you the same values as calculated below?
> > >
> > > 2. In the for loop below, when you use "x[BarCount-1]" to
> compare,
> > > what are you assuming BarCount value to be? "BarCount-1" will
> > always
> > > give you the last value in the array, no?
> >
> > I agree.
> >
> > >Furthermore, as TJ
> > > explained to me earlier in another thread, the BarCount value
> > > fluctuates when QuickAFL mode is on.
> >
> > I didnīt follow this reply you refer but I donīt see anything
> > flactuating in my results. Did you notice something similar ?
> >
> > >So if you add "SetBarsRequired
> > > (10000, 10000)" at the top of your formula to correct it,
you'll
> > > notice that your min f value is a constant.
> >
> > I do not use SetBarsRequired in this code.
> >
> > To avoid confusion [?] with barcount, replace this line with
> >
> > if(x[LastValue(Cum(1))-1]<=perc)
> >
> > It will give the same result.
> > > TIA,
> > >
> > > Jitu
> > In general, paste the code and see how it works [because it
works]
> > and then arrange it according to your standards.
> > Dimitris Tsokakis
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Dimitris Tsokakis"
> > <TSOKAKIS@xxxx>
> > > wrote:
> > > >
> > > > Paste in Inicator builder the
> > > >
> > > > // Adjustable Bollinger bands
> > > > n=20;
> > > > Lookback=100;
> > > > perc=95;
> > > > for(f=1.5;f<3;f=f+0.01)
> > > > {
> > > > bB=BBandBot(C,n,f);bT=BBandTop(C,n,f);
> > > > x=100*Sum(C>=bB AND C<=bT,Lookback)/Lookback;
> > > > if(x[BarCount-1]<=perc)
> > > > {
> > > > g=f;
> > > > }
> > > > }
> > > > newbB=BBandBot(C,n,g);
> > > > newbT=BBandTop(C,n,g);
> > > > newperc=100*Sum(C>=newbB AND C<=newbT,Lookback)/Lookback;
> > > > Plot(C,"",1,64);Plot(newbB,"",colorLightYellow,8);Plot
> > > (newbT,"",colorLightYellow,8);
> > > > Plot(BBandBot(C,n,2),"",colorRed,1);Plot(BBandTop
> > > (C,n,2),"",colorRed,1);
> > > > Title="f min="+WriteVal(g,1.2)+",perc="+WriteVal(newperc,1.0)
> +"%";
> > > >
> > > > The formula will find the f min necessary for the 95%
> confidence,
> > > > will plot the new BBands and, for comparison, will plot the
> usual
> > > f=2 BBlines.
> > > > It is interesting to see fminCSCO=2.09 but fminBEAS=2.70.
> > > > You may adjust n, Lookback and perc.
> > > > Dimitris Tsokakis
------------------------ Yahoo! Groups Sponsor ---------------------~-->
ReplayTV: CNet Ranked #1 over Tivo!
Instant Replay & Pause live TV.
Special Sale: 50% off!
http://us.click.yahoo.com/UUMW7B/.5qGAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|