PureBytes Links
Trading Reference Links
|
And once again....
Suppose you want to rescale a series so that it goes through say 100
at a given date, say beginning of the year. We have looked at two ways
of doing that.
-----------------
The first is to calculate the percentage change in the series.
Percentage change is baseless, as is 100, and you can simply apply the
percentage changes to 100 to get the result. The trick is that,
especially with MSFL, you have to calculate the percentage change in
your series from the same day as the one where you want the
transformed series to equal 100. So you figure out code to give you
the price on that day, and call it say PriceX, and now you calculate
the percentage change in the original series from this point,
PctChange := ( C - PriceX ) / PriceX
Next, to apply this to the desired 100 value, you do the following
Final := PctChange * 100 + 100;
If you want to rather use 1000, then you'd swap the two 100s above for
that number.
So, in one step, we write
( C - PriceX ) / PriceX * 100 + 100
-----------------
The second approach is to simply rescale the price. You multiply it
with a (positive) factor and you have the original series, just in a
different position along the axis. The trick here is to scale it so
that it is equal to a certain value, say 100, on a given date. But we
know that on this date the original series is PriceX, so if we divide
by PriceX, we will have a value of 1 in this date! So we start with
Inbetween := C / PriceX
We know this inbetween result is 1 on the day we are interested in,
and if we want it to be 100 on that day, we just multiply it with 100.
If we want it to be 1000, we multiply with 1000 and so on.
Final := 100 * Inbetween
or, in one step
C / PriceX * 100
-----------------
Now it is time for coffee........
Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com
--- In equismetastock@xxxxxxxxxxxxxxx, mgf_za_1999 <no_reply@xxxx> wrote:
> Thanks Larry,
>
> I enjoy your dissertations. Overwritten code is fine, as is rewritten
> code. I am caught eternally it seems in that loop...
>
> What I am trying to point out is the different ideas to get to the
> same answer, and how one is simpler in the end, and related to the
> ratio as we discussed in another thread. The other idea, funny enough,
> is probably more related to the spread, as you calculate a spread,
>
> C - BeginYearPx
>
> to be specific, and then rescale this to get to the answer. Both give
> the same result though.
>
> Regards
> MG Ferreira
> TsaTsa EOD Programmer and trading model builder
> http://www.ferra4models.com
> http://fun.ferra4models.com
>
> --- In equismetastock@xxxxxxxxxxxxxxx, "Larry Carhartt" <lc@xxxx> wrote:
> >
> > My code is always a bit overwritten. If you have read some of my
> > dissertations here on the forum you know that is how I my brain
> works. The
> > formulas are clear to me, but perhaps not for public consumption.
> >
> >
> > -----Original Message-----
> > From: Larry Carhartt [mailto:lc@x...]
> > Sent: Wednesday, September 28, 2005 8:41 PM
> > To: 'equismetastock@xxxxxxxxxxxxxxx'
> > Subject: RE: [EquisMetaStock Group] Re: Constant price from a
> specific date
> > - FOLLOWUP
> >
> >
> > I originally tried as you suggest (not the same code as yours but
> similar
> > idea) and realized it does not work with negative numbers. The
> parentheses
> > make all the difference. The percent change is "added" to 100 to
> make all
> > the historical prices above zero. Simply multiplying by 100
allows the
> > result to remain negative. Negative values will not plot in a bar or
> > candlestick chart. For a line chart, what you suggest works fine
since
> > lines can display below zero.
> >
> > Thank you
> >
> > Best,
> >
> > Larry Carhartt
> >
> > MasterDATA
> > The Only Source for Index & ETF Composite/Breadth Reports, Charts
& Data
> > www.MasterDATA.com lc@xxxx 818-701-6686
> >
> >
> >
> > -----Original Message-----
> > From: equismetastock@xxxxxxxxxxxxxxx
> [mailto:equismetastock@xxxxxxxxxxxxxxx]
> > On Behalf Of mgf_za_1999
> > Sent: Wednesday, September 28, 2005 8:17 PM
> > To: equismetastock@xxxxxxxxxxxxxxx
> > Subject: [EquisMetaStock Group] Re: Constant price from a specific
> date -
> > FOLLOWUP
> >
> >
> > You could simplify the last line a bit, it now does something like
> >
> > x + calcs - x
> >
> > and you can simplify it to simply
> >
> > calcs
> >
> > Instead of
> >
> > 100+((C-BeginYearPx)/BeginYearPx*100)
> >
> > use
> >
> > 100 * C / BeginYearPx
> >
> > which is a lot easier to understand and change in future. The
original
> > version calculates the percentage change and applies that to 100
> while this
> > version simply rescales the close so that it is equal to 100 at the
> > beginning of the year. Same result, but different approaches. One
> looks like
> > rocket science, other is a simple rescaling calculation.
> >
> > Anyhow, if you ever want to change it, say to start at 1,000 in
stead of
> > 100, or 1 or whatever, this is easier to do as well. Also, note
how the
> > ratio is being used here, to catch up on some other discussions.
> >
> > Regards
> > MG Ferreira
> > TsaTsa EOD Programmer and trading model builder
> http://www.ferra4models.com
> > http://fun.ferra4models.com
> >
> >
> > --- In equismetastock@xxxxxxxxxxxxxxx, "Larry Carhartt" <lc@xxxx>
wrote:
> > > Thanks, Jose. I realize that. Because I publish these
datafiles for
> > > download, I didn't want users to have to download the full database
> > every
> > > night. By the setting the constant price to the last day of last
> > year, they
> > > only will be "required" to fully download once a year. Soon,
instead
> > > of doing a full download nightly, I am rewriting the plug-in so they
> > will only
> > > need to download the current day's data and it will put itself into
> > > the right place in their file (append or replace). If I set the
> > constant price
> > > exactly one year ago, "all" the price values for the equal weighted
> > prices
> > > would change daily thus affecting the entire data base every day. I
> > realize
> > > the current relative price shown will be measure from the start
> > price of the
> > > current year. In terms of the overall price history, however,
> > everything
> > > stays aligned properly between stocks, indexes and ETFs. They
are all
> > > reduced to a common denominator, 100.
> > >
> > > Best,
> > >
> > > Larry Carhartt
> > >
> > > MasterDATA
> > > The Only Source for Index & ETF Composite/Breadth Reports, Charts &
> > > Data www.MasterDATA.com lc@xxxx
> > > 818-701-6686
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: equismetastock@xxxxxxxxxxxxxxx
> > [mailto:equismetastock@xxxxxxxxxxxxxxx]
> > > On Behalf Of Jose Silva
> > > Sent: Wednesday, September 28, 2005 4:55 PM
> > > To: equismetastock@xxxxxxxxxxxxxxx
> > > Subject: [EquisMetaStock Group] Re: Constant price from a specific
> > date -
> > > FOLLOWUP
> > >
> > >
> > > Larry, you've set the month variable in your code to last
> December, so
> > > that currently it is only measuring the last ten months.
> > >
> > > To save a lot of time (and possible errors) with the date setting,
> you
> > > could try Richard's excellent NexusDate.dll to automate this
process
> > > for you in MetaStock:
> > >
> > > ---8<------------------------
> > > { Download NexusDate.dll from:
> > > http://www.tradernexus.com/nexusdate }
> > >
> > > x:=ExtFml("NexusDate.DaysOld")>=366;
> > > StartDate:=x=0 AND Alert(x,2);
> > > BeginYearPx:=LastValue(ValueWhen(1,StartDate,C));
> > >
> > > 100+((C-BeginYearPx)/BeginYearPx*100)
> > > ---8<------------------------
> > >
> > >
> > > jose '-)
> > > http://www.metastocktools.com
> > >
> > >
> > >
> > > --- In equismetastock@xxxxxxxxxxxxxxx, "Larry Carhartt" <lc@xxxx>
> > > wrote:
> > > >
> > > > Although many of you supplied answers for my earlier inquiry
> > regarding
> > > > finding the price of 1 year ago and setting it as a constant
(and I
> > > > appreciate the response very much), I elected to use Roy Larsen's.
> > > > For reasons that I will spare you, I now have decided to use
> instead
> > > > the last closing price of last year as the constant. In other
> > words, I
> > > > will be calculating the rate of return for the current calendar
> year
> > > > both forward (this is normal practice) and backward (not very
> > > > common) based upon the closing price of the last trade day of
last
> > > > year. I modified Roy's formula as follows:
> > > >
> > > > Sm:=12;
> > > > Sd:=28;
> > > > Sy:=LastValue(Year()-1);
> > > >
> > > > StartDate:=(DayOfMonth()>=Sd AND
> > > > Month()=Sm AND
> > > > Year()=Sy);
> > > >
> > > > BeginYearPx:=LastValue(ValueWhen(1,StartDate,C));
> > > >
> > > > 100+(((C-BeginYearPx)/BeginYearPx)*100);
> > > >
> > > > I know it is more than a little modified, but Roy's original
> formula
> > > > introduced me to some MetaStock functions I had never used
before.
> > > > THAT is the true value of this forum. Yes, you may get the exact
> > > > answer you need, but you can learn from every answer (from
guys like
> > > > Roy, Jose, Richard and many more I should be mentioning). By the
> > > > way, I still plan on using Roy's original formula for other
purposes
> > > > (with full credit, of course). And, Jose, thank you for
getting my
> > > > brain kick-started by pointing out the problem with simply
> > > > accumulating percentage gains/losses.
> > > >
> > > > When I use the above as the formula for the custom indicator, it
> > > > generates the correct values. You may notice that I also modified
> > the
> > > > last line (my addition) so that the year always starts with a
> > value of
> > > > 100. The reason for this is that I plan on additionally
generating
> > > > OHLC MetaStock format price files outside of MetaStock and then
> > > > converting those files to MetaStock (that code will be based
on the
> > > > same formula). That way, I can display bar or candlestick charts
> > with
> > > > the new "relative" OHLC prices. OHLC price files won't plot
> > > > negative
> > > > values, so starting at 100 always keeps the value above 0 even
when
> > > > going back previous to the beginning of the year or if the
current
> > > > price is down for the year. In other words, if the security is
> > down 3%
> > > > from the current year's beginning price, the displayed value for
> > > > that
> > > > day will be 97. It really seems to do a good job of keeping the
> > > > displayed value properly aligned with the actual price and
current
> > > > rate of return without drift of any kind.
> > > >
> > > > I think I mentioned this before, but in case you are tuning in
> late,
> > > > where I am really going with this is to recalculate all the
indexes
> > > > and ETFs I work with to equal weight composites. Most indexes
are
> > > > either cap weighted like the S&P 500 Index or price weighted like
> > > > the Dow Jones Industrial Average. To do that, I need to apply this
> > formula
> > > > to each of 3400 components I follow then recalculate the
historical
> > > > data on the composites using the values given by the above formula
> > and
> > > > then simply total them and divide by the number of components in
> the
> > > > index or ETF. Voila, an equal weighted composite (I think or
hope).
> > > >
> > > > Again, I appreciate everyone's input on this.
> > > >
> > > > Thank you.
> > > >
> > > > Best,
> > > >
> > > > Larry Carhartt
> > > >
> > > > MasterDATA Composite Plug-in For MetaStock
> > > > The Only Source for Index & ETF Composite/Breadth Historical
> > MetaStock
> > > > Data <http://www.masterdata4metastock.com/>
> > > > www.MasterDATA4MetaStock.com <mailto:lc@x...> lc@xxxx
818-701-6686
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Try Online Currency Trading with GFT. Free 50K Demo. Trade
24 Hours. Commission-Free.
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/BefplB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/equismetastock/
<*> To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|