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

[amibroker] Re: Hedging with PositionScore?



PureBytes Links

Trading Reference Links

Ed, thanks for the code, and sorry for the late reply. Btw, I solved 
the varset/-get myself (it works fine). 

However, I suggest we continue this discussion on the beta-group, 
where I'll post a mail with some of my code. I hope for anybody 
interested that it highlights the possibilities, but also possibly 
(?) some of the limitations of the CBT. The header of my mail will 
be "Dynamic rebalancing via CBT".


PS

--- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@xxx> 
wrote:
>
> hi,
> 
> I think te code I posted in the beta group does not address your 
specific problem. I have not used varset so I would not know if there 
is a problem here. I posted my code here as wel and was not planning 
to upload in the file section since I am fairly new to the topic 
myself. I just tried to get some conversation going on the CBI but I 
think for many people the problem is  getting started with it.  I am 
finding out it is not too complicated it just needs some good 
examples.
> 
> Maybe if you explain what you want to do I can help,
> 
> rgds, Ed
> 
> 
> 
>   ----- Original Message ----- 
>   From: vlanschot 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Tuesday, May 08, 2007 11:35 AM
>   Subject: [amibroker] Re: Hedging with PositionScore?
> 
> 
>   Question for Ed (nl) who created the code below in 03/2005, or of 
>   course anybody else who cares to jump in.
> 
>   Is there any reason why I cannot seem to get, in the 
GetFirstSignal-
>   loop, the values from a VarSet which I defined previously in the 
>   GetFirstOpenPos-loop. Your code below shows that 
the "cntlongopen" 
>   variable, defined in the 1st loop, can be called later in the 2nd 
>   loop.
> 
>   For all clarity, I need to make a link between stock-specific 
>   variables between these loops. In other words, I use VarSet 
>   ("Var1"+openpos.Symbol, var1) in order to retrieve it in the 2nd 
loop 
>   via VarGet("Var1"+sig.Symbol). So far, this doesn't work.
> 
>   For context, and as mentioned in some of my previous mails, I'm 
>   trying to code a fairly simple (I thought) rebalancing strategy, 
this 
>   time without the rotational trading bit. Any help appreciated.
> 
>   Thx,
> 
>   PS 
> 
>   --- In amibroker@xxxxxxxxxxxxxxx, "ed nl" <ed2000nl@> wrote:
>   >
>   > Herman,
>   > 
>   > I expanded the code a little. Now you can set maxShort is well. 
The 
>   nice thing about this is that you will only go full inside the 
margin 
>   with mixed long and short positions and not just either long or 
short,
>   > 
>   > rgds, Ed
>   > 
>   > 
>   > 
>   > /* 
>   > 
>   > Do not allow more than "maxLong" LONG positions OR "maxShort" 
SHORT 
>   positions 
>   > 
>   > */ 
>   > 
>   > SetCustomBacktestProc(""); 
>   > 
>   > maxLong = 8; 
>   > maxShort = 9; 
>   > 
>   > if( Status("action") == actionPortfolio ) { 
>   > 
>   > bo = GetBacktesterObject(); 
>   > bo.PreProcess(); 
>   > 
>   > for( i = 0; i < BarCount; i++ ) { 
>   > 
>   > 
>   > cntLongOpen = 0; 
>   > cntShortOpen = 0; 
>   > 
>   > // scan through open positions and count the number of long 
>   positions 
>   > for( openpos = bo.GetFirstOpenPos(); openpos; openpos = 
>   bo.GetNextOpenPos() ) { 
>   > 
>   > // check for entry signal and long signal 
>   > if( openpos.IsOpen AND openpos.IsLong ) { 
>   > 
>   > cntLongOpen = cntLongOpen + 1; 
>   > 
>   > } else if ( openpos.IsOpen AND openpos.IsLong == 0) { 
>   > 
>   > cntShortOpen = cntShortOpen + 1; 
>   > 
>   > } 
>   > 
>   > } 
>   > 
>   > 
>   > // look at new signals and exclude Long signals if they 
>   exceed maxLong 
>   > for( sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal
>   (i) ) { 
>   > 
>   > // check for entry signal and long signal 
>   > if( sig.IsEntry() AND sig.IsLong() ) { 
>   > 
>   > if( cntLongOpen >= maxLong ) { 
>   > 
>   > sig.PosSize = 0; 
>   > 
>   > } else { 
>   > 
>   > cntLongOpen = cntLongOpen + 1; 
>   > 
>   > 
>   > } 
>   > 
>   > // check for entry signal and short signal 
>   > } else if ( sig.IsEntry() AND sig.IsLong() == 0) { 
>   > 
>   > if( cntShortOpen >= maxShort ) { 
>   > 
>   > sig.PosSize = 0; 
>   > 
>   > } else { 
>   > 
>   > cntShortOpen = cntShortOpen + 1; 
>   > 
>   > 
>   > } 
>   > 
>   > 
>   > } 
>   > 
>   > 
>   > } 
>   > 
>   > bo.ProcessTradeSignals( i ); 
>   > } 
>   > 
>   > bo.PostProcess(); 
>   > 
>   > } 
>   > ----- Original Message ----- 
>   > From: Herman van den Bergen 
>   > To: amibroker@xxxxxxxxxxxxxxx 
>   > Sent: Tuesday, March 01, 2005 11:59 AM
>   > Subject: RE: [amibroker] Hedging with PositionScore?
>   > 
>   > 
>   > Thank you Ed, will try that!
>   > 
>   > herman
>   > -----Original Message-----
>   > From: ed nl [mailto:ed2000nl@]
>   > Sent: Tuesday, March 01, 2005 2:42 AM
>   > To: amibroker@xxxxxxxxxxxxxxx
>   > Subject: Re: [amibroker] Hedging with PositionScore?
>   > 
>   > 
>   > I think I answered my own question in case you are interested. 
>   It seems to work.
>   > 
>   > rgds, Ed
>   > 
>   > 
>   > /* 
>   > 
>   > Number of positions: do not allow more than "maxLong" LONG 
>   positions 
>   > 
>   > */ 
>   > 
>   > SetCustomBacktestProc(""); 
>   > 
>   > maxLong = 7; 
>   > 
>   > if( Status("action") == actionPortfolio ) { 
>   > 
>   > bo = GetBacktesterObject(); 
>   > bo.PreProcess(); 
>   > 
>   > for( i = 0; i < BarCount; i++ ) { 
>   > 
>   > 
>   > cntLongOpen = 0; 
>   > 
>   > // scan through open positions and count the number of 
>   long positions 
>   > for( openpos = bo.GetFirstOpenPos(); openpos; openpos = 
>   bo.GetNextOpenPos() ) { 
>   > 
>   > // check for entry signal and long signal 
>   > if( openpos.IsOpen AND openpos.IsLong ) { 
>   > 
>   > cntLongOpen = cntLongOpen + 1; 
>   > 
>   > } 
>   > 
>   > } 
>   > 
>   > 
>   > // look at new signals and exclude Long signals if they 
>   exceed maxLong 
>   > for( sig = bo.GetFirstSignal(i); sig; sig = 
>   bo.GetNextSignal(i) ) { 
>   > 
>   > // check for entry signal and long signal 
>   > if( sig.IsEntry() AND sig.IsLong() ) { 
>   > 
>   > if( cntLongOpen > maxLong ) { 
>   > 
>   > sig.PosSize = 0; 
>   > 
>   > } else { 
>   > 
>   > cntLongOpen = cntLongOpen + 1; 
>   > 
>   > 
>   > } 
>   > 
>   > 
>   > } 
>   > 
>   > } 
>   > 
>   > bo.ProcessTradeSignals( i ); 
>   > } 
>   > 
>   > bo.PostProcess(); 
>   > 
>   > }
>




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/