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

RE: [amibroker] Re: Calculating % change since 1/3/2006



PureBytes Links

Trading Reference Links

Okay,

This is the code that works for me:

LYC = ValueWhen( Year()!=Ref(Year(),1), C );
// LYC (Last Year's Closing Price)
AddColumn(LYC,"L YR C" , 3.2, colorDarkRed, colorLightGrey  );
YTDP = (  (C - LYC)/ LYC )*100;
// YTDP (Year to date Percentage change)
AddColumn(YTDP,"YTD %", 3.2, colorDarkRed, colorLightGrey  );

BarSince also worked but I removed it to streamline the code.

My filter is setup to look at a small watchlist (so it runs fast) and the
Range is set to the last 1 days.  Then just run it.

To verify it is working put your vertical data bar (tooltip) on 12/30/2005
and the LYC column should match that which is in the title bar.



-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of dmcleod1981
Sent: Sunday, March 26, 2006 8:42 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Calculating % change since 1/3/2006

I closed the program and reopened, I even made a new DB and still get
the same thing as in different closing values. It would seem to make
sense that it should as it would need to be a new year for the
Year()!= Ref(Year(), has to be after Jan 1, to be a different, thus
the reason it uses the first price in January which in this case was
Jan 03, 2006. I may be completely off the mark in my interpretation
but this is what it seems to be. I don't think the formula is wrong
but I don't think the barssince version gives you what you where
originally looking for. Again, I may be completely off the mark.

DM

--- In amibroker@xxxxxxxxxxxxxxx, "MarketMonk777" <dlittner@xxx> wrote:
>
> You know I had the same problem and then it went away.  Close down
AB and
> reopen everything and see if that works.
> 
> MM
> 
> -----Original Message-----
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
On Behalf
> Of dmcleod1981
> Sent: Sunday, March 26, 2006 7:14 AM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: Calculating % change since 1/3/2006
> 
> MM,
> 
> I added the following to your code based on the original examples and
> ran an exploration and come up with different closing values. Perhaps
> I have made a mistake and am not applying this correctly.
> 
> //original examples
> 
> Sample1 = ValueWhen( Year()!=Ref(Year(),1), C );
> 
> Sample2 = Ref( C, -BarsSince(Year()!=Ref(Year(),1))+1);
> 
> AddColumn(Sample1,"Closing Price ",1.2,colorRed);
> AddColumn(Sample2,"Closing Price ",1.2,colorRed);
> Filter=1;
> 
> When I run this I get the following data:
> Ticker	Date/Time	1 P %	5 P %	21 P %	63 P %	255 P %	BS
12-30-06
> LC
> YTD %	L YR C	% from LY	Closing Price 	Closing Price 	
> DELL	3/24/2006	-0.92	3.37	3.39	-2.81	-21.76	57.00
> 29.95	0.37
> 29.95	0.37	29.95	30.61	
> IBM	3/24/2006	0.19	0.07	3.94	0.29	-6.87	57.00
> 82.20	1.41	82.20
> 1.41	82.20	82.06	
> INTC	3/24/2006	-0.51	0.31	-3.40	-24.27	-16.60	57.00
> 24.96	-21.47
> 24.96	-21.47	24.96	25.57	
> MSFT	3/24/2006	0.60	-1.78	1.31	1.05	11.61	57.00
> 26.15	3.29	26.15
> 3.29	26.15	26.84	
> 
> The closes respectively are 12/30/05 and 01/03/06, i.e DELL is 29.95
> 30.61 which is what Yahoo and other sources show. I was trying to
> figure out why the difference.
> 
> Thanks,
> 
> DM
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "marketmonk777" <dlittner@> wrote:
> >
> > And of course since it's late I entered in a typo.  Change (or not)
> > the 12-30-06 to 12-30-05 in the column heading.  
> > 
> > You will notice that both of Graham's examples of ValueWhen and
> > BarsSince work the same.
> > 
> > Thanks once again Graham.
> > 
> > MM
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "marketmonk777" <dlittner@> wrote:
> > >
> > > Hi DM,
> > > 
> > > The code I posted works just fine.  Sorry if I caused the
confusion by
> > > typing in 1-3-06 as a date in my column title. There are indeed 57
> > > bars since 12-30-05.
> > > 
> > > It retrieves the closing price on 12/30/05.  And from that I can
> > > calculate the YTD % performance.
> > > 
> > > Here is the price % calculations and some extra code to verify
> > > (visually) that it works.
> > > 
> > > 
> > > //  Price  Deltas
> > > 
> > > AddColumn( ( (C-Ref(C,-1))/Ref(C,-1))*100,"1 P %", 3.2,
> > > colorYellow,colorGreen);
> > > 
> > > AddColumn( ( (C-Ref(C,-5))/Ref(C,-5))*100,"5 P %", 3.2,
> > > colorYellow,colorGreen);
> > > 
> > > AddColumn( ( (C-Ref(C,-21))/Ref(C,-21))*100,"21 P %", 3.2,
> > > colorYellow,colorGreen);
> > > 
> > > AddColumn( ( (C-Ref(C,-63))/Ref(C,-63))*100,"63 P %", 3.2,
> > > colorYellow,colorGreen);
> > > 
> > > AddColumn( ( (C-Ref(C,-255))/Ref(C,-255))*100,"255 P %", 3.2,
> > > colorYellow,colorGreen);
> > > 
> > > BS = BarsSince(Year()!=Ref(Year(),1));
> > > 
> > > AddColumn(BS,"BS 12-30-06" , 3.2, colorDarkRed, colorLightGrey  );
> > > 
> > > LC = Ref( C,-BS);
> > > 
> > > AddColumn(LC,"LC" , 3.2, colorDarkRed, colorLightGrey  );
> > > 
> > > YTDP = (  (C - Ref( C,-BS)) / Ref( C, -BS)  )*100;
> > > 
> > > AddColumn(YTDP,"YTD %" , 3.2, colorDarkRed, colorLightGrey  );
> > > 
> > > LYC = ValueWhen( Year()!=Ref(Year(),1), C );
> > > 
> > > AddColumn(LYC,"L YR C" , 3.2, colorDarkRed, colorLightGrey  );
> > > 
> > > PCLY = (  (C - LYC)/ LYC )*100;
> > > 
> > > AddColumn(PCLY,"% from LY", 3.2, colorDarkRed, colorLightGrey  );
> > > 
> > > MM
> > > --- In amibroker@xxxxxxxxxxxxxxx, "dmcleod1981" <dmcleod1981@>
wrote:
> > > >
> > > > Sorry meant to type 01/01/06 for second lines closing price
not '04.
> > > > 
> > > > DM
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "dmcleod1981" <dmcleod1981@>
> wrote:
> > > > >
> > > > > The two formulas appear to give different dates. The first
> does give
> > > > > the closing price for 12/30/04 but the second gives the closing
> > price
> > > > > for 01/03/04 which would be incorrect for year to date figures.
> > > > > 
> > > > > I am also confused as to the +1 and couldn't see how to
> correct the
> > > > > line to give the closing '05 price.
> > > > > 
> > > > > DM
> > > > > 
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "MarketMonk777" <dlittner@>
> wrote:
> > > > > >
> > > > > > Hi Graham,
> > > > > > 
> > > > > > Thanks, the barssince works.  I have added the following
> lines of
> > > > code:
> > > > > > 
> > > > > > BS = BarsSince(Year()!=Ref(Year(),1));
> > > > > > AddColumn(BS,"BS 1-1-06" , 3.2, colorDarkRed,
colorLightGrey  );
> > > > > > YTD = C - Ref( C, -BarsSince(Year()!=Ref(Year(),1))+1);
> > > > > > AddColumn(YTD,"YTD Net" , 3.2, colorDarkRed,
colorLightGrey  );
> > > > > > 
> > > > > > Just to confirm that all works.
> > > > > > 
> > > > > > I am confused as to the purpose of the +1 that is added at
> the end
> > > > > of the
> > > > > > code in the YTD line.
> > > > > > 
> > > > > > I was able to research and figure out that != means not equal
> > > to.  And
> > > > > > researched how barssince works.  And that ref(year(),1) is
> the way
> > > > > to catch
> > > > > > the year changing from 2005 to 2006.
> > > > > > 
> > > > > > But that +1 has me confused.  What is it's purpose?
> > > > > > 
> > > > > > Dave
> > > > > > 
> > > > > > -----Original Message-----
> > > > > > From: amibroker@xxxxxxxxxxxxxxx
> [mailto:amibroker@xxxxxxxxxxxxxxx]
> > > > > On Behalf
> > > > > > Of Graham
> > > > > > Sent: Saturday, March 25, 2006 3:47 PM
> > > > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > > > Subject: Re: [amibroker] Calculating % change since 1/3/2006
> > > > > > 
> > > > > > you can use valuewhen function to reference a fixed point
or ref
> > > with
> > > > > > barssince
> > > > > > for the close price of end of previous year
> > > > > > 
> > > > > > valuewhen( year()!=ref(year(),1), C )
> > > > > > 
> > > > > > or
> > > > > > 
> > > > > > ref( c, -barssince(year()!=ref(year(),1))+1)
> > > > > > 
> > > > > > 
> > > > > > --
> > > > > > Cheers
> > > > > > Graham
> > > > > > AB-Write >< Professional AFL Writing Service
> > > > > > Yes, I write AFL code to your requirements
> > > > > > http://e-wire.net.au/~eb_kavan/ab_write.htm
> > > > > > 
> > > > > > 
> > > > > > On 3/26/06, marketmonk777 <dlittner@> wrote:
> > > > > > > Hi folks,
> > > > > > >
> > > > > > > I would like to add a value to my title line and in some
of my
> > > > > > > explorations.  The value that I am trying to determine is
> the %
> > > > change
> > > > > > > since the last trading day of 2005 (or should I use
1/3/06?).
> > > > > > >
> > > > > > > How do I specify a fixed date in my calculations?
> > > > > > >
> > > > > > > Thanks,
> > > > > > >
> > > > > > > Dave
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > 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 other support material please check also:
> > > > > > > http://www.amibroker.com/support.html
> > > > > > >
> > > > > > >
> > > > > > > Yahoo! Groups Links
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > 
> > > > > > 
> > > > > > 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 other support material please check also:
> > > > > > http://www.amibroker.com/support.html
> > > > > > 
> > > > > >  
> > > > > > Yahoo! Groups Links
> > > > > >
> > > > >
> > > >
> > >
> >
> 
> 
> 
> 
> 
> 
> 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 other support material please check also:
> http://www.amibroker.com/support.html
> 
>  
> Yahoo! Groups Links
>







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 other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links



 





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 other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/