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

[amibroker] Re: Net position sizing.



PureBytes Links

Trading Reference Links

Hello,

Once more, thanks to Ed Pottasch for the help. Same thing to cipherscribe.

Your piece of work awake a question I never found a robust answer.

Till now I discretionnary traded the future. This way it's difficult
to pyramid.

So my question is : For a private investor, does the financial system
allow a huge or illimited profit ?

My believe is that an annual profit amount is bearable. Such a winner
is a pain in the ass for the system, but until a predefined level, ie
a number of lots not too high, it's oK.
But if the idea is to beat records of gain, red alarms will blink and
retaliatory measure are taken. 
An acceptable solution for the two parts is to become a professionnal
trader into a financial structure.

If this question is not off the subjet , i'll appreciate your comments
and if the question has a meaning which annual $ amount is the glass
ceilling ?

Best regards

--- In amibroker@xxxxxxxxxxxxxxx, "cipherscribe"
<adrian.mollenhorst@xxx> wrote:
>
> OMG! I think I did it! The following code limits the net position on a
> single instrument in raw backtest mode to 3. So if you had two long
> positions open, you could up to 5 shorts. If anyone sees a problem
> with the code, let me know.
> 
> It became clearer when I read up a bit more (RTFM!), and got to
> understand what openpos describes as opposed to signal.
> 
> Turns out this tells me I am better off (marginally) taking as many
> positions as I can - not much more in CAR, but slightly better CAR/MDD
> 
> Adrian
> 
> _SECTION_BEGIN("Maximum position");
> // Maximum position 
> //-----------------------------
> SetCustomBacktestProc("");
> if( Status("action") == actionPortfolio ) {
>  
>    bo = GetBacktesterObject();
>    bo.PreProcess();
>  
>    for( i = 0; i < BarCount; i++ ) {
>       cnt = 0;
>       for( Openpos = bo.GetFirstopenpos(); Openpos; Openpos =
> bo.GetNextopenpos() ) {
>          if( Openpos.Islong() ) {
> 				Cnt = Cnt+1;
> 				}
> 			else if (!Openpos.Islong()) {
> 				Cnt = Cnt-1;
> 				}
> 
>            for( sig = bo.GetFirstSignal(i); sig; sig =
> bo.GetNextSignal(i) ) {
> 			 if( cnt < -2 OR Cnt >2) {
>          if( sig.IsEntry() ) {
>             sig.PosSize = 0;
> 
>             } 
>             }
>          }
> }
>       
> 
>       bo.ProcessTradeSignals( i );
>    }
>    bo.PostProcess();
> }
> //-----------------------------
> _SECTION_END();
> 
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "cipherscribe"
> <adrian.mollenhorst@> wrote:
> >
> > Man,
> > 
> > This stuff has done my head in. I can't get it to work, but realise
> > it's not going to be a two liner.
> > 
> > Are there any other resources on the custom backtester, other than
> > those two links, or the "Houston2.pdf" that goes into more detail and
> > examples?
> > 
> > Adrian
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@>
> > wrote:
> > >
> > > yeah well the code shows the idea ... can't garantee that the code
> > as it is posted works as it is intended :)  But I was able to use
> > similar code to construct a balanced system (same number of long and
> > short positions at all times) so maybe you find parts of the code
> useful,
> > > 
> > > rgds, Ed
> > > 
> > > 
> > > 
> > > 
> > > 
> > >   ----- Original Message ----- 
> > >   From: cipherscribe 
> > >   To: amibroker@xxxxxxxxxxxxxxx 
> > >   Sent: Wednesday, September 24, 2008 9:59 PM
> > >   Subject: [amibroker] Re: Net position sizing.
> > > 
> > > 
> > >   Wow! Thanks Ed.
> > > 
> > >   There's alot of learning in your code. Really appreciate you
> posting.
> > >   I'll send you an update once I digest it all... :-)
> > > 
> > >   --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@>
> > >   wrote:
> > >   >
> > >   > maybe this code helps also:
> > >   > 
> > >   > 
> > >   >
> > >  
> >
>
http://www.mail-archive.com/amibroker-beta@xxxxxxxxxxxxxxx/msg00262/equalLongShort001.afl
> > >   > 
> > >   > 
> > >   > 
> > >   > 
> > >   > 
> > >   > ----- Original Message ----- 
> > >   > From: cipherscribe 
> > >   > To: amibroker@xxxxxxxxxxxxxxx 
> > >   > Sent: Wednesday, September 24, 2008 9:10 PM
> > >   > Subject: [amibroker] Re: Net position sizing.
> > >   > 
> > >   > 
> > >   > Thanks Ed.
> > >   > 
> > >   > I love that exclamation mark!
> > >   > 
> > >   > I am using the following code, but it's not eliminating the
trades
> > >   > above the param number. I tried using the default backtest mode
> > >   > (removed the "backtestRegularRawMulti" statement), and ran the
> code
> > >   > with a watchlist of symbols, but I still get more trades
processed
> > >   > than that in my param field.
> > >   > 
> > >   > Any clues here on why this code may not be working?
> > >   > 
> > >   > One clue is when I set the parameter to zero, it works - no long
> > >   > trades are executed. But any number other than zero, and it
> > processes
> > >   > them all in the backtest.
> > >   > 
> > >   > _SECTION_BEGIN("Maximum buys");
> > >   > // Maximum buys in a period
> > >   > //-----------------------------
> > >   > SetCustomBacktestProc("");
> > >   > Num = Param("MaxBuys",4,0,9,1);
> > >   > MaxBuys = Num;
> > >   > 
> > >   > if( Status("action") == actionPortfolio ) {
> > >   > 
> > >   > bo = GetBacktesterObject();
> > >   > bo.PreProcess();
> > >   > 
> > >   > for( i = 0; i < BarCount; i++ ) {
> > >   > cntBuys = 0;
> > >   > for( sig= bo.GetFirstsignal(i); sig; sig =
bo.GetNextsignal(i) ) {
> > >   > if( sig.Islong() ) {
> > >   > if( CntBuys > MaxBuys - 1 ) {
> > >   > sig.possize= 0;
> > >   > } else {
> > >   > cntBuys++;
> > >   > }
> > >   > }
> > >   > }
> > >   > bo.ProcessTradeSignals( i );
> > >   > }
> > >   > bo.PostProcess();
> > >   > }
> > >   > //-----------------------------
> > >   > _SECTION_END();
> > >   > 
> > >   > --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch"
<empottasch@>
> > >   > wrote:
> > >   > >
> > >   > > if you are for instance looping through the trades like:
> > >   > > 
> > >   > > for( trade = bo.GetFirstTrade(); trade ; trade =
> > >   bo.GetNextTrade() ) {
> > >   > > 
> > >   > > then you can check: if (!trade.IsLong)
> > >   > > 
> > >   > > rgds,Ed
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > 
> > >   > > ----- Original Message ----- 
> > >   > > From: cipherscribe 
> > >   > > To: amibroker@xxxxxxxxxxxxxxx 
> > >   > > Sent: Wednesday, September 24, 2008 8:33 PM
> > >   > > Subject: [amibroker] Re: Net position sizing.
> > >   > > 
> > >   > > 
> > >   > > How do you identify a short signal in the preprocess? I see
> > only the
> > >   > > following signal object methods:
> > >   > > 
> > >   > > Methods:
> > >   > > 
> > >   > > * bool IsEntry()
> > >   > > 
> > >   > > True if this is entry signal, False otherwise
> > >   > > 
> > >   > > * bool IsExit()
> > >   > > 
> > >   > > True if this is exit signal, False otherwise
> > >   > > 
> > >   > > * bool IsLong()
> > >   > > 
> > >   > > True if this is long entry (buy) or long exit (sell) or
scale-in
> > >   > > signal, False otherwise
> > >   > > 
> > >   > > * bool IsScale()
> > >   > > 
> > >   > > True if this is scale-in or scale-out signal, False otherwise 
> > >   > > 
> > >   > > Is there a IsShort() method?
> > >   > > 
> > >   > > Cheers,
> > >   > > 
> > >   > > Adrian
> > >   > > 
> > >   > > --- In amibroker@xxxxxxxxxxxxxxx, "cipherscribe"
> > >   > > <adrian.mollenhorst@> wrote:
> > >   > > >
> > >   > > > Thanks Thomasz and Ara,
> > >   > > > 
> > >   > > > I am using the "backtestRegularRawMulti" option, which
> gives me
> > >   > > > multiple signals.
> > >   > > > 
> > >   > > > Thanks for the hint to direct my attentions toward the
custom
> > >   > > > backtester. I shall look into it and hopefully code what
I am
> > >   > > looking for.
> > >   > > > 
> > >   > > > Cheers,
> > >   > > > 
> > >   > > > Adrian
> > >   > > > 
> > >   > > > 
> > >   > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko"
<groups@>
> > >   wrote:
> > >   > > > >
> > >   > > > > By default you can NOT have both LONG and SHORT pos on the
> > same
> > >   > > > symbol open at the same time.
> > >   > > > > 
> > >   > > > > The only way to have it is to use low-level custom
> backtester.
> > >   > > > > http://www.amibroker.com/guide/a_custombacktest.html
> > >   > > > > 
> > >   > > > > Best regards,
> > >   > > > > Tomasz Janeczko
> > >   > > > > amibroker.com
> > >   > > > > ----- Original Message ----- 
> > >   > > > > From: "cipherscribe" <adrian.mollenhorst@>
> > >   > > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > >   > > > > Sent: Wednesday, September 24, 2008 5:17 PM
> > >   > > > > Subject: [amibroker] Net position sizing.
> > >   > > > > 
> > >   > > > > 
> > >   > > > > >I trade the ES Futures contract mechanically, and I
want my
> > >   to be
> > >   > > able
> > >   > > > > > to backtest my system such that it has a maximum net
> > >   > position at any
> > >   > > > > > one time of abs(x) positions.
> > >   > > > > > 
> > >   > > > > > I can set the option to limit the number of Maximum Open
> > >   > Positions,
> > >   > > > > > but this doesn't help me when I am trading only 1
> > instrument. 
> > >   > > > > > 
> > >   > > > > > For example (Note I am using the backtest mode
> > >   > > > > > "backtestRegularRawMulti", so I take every raw signal my
> > >   equity
> > >   > > allows
> > >   > > > > > me.), the system can issue a buy, which will make me
long.
> > >   > If the
> > >   > > > > > system issues a short, while I'm long, it will send a
> short
> > >   > order,
> > >   > > > > > which will make me effectively flat.
> > >   > > > > > 
> > >   > > > > > This will count as 2 open orders in the backtester,
but in
> > >   > > reality, I
> > >   > > > > > have no positions open, and could take another abs(x) in
> > >   either
> > >   > > > > > direction before I hit my maximum limit of open
> > positions (x).
> > >   > > > > > 
> > >   > > > > > So if I had 2 longs open, I could accept up to 5 shorts,
> > if my
> > >   > > maximum
> > >   > > > > > open position(x) was abs(3).
> > >   > > > > > 
> > >   > > > > > This is different from exiting a position when a signal
> > in the
> > >   > > > > > opposing direction is triggerred, as in
> > >   > "ReverseSignalForcesExit",
> > >   > > > > > since that option cancels the existing order. I need
> both to
> > >   > remain
> > >   > > > > > open, remembered, and exited at my sell/cover trigger,
> > not the
> > >   > > > > > opposing short/buy signal.
> > >   > > > > > 
> > >   > > > > > What I need is for Amibroker to tabulate both long and
> short
> > >   > > positions
> > >   > > > > > distinctly, to count longs as positive, shorts as
> > >   > negatively, and to
> > >   > > > > > be able to set a maximum net position.
> > >   > > > > > 
> > >   > > > > > I can do this in reality with no problems - send orders
> > to IB
> > >   > > based on
> > >   > > > > > a maximum net position, but I'd like to be able to do
> it in
> > >   > > > > > backtester, so I can validate the system.
> > >   > > > > > 
> > >   > > > > > Any Ideas?
> > >   > > > > > 
> > >   > > > > > 
> > >   > > > > > ------------------------------------
> > >   > > > > > 
> > >   > > > > > 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
> > >   > > > > > 
> > >   > > > > > 
> > >   > > > > >
> > >   > > > >
> > >   > > >
> > >   > >
> > >   >
> > >
> >
>



------------------------------------

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/