PureBytes Links
Trading Reference Links
|
O.K.
I understand your situation - AmiBroker does jam the neural pathways
when we first start to learn it.
I already started on an example for you.
It is at the UKB under BuyAndHold.
I noted your points and it should clear them all up, except for the
Wizard - if you enter the code into the Wizard as I have written it
you should come up with a passmark.
It has a Buy&Hold plot at the moment as well as a chart with your
trading system arrows to mark the buy and sell.
The next step is to add the equity curve for your system and plot it
in the one pane (alongside the B&H) for comparison.
The idea is to show you, using plots, what the backtester does
(except we are only using one stock and the backtester can do
multiples).
You can use the formulas on any stock and any number of bars (I
didn't use Yahoo - I just used the stock that was current in my
database when I opened it - i.e. it was picked at random).
I'll finish it within the next 24 -48 hours.
It doesn't look like it will produce an interesting trading system
but it does explain a lot about backtesting.
brian_z
http://www.amibroker.org/userkb/
--- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
<electricwally77@xxx> wrote:
>
>
>
> Actually the Buy & Hold formula could also be called Buy and Sell
only
> one time. In other words, I'll settle for buying the stock on the
> first bar (back in 1962) and selling the stock on the last bar (in
2007).
>
> That to me is pretty much a Buy and Hold strategy as well.
>
> The stock is Hewlitt Packard (HPQ) and the data consists of 11,561
> Daily bars starting on January 2, 1962 and ending on the last bar on
> December 4, 2007.
>
> Its not critical where I get in on the first bar or where I get out
on
> the last bar.
>
> Thank you
> Walter
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
> <electricwally77@> wrote:
> >
> >
> >
> > Brian
> >
> > I also forgot to mention that I would (if at all possible please)
> > prefer to try and come up with the Buy & Hold code using the AFL
> > Wizard. Its easy to use. I understand that pure coding in AFL is
the
> > way to go but I'm not there yet. Eventually I'll learn it.
> >
> > I'm spending much time on this trying to play catch up with
everyone
> > else. Hopefully someday soon I'll post something other than
> > rudimentary questions. In the meantime, that's where I'm at right
now.
> >
> > I'm sure you've seen the AFL WIZARD (see Analysis - AFL Code
Wizard).
> > Its amazing and if it wasn't an option in the program I would be
lost.
> >
> > I'm really curious if what I'm trying to accomplish can be
created in
> > the AFL Wizard. Honestly, I've been at it for hours yesterday and
> > could not come up with a formula that AB was happy with. I'm
convinced
> > I've got something wrong in the settings and the AFL code. More
> > hunting today. Learniing is fun!
> >
> > Thank you
> > Walter
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
> > <electricwally77@> wrote:
> > >
> > > Hi Brian
> > >
> > > > Do you want the B&H as well as a comparison?
> > >
> > > Yes. Actually its the other way around. I would like to do the
system
> > > test I mentioned in post 117721 and use the B&H as a
comparison. I
> > > thought about my previous reply to you and forgot to mention
that the
> > > Buy & Hold was needed as well to do a comparison against the
system
> > test.
> > >
> > > I apologize for the confusion.
> > >
> > > Thanks Brian
> > > Walter
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@>
wrote:
> > > >
> > > > > I'm back testing someone's basic SMA system. I jsut want to
see
> > > > > returns of his system over a longer period of time.
> > > >
> > > > O.K
> > > >
> > > > But that's not buy & hold - that is a system test.
> > > > Do you want the B&H as well as a comparison?
> > > >
> > > > brian_z
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
> > > > <electricwally77@> wrote:
> > > > >
> > > > >
> > > > >
> > > > > Hi Brian
> > > > >
> > > > > >>Q1. Where do you want to use the answer?
> > > > >
> > > > > I'm back testing someone's basic SMA system. I jsut want to
see
> > > > > returns of his system over a longer period of time.
> > > > >
> > > > > >> Q2. How much money have you got to spend i.e. what is
your
> > > > initial
> > > > > equity?
> > > > >
> > > > > Start with $100,000.
> > > > >
> > > > > >> Q3. The first bar has a lot of points on it - everything
> equal to
> > > > > and between the high and the low. Which data point do you
mean -
> > > > Open,
> > > > > Close, High, Low or something else?
> > > > >
> > > > > I understand the data points but not sure of your question.
I
> simply
> > > > > would like to buy at the open on the first bar or even on
the
> close
> > > > or
> > > > > anywhere on the first bar. Its really not that important(I
> think).
> > > > > Not sure about the exit. This is where it gets fuzzy. I
assume the
> > > > > exit would be to sell on the most recent bar (last bar in
the
> data)
> > > > to
> > > > > close out the position.
> > > > >
> > > > > Thus I guess its not called buy and hold because if we sell
it we
> > > > > close the position. However we did actually Buy and Hold it
from
> > > > 1962
> > > > > to 2007. Whatever....I'm confused.
> > > > >
> > > > > I'm just trying to test a system I was presented with that
has 3
> > > > SMA's
> > > > > for example, let's just call them the following (40 day
SMA,
> 80 day
> > > > > SMA and 200 day SMA). The system only buys (enters long)on
the
> next
> > > > > morning when the stock closes the previous day above all
three
> SMA's
> > > > > and sells the next morning (exits long) when the stock
closes the
> > > > > previous day below all three SMA's. If we are long the stock
> and it
> > > > is
> > > > > trading within the three moving averages then it is simply
a HOLD
> > > > (no
> > > > > action).
> > > > >
> > > > > I'm testing it on all the data available on HPQ (Hewlitt
Packard)
> > > > > downloaded from yahoo.
> > > > >
> > > > > >>> If you can answer them I'll see if I can give you a
quick
> answer
> > > > > to get you going while you take your time to take in the
full AA
> > > > picture.
> > > > >
> > > > > Okay Brian. Sounds good.
> > > > >
> > > > > Thanks for all your time.
> > > > > Walter
> > > > >
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@>
> wrote:
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
> > > > > > <electricwally77@> wrote:
> > > > > > >
> > > > > > > Hi Brian
> > > > > > >
> > > > > > > I appreciate all the help. I guess -at this point- my
specific
> > > > > > > question would be how and what are the correct settings
in
> the
> > > > AA
> > > > > > > "settings" window under the tabs called;
> > > > > > > General,Trades,Stops,Report,Portfolio
> > > > > > >
> > > > > > > The help file tells me to set the min. shares to 1 yet
I
> > > > believe you
> > > > > > > said to set it to 0.0001. I'm confused. Sorry 'bout
that.
> > > > > > >
> > > > > > > I really need to sit down and dig into the help files
and
> > > > figure how
> > > > > > > and why to set the parameters in the "settings" window.
> > > > > > >
> > > > > > > All I'm trying to accomplish (please bear with me) is to
> create
> > > > a
> > > > > > simple
> > > > > > > "buy on first bar" and "sell on last bar".
> > > > > >
> > > > > > Q1. Where do you want to use the answer?
> > > > > >
> > > > > > Do you just want to plot it or what (to start with)?
> > > > > >
> > > > > >
> > > > > > Q2. How much money have you got to spend i.e. what is
your
> > > > initial
> > > > > > equity?
> > > > > >
> > > > > > Q3. The first bar has a lot of points on it - everything
> equal to
> > > > and
> > > > > > between the high and the low. Which data point do you
mean -
> > > > Open,
> > > > > > Close, High, Low or something else?
> > > > > >
> > > > > > AA needs to know the answer to questions like this before
it
> can
> > > > > > proceed.
> > > > > >
> > > > > > If you can answer them I'll see if I can give you a quick
> answer
> > > > to
> > > > > > get you going while you take your time to take in the
full AA
> > > > picture.
> > > > > >
> > > > > >
> > > > > > brian_z
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I did not know it would be
> > > > > > > this intricate to accomplish. Intricate as defined by a
> newbie
> > > > such
> > > > > > as
> > > > > > > myself.
> > > > > > >
> > > > > > > I'm using only one stock (HPQ) using daily data from
1962 to
> > > > > > present.
> > > > > > > The total daily bars are 11,561.
> > > > > > >
> > > > > > > Let me keep digging. I'll nail it down eventually. I
know
> back
> > > > > > testing
> > > > > > > involves a rather high learning curve but the payoff is
well
> > > > worth
> > > > > > it
> > > > > > > once I understand and begin to maneuver around and
> actually see
> > > > > > > systems work.
> > > > > > >
> > > > > > > Thanks Brian
> > > > > > > Walter
> > > > > > >
> > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111"
<brian_z111@>
> > > > wrote:
> > > > > > > >
> > > > > > > > If you get stuck come back with a specific question.
> > > > > > > >
> > > > > > > > You should be able to replicate the outcomes of the
code
> > > > below
> > > > > > > > (understanding it's principles is the basis of B&H).
> > > > > > > > If you can't let me know.
> > > > > > > >
> > > > > > > > The only real difference between it and my PDF is
that you
> > > > only
> > > > > > want
> > > > > > > > to B&H one stock whereas in the PDF I used three
(from
> > > > memory).
> > > > > > > >
> > > > > > > >
> > > > > > > > I'm not necessarily around every day but I will check
> back on
> > > > > > this
> > > > > > > > topic at some stage.
> > > > > > > >
> > > > > > > > > Filter = 1;
> > > > > > > >
> > > > > > > > >//In AA settings Initial Equity = 1
> > > > > > > > > //Min shares = 0.0001
> > > > > > > > > //Run on all quotations
> > > > > > > > >
> > > > > > > > > PositionSize = -100;
> > > > > > > > >
> > > > > > > > > Buy =1;
> > > > > > > > > Sell = 0;
> > > > > > > > >
> > > > > > > > > e = Equity();
> > > > > > > > >
> > > > > > > > > AddColumn(e,"equity",1.6,1);
> > > > > > > > >
> > > > > > > > > Plot(e * 28.01,"Equity",1,1);//manually enter the
> starting
> > > > > > close for
> > > > > > > > > your symbol
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
> > > > > > > > <electricwally77@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Brian
> > > > > > > > >
> > > > > > > > > I appreciate all your help. I'm slowly reading and
> trying to
> > > > > > > > > understand all that you have presented. Please give
me
> some
> > > > > > time to
> > > > > > > > > figure all this out. I went into my settings in the
AA
> > > > window
> > > > > > and I
> > > > > > > > am
> > > > > > > > > making some changes.
> > > > > > > > >
> > > > > > > > > First thing I noticed was that "min. shares" was
set
> > > > to .01
> > > > > > > > > I changed it to 1.
> > > > > > > > >
> > > > > > > > > I'm reading through some help files as well (in
> regards to
> > > > the
> > > > > > AA
> > > > > > > > > window "settings" button.)
> > > > > > > > >
> > > > > > > > > I just wanted to send you this quick note to let
you know
> > > > I'm
> > > > > > > > working
> > > > > > > > > on it.
> > > > > > > > >
> > > > > > > > > Thank you again
> > > > > > > > > Walter
> > > > > > > > >
> > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111"
> > > > <brian_z111@>
> > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > Walter,
> > > > > > > > > >
> > > > > > > > > > Backtesting in the AA window is a simulation of
real
> > > > trading
> > > > > > > > > > conditions - the trade requires an intitial equity
> and a
> > > > > > setting
> > > > > > > > for
> > > > > > > > > > the minimum size allowed (one share or part of a
share)
> > > > plus
> > > > > > > > other
> > > > > > > > > > settings.
> > > > > > > > > >
> > > > > > > > > > In my example PDF file I show where and when I
accepted
> > > > the
> > > > > > > > defaults
> > > > > > > > > > or changed them (the file is not exact or the be
all
> and
> > > > end
> > > > > > all -
> > > > > > > > it
> > > > > > > > > > only attempts to convey the main principles
involved).
> > > > > > > > > >
> > > > > > > > > > Using a small training database I selected a
symbol
> that
> > > > had
> > > > > > an
> > > > > > > > > > opening close price of 28.01.
> > > > > > > > > >
> > > > > > > > > > The I ran the following in AA - with the symbol
> selected
> > > > as
> > > > > > the
> > > > > > > > > > current symbol in the All Symbols list.
> > > > > > > > > > The AB defaults are accepted except for
PositionSize
> and
> > > > > > > > MinShares
> > > > > > > > > > and Intitial Equity i.e. buy is on the Close.
> > > > > > > > > >
> > > > > > > > > > Equity itself will be a compounded % of the ROC
for 1
> > > > period
> > > > > > on
> > > > > > > > the
> > > > > > > > > > close.
> > > > > > > > > > Multiplying it by the starting close price adjusts
> equity
> > > > so
> > > > > > that
> > > > > > > > it
> > > > > > > > > > is relative to the starting close.
> > > > > > > > > >
> > > > > > > > > > Note: Intitial Eq does not allow decimal places
so I
> > > > chose 1
> > > > > > > > dollar.
> > > > > > > > > > Then I allowed shares to be purchased in
1/10000th
> > > > parcels so
> > > > > > > > that
> > > > > > > > > > the 1 dollar equity could be apportioned by up to
4
> > > > decimal
> > > > > > > > places
> > > > > > > > > > with accuracy.
> > > > > > > > > >
> > > > > > > > > > Filter = 1;
> > > > > > > > > >
> > > > > > > > > > //In AA settings Initial Equity = 1
> > > > > > > > > > //Min shares = 0.0001
> > > > > > > > > > //Run on all quotations
> > > > > > > > > >
> > > > > > > > > > PositionSize = -100;
> > > > > > > > > >
> > > > > > > > > > Buy =1;
> > > > > > > > > > Sell = 0;
> > > > > > > > > >
> > > > > > > > > > e = Equity();
> > > > > > > > > >
> > > > > > > > > > AddColumn(e,"equity",1.6,1);
> > > > > > > > > >
> > > > > > > > > > Plot(e * 28.01,"Equity",1,1);//manually enter the
> > > > starting
> > > > > > close
> > > > > > > > for
> > > > > > > > > > your symbol
> > > > > > > > > >
> > > > > > > > > > Since the plot simulates buying 1 * the opening
close
> > > > price
> > > > > > it
> > > > > > > > > > exactly equals the price chart (which is what I
> would get
> > > > if
> > > > > > I
> > > > > > > > bought
> > > > > > > > > > 1 share at the close of the first bar).
> > > > > > > > > > The number of bars doesn't matter since it is
never
> sold
> > > > in a
> > > > > > buy
> > > > > > > > and
> > > > > > > > > > hold (a little poetry there).
> > > > > > > > > >
> > > > > > > > > > The same thing can be done other ways:
> > > > > > > > > >
> > > > > > > > > > for example someone else provides this method ( I
won't
> > > > > > explain
> > > > > > > > it
> > > > > > > > > > because it is not mine but I don't see any reason
why
> > > > that
> > > > > > type
> > > > > > > > of
> > > > > > > > > > approach wouldn't work).
> > > > > > > > > >
> > > > > > > > > > /* now buy and hold simulation */
> > > > > > > > > > Short=Cover= 0;
> > > > > > > > > > Buy=Status(" firstbarintest" );
> > > > > > > > > > Sell=Status( "lastbarintest" );
> > > > > > > > > > SetTradeDelays( 0,0,0,0); PositionSize = -100;
> > > > > > > > > > ApplyStop(0, 0,0,0);
> > > > > > > > > > ApplyStop(1, 0,0,0);
> > > > > > > > > > ApplyStop(2, 0,0,0);
> > > > > > > > > > Plot( Equity( 0, -2 ), "Buy&Hold", -9 );
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > brian_z
> > > > > > > > > >
> > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Walter Lepore"
> > > > > > > > > > <electricwally77@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Brian
> > > > > > > > > > >
> > > > > > > > > > > I thank you for helping.
> > > > > > > > > > >
> > > > > > > > > > > Based on your advice, here is the code I
entered...
> > > > > > > > > > >
> > > > > > > > > > > _N(Title = StrFormat("{{NAME}} - {{INTERVAL}}
> {{DATE}}
> > > > Open
> > > > > > %g,
> > > > > > > > Hi %
> > > > > > > > > > g,
> > > > > > > > > > > Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L,
C,
> > > > > > SelectedValue
> > > > > > > > ( ROC
> > > > > > > > > > (
> > > > > > > > > > > C, 1 ) ) ));
> > > > > > > > > > > Plot( C, "Close", ParamColor("Color",
colorBlack ),
> > > > > > > > styleNoTitle |
> > > > > > > > > > > ParamStyle("Style") | GetPriceStyle() );
> > > > > > > > > > > _SECTION_END();
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Buy = 1;
> > > > > > > > > > > Sell = 0;
> > > > > > > > > > >
> > > > > > > > > > > I clicked "apply indicator" in the formula
window and
> > > > > > completed
> > > > > > > > a
> > > > > > > > > > back
> > > > > > > > > > > test but received some strange results. My
trade list
> > > > in
> > > > > > the AA
> > > > > > > > > > window
> > > > > > > > > > > shows 5 trades total. Under the trade column,
the
> first
> > > > > > trade
> > > > > > > > says
> > > > > > > > > > > "OUT". 2nd trade says "Long", 3rd trade says
> "Out", 4th
> > > > > > trade
> > > > > > > > says
> > > > > > > > > > > "Long" and the 5th trade says "Out".
> > > > > > > > > > >
> > > > > > > > > > > I clicked "show actual trades" and it shows a
red
> arrow
> > > > on
> > > > > > bar
> > > > > > > > 1
> > > > > > > > > > and a
> > > > > > > > > > > green and red arrow on bar 11,560 and a green
and red
> > > > arrow
> > > > > > on
> > > > > > > > bar
> > > > > > > > > > > 11,561.
> > > > > > > > > > >
> > > > > > > > > > > There are 11,561 bars total (daily data from
1962 to
> > > > 2007)
> > > > > > > > > > >
> > > > > > > > > > > Hope you can help please
> > > > > > > > > > >
> > > > > > > > > > > Thanks Brian
> > > > > > > > > > > Walter
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111"
> > > > > > <brian_z111@>
> > > > > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Walter,
> > > > > > > > > > > >
> > > > > > > > > > > > There' more than one way - here's a simple
one.
> > > > > > > > > > > >
> > > > > > > > > > > > buy = 1;
> > > > > > > > > > > > sell = 0;
> > > > > > > > > > > >
> > > > > > > > > > > > There's an extended example in the files
section of
> > > > this
> > > > > > > > message
> > > > > > > > > > > > board.
> > > > > > > > > > > >
> > > > > > > > > > > > Files > CompareIndexToPortfolio
> > > > > > > > > > > >
> > > > > > > > > > > > brian_z
> > > > > > > > > > > >
> > > > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Walter
Lepore"
> > > > > > > > > > > > <electricwally77@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Members
> > > > > > > > > > > > >
> > > > > > > > > > > > > Please bear with me. I am trying to write a
> simply
> > > > Buy
> > > > > > and
> > > > > > > > Hold
> > > > > > > > > > > > system
> > > > > > > > > > > > > using only one stock (HPQ-Hewlitt Packard).
I'm
> > > > using
> > > > > > End
> > > > > > > > of
> > > > > > > > > > Day
> > > > > > > > > > > > data
> > > > > > > > > > > > > and programming using the AFL Wizard . I've
> been at
> > > > it
> > > > > > for
> > > > > > > > > > about two
> > > > > > > > > > > > > hours but can't generate the results of a
simple
> > > > buy &
> > > > > > Hold.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Obviously I'm doing something wrong. There
are a
> > > > total
> > > > > > of
> > > > > > > > > > 11,561
> > > > > > > > > > > > > Daily bars in the data I downloaded from
Yahoo.
> > > > > > > > > > > > >
> > > > > > > > > > > > > I've built several different formulas and
none of
> > > > them
> > > > > > > > result
> > > > > > > > > > in a
> > > > > > > > > > > > > simple Buy and Hold when I backtest and run
a
> > > > report.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Can someone please tell me what the code is
for a
> > > > > > simple
> > > > > > > > buy
> > > > > > > > > > and
> > > > > > > > > > > > hold
> > > > > > > > > > > > > please?
> > > > > > > > > > > > >
> > > > > > > > > > > > > I assume there will only be an "Enter Long"
but
> > > > > > NO "Exit
> > > > > > > > Long"
> > > > > > > > > > since
> > > > > > > > > > > > > I'm still holding. Correct?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thank you very much
> > > > > > > > > > > > > Walter
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
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
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> 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/
|