Markus -
OK, here's an example of what I think that you were after. It is a
non-practical demo, but should show some points about encoding of signal
types. In your case, it shows calculating number of shares directly
from % of cash and putting it in the signal object for the backtester to
process. See the comments for details and the AA results for the
effect. BTW, I hope you'll find some other nuggets in this example
also, and find it useful as a framework for exploring some aspects of
the CBT. Some aspects of the CBT just need to be "played" with to see
what is possible. This will teach me to get involved. :-)
-- BruceR
// Simple example to do the following -
// 1. Buy on the first trading day of the month and sell 5 days
later
// 2. Setup default to buy $5000
// 3. Then, in the CBT, modify the trades on even months to buy s
// shares equal to 20% of cash.
//
// NOTE - the encodings for PosSize as detailed in the
SetPositionSize() help are -
// values below -2000 encode share count,
// values between -2000 AND -1000 encode % of current
position (scaling)
// values between -1000 AND 0 encode % of portfolio Equity
// values above 0 encode dollar value
Buy = IIf( Month( ) != Ref( Month( ), -1 ), 1, 0 );
Sell = Ref( Buy, -5 );
Short = Cover = 0;
SetPositionSize( 5000, spsValue );
SetOption( "InitialEquity", 100000 );
RoundLotSize = 1;
// MID-LEVEL CBT MODEL
SetOption( "UseCustomBacktestProc", True );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject( );
bo.PreProcess( );
mon = Month( );
dt = DateTime( );
for ( bar = 0; bar < BarCount; bar++ )
{
for( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal(
bar ) )
{
// On even months, arbitrarily buy shares = 20% of cash
// On odd months, $5000 will be used from SetPositionSize
above
if ( sig.IsEntry )
{
if ( Mon[ bar ] % 2 == 0 AND sig.IsEntry )
{
// Note - int() function effectively rounds down
shares = int( bo.cash * 0.20 / sig.Price );
sig.PosSize = -2000 - shares;
}
_TRACE( NumToStr( dt[ bar ], formatDateTime ) +
" , Cash = " + bo.Cash +
" , Price = " + sig.Price +
" , PositionSize = " + sig.possize );
}
}
bo.ProcessTradeSignals( bar );
}
bo.PostProcess( );
}
--- In [email protected], "bruce1r" <bru...@...> wrote:
>
> Markus -
>
> I don't think that you, and maybe Mike, are seeing what I'm trying to
point out. I referred you to SetPositionSize() help because it details
the encoding of shares in PosSize in the signal object in the CBT.
Specically that is (-2000-shares).
>
> When you traverse the signal objects in the CBT, you can do your own
calculation of shares from cash or whatever, and replace the sig.PosSize
value before calling the mid or low level routines to process trades.
>
> Stated simply, you can set the number of shares yourself directly in
the CBT from your own calculation.
>
> If that is what you're after, give me a short time and I'll whip up an
example if you don't see this.
>
> -- Bruce
>
>
> --- In [email protected], Markus Witzler funnybiz@ wrote:
> >
> > Hello Bruce,
> >
> > the reason I must use CBT is that I can´t use Setpositionsize
(...spsshares), since I need to compute adequate number of shares by
referring to actual cash position.
> >
> > "spsShares" doesn´t allow - according to cust. support- for
calling current cash or equity position to compute "spsshares". Thus the
need for using CBT.
> >
> > Normally, everyone seems to compute sig.possize (and implied number
of shares is a result thereof). I want to compute shares and the
position size (in money terms) should be the implied result - thus the
other way around.
> >
> > The reason for this is that i want to follow along a coding
excercise I was given. And I´m not sure that -if I only specify
sig.possize and not sharesize (i.e. trade.shares)- that AB may screw up
(i.e. round up or down in some cases) when I don´t realize that.
> >
> > Take for instance into account that AB ALWAYS rounds DOWN if
fraction of shares occur.
> >
> > I, myself, want to have control if rounding occurs or not and HOw it
occurs (up or down). That could sometimes mean I´m rounding up when
AB would round down.
> >
> > This is not because I´m particularly picky since this issue
influences the outcome of the backtest only slightly. It´s only that
I want to accurately reproduce the results of the excercise I was given.
> >
> > In actual trading, there shouldn´t be any problem determining
sig.possize in signal list and leave it up to AB to (maybe) rounding up
or down potential fractional shares.
> >
> > If you have any clue that might help, please fell free to step in.
> >
> > Thanks for your contribution
> >
> > Markus
> > ________________________________________________________________
> > Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
> > für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/
> >
>