Re: [amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread Tomasz Janeczko
  Hello,

:-) Well, if you calculate closing equity the way I described, you won't need 
low level.

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-16 19:34, rise_t575 wrote:
>
> Thanks for this additional info.
>
> I just was thinking something like "My very first CBT code and I have to use 
> low level... That's what I call bad luck..."
>
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>>Hello,
>>
>> One more thing to add: as an alternative to going low-level, you could 
>> iterate through open positions list on your own
>> (GetFirstOpenPos/GetNextOpenPos) get number of shares (Shares property) and 
>> multiply by Close price (trade object has GetPrice(bar, "C") method for 
>> that), then
>> add to bo.Cash and you get the closing equity value that way, without need 
>> to call UpdateStats
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>>
>> On 2010-07-16 19:17, Tomasz Janeczko wrote:
>>>   Hello,
>>>
>>> Generally speaking  you should be using low-level backtest for that.
>>> Guessing from your rather short descriptions, I think that you are trying 
>>> to override normal spsPercentOfEquity
>>> position size processing and use your own.
>>>
>>> The example codes for using low-level interface are included at the end of 
>>> this article:
>>> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
>>>
>>> ProcessTradeSignals not only processes signals but also does what 
>>> UpdateStats() is doing therefore
>>> you should not mix both since exposure will be counted twice.
>>>
>>> Using low-level mode avoids that.
>>>
>>> Best regards,
>>> Tomasz Janeczko
>>> amibroker.com
>>>
>>> On 2010-07-16 18:56, rise_t575 wrote:
 One last question for clarification:

 1) On one hand, I have to call bo.ProcessTradeSignals() for updating 
 equity.
 2) On the other hand, I have to calculate position sizes *before* calling 
 bo.ProcessTradeSignals().
 3) But for calculating the correct position sizes, my position sizing code 
 has to have access to the updated equity.

 So using UpdateStats() in this case is *mandatory*, correct?

 --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
> Hello,
>
> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
> TimeInsideBar = 2
> two things in addition to updating equity happen:
> a) interest earnings are added (from free cash)
> b) position exposure and portfolio stats are calculated
>
> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) 
> more than once per bar.
>
> One thing you should think of:  be aware that if you are using current 
> bar closing equity for
> position sizing, you are generating possible future data leak.
> How is that so? It is easy - assume that your position sizing depends on 
> current equity,
> you can calculate bar's open equity and open position equal to the 
> difference between
> open equity and close equity of the same bar. And you generate single bar 
> trade.
> This way you have the system that has 100% winning trades, because it is 
> using future leak in
> position sizing.
> That is the reason AmiBroker DOES NOT use close equity of current bar for 
> position sizing.
> It either uses previous bar close equity or equity value at the open.
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
>
> On 2010-07-16 15:29, rise_t575 wrote:
>> I see - thanks.
>>
>> Actually I would like to use equity calculated from closing prices of 
>> the current bar (by searching the web, I've found that normally, AB 
>> calculates equity
>> for position sizing with opening prices of the current bar - and not 
>> being aware of this has caused me some major headaches the last couple 
>> of days. Is
>> this mentioned in the position sizing related sections of the manual? If 
>> not, this information should be added). Reading the description of 
>> UpdateStats(),
>> it seems like I could achieve this by setting the second (TimInsideBar) 
>> parameter to "2". When I put "bo.UpdateStats( bar, 2 );" into my code, 
>> at least the
>> position sizes are calculated exactly the way I want them to.
>> But there are several warnings about doing this in the method's 
>> description. Can I unintentionally mess something up by doing this?
>>
>> Thanks.
>>
>> --- In amibroker@yahoogroups.com, Tomasz Janeczkowrote:
>>>  Hello,
>>>
>>> Sorry, the method name is actually UpdateStats()
>>>
>>> Best regards,
>>> Tomasz Janeczko
>>> amibroker.com
>>>
>>> On 2010-07-16 14:06, rise_t575 wrote:
 Probably I'm blind, but I cannot find any information about the 
 mentioned UpdateEquity() function, any searches in the online/offline 
 manual result
 noth

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


Thanks for this additional info.

I just was thinking something like "My very first CBT code and I have to use 
low level... That's what I call bad luck..."

--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> One more thing to add: as an alternative to going low-level, you could 
> iterate through open positions list on your own
> (GetFirstOpenPos/GetNextOpenPos) get number of shares (Shares property) and 
> multiply by Close price (trade object has GetPrice(bar, "C") method for 
> that), then 
> add to bo.Cash and you get the closing equity value that way, without need to 
> call UpdateStats
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-16 19:17, Tomasz Janeczko wrote:
> >  Hello,
> >
> > Generally speaking  you should be using low-level backtest for that.
> > Guessing from your rather short descriptions, I think that you are trying 
> > to override normal spsPercentOfEquity
> > position size processing and use your own.
> >
> > The example codes for using low-level interface are included at the end of 
> > this article:
> > http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> >
> > ProcessTradeSignals not only processes signals but also does what 
> > UpdateStats() is doing therefore
> > you should not mix both since exposure will be counted twice.
> >
> > Using low-level mode avoids that.
> >
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> >
> > On 2010-07-16 18:56, rise_t575 wrote:
> >>
> >> One last question for clarification:
> >>
> >> 1) On one hand, I have to call bo.ProcessTradeSignals() for updating 
> >> equity.
> >> 2) On the other hand, I have to calculate position sizes *before* calling 
> >> bo.ProcessTradeSignals().
> >> 3) But for calculating the correct position sizes, my position sizing code 
> >> has to have access to the updated equity.
> >>
> >> So using UpdateStats() in this case is *mandatory*, correct?
> >>
> >> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >>>Hello,
> >>>
> >>> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
> >>> TimeInsideBar = 2
> >>> two things in addition to updating equity happen:
> >>> a) interest earnings are added (from free cash)
> >>> b) position exposure and portfolio stats are calculated
> >>>
> >>> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) 
> >>> more than once per bar.
> >>>
> >>> One thing you should think of:  be aware that if you are using current 
> >>> bar closing equity for
> >>> position sizing, you are generating possible future data leak.
> >>> How is that so? It is easy - assume that your position sizing depends on 
> >>> current equity,
> >>> you can calculate bar's open equity and open position equal to the 
> >>> difference between
> >>> open equity and close equity of the same bar. And you generate single bar 
> >>> trade.
> >>> This way you have the system that has 100% winning trades, because it is 
> >>> using future leak in
> >>> position sizing.
> >>> That is the reason AmiBroker DOES NOT use close equity of current bar for 
> >>> position sizing.
> >>> It either uses previous bar close equity or equity value at the open.
> >>>
> >>> Best regards,
> >>> Tomasz Janeczko
> >>> amibroker.com
> >>>
> >>> On 2010-07-16 15:29, rise_t575 wrote:
>  I see - thanks.
> 
>  Actually I would like to use equity calculated from closing prices of 
>  the current bar (by searching the web, I've found that normally, AB 
>  calculates equity 
>  for position sizing with opening prices of the current bar - and not 
>  being aware of this has caused me some major headaches the last couple 
>  of days. Is 
>  this mentioned in the position sizing related sections of the manual? If 
>  not, this information should be added). Reading the description of 
>  UpdateStats(), 
>  it seems like I could achieve this by setting the second (TimInsideBar) 
>  parameter to "2". When I put "bo.UpdateStats( bar, 2 );" into my code, 
>  at least the 
>  position sizes are calculated exactly the way I want them to.
>  But there are several warnings about doing this in the method's 
>  description. Can I unintentionally mess something up by doing this?
> 
>  Thanks.
> 
>  --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
> > Hello,
> >
> > Sorry, the method name is actually UpdateStats()
> >
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> >
> > On 2010-07-16 14:06, rise_t575 wrote:
> >> Probably I'm blind, but I cannot find any information about the 
> >> mentioned UpdateEquity() function, any searches in the online/offline 
> >> manual result 
> >> nothing. Could someone provide me with a link?
> >>
> >> Thanks.
> >>
> >>
> >> --- In amibroker@yahoogroups.com, Tomasz Janeczkowrote:
> >>>  Hello,
> >>>
> >>> T

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


Yes, correct - that's exactly what I am trying - completely overriding normal 
spsPercentOfEquity.

Your reply also clears up the question if using UpdateStats() within the 
barcount loop *and* calling ProcessTradeSignals() thereafter would be equal to 
using UpdateStats() twice per bar - which seems to be a "yes".


--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> Generally speaking  you should be using low-level backtest for that.
> Guessing from your rather short descriptions, I think that you are trying to 
> override normal spsPercentOfEquity
> position size processing and use your own.
> 
> The example codes for using low-level interface are included at the end of 
> this article:
> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> 
> ProcessTradeSignals not only processes signals but also does what 
> UpdateStats() is doing therefore
> you should not mix both since exposure will be counted twice.
> 
> Using low-level mode avoids that.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-16 18:56, rise_t575 wrote:
> >
> > One last question for clarification:
> >
> > 1) On one hand, I have to call bo.ProcessTradeSignals() for updating equity.
> > 2) On the other hand, I have to calculate position sizes *before* calling 
> > bo.ProcessTradeSignals().
> > 3) But for calculating the correct position sizes, my position sizing code 
> > has to have access to the updated equity.
> >
> > So using UpdateStats() in this case is *mandatory*, correct?
> >
> > --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >>Hello,
> >>
> >> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
> >> TimeInsideBar = 2
> >> two things in addition to updating equity happen:
> >> a) interest earnings are added (from free cash)
> >> b) position exposure and portfolio stats are calculated
> >>
> >> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) 
> >> more than once per bar.
> >>
> >> One thing you should think of:  be aware that if you are using current bar 
> >> closing equity for
> >> position sizing, you are generating possible future data leak.
> >> How is that so? It is easy - assume that your position sizing depends on 
> >> current equity,
> >> you can calculate bar's open equity and open position equal to the 
> >> difference between
> >> open equity and close equity of the same bar. And you generate single bar 
> >> trade.
> >> This way you have the system that has 100% winning trades, because it is 
> >> using future leak in
> >> position sizing.
> >> That is the reason AmiBroker DOES NOT use close equity of current bar for 
> >> position sizing.
> >> It either uses previous bar close equity or equity value at the open.
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >>
> >> On 2010-07-16 15:29, rise_t575 wrote:
> >>> I see - thanks.
> >>>
> >>> Actually I would like to use equity calculated from closing prices of the 
> >>> current bar (by searching the web, I've found that normally, AB 
> >>> calculates equity for position sizing with opening prices of the current 
> >>> bar - and not being aware of this has caused me some major headaches the 
> >>> last couple of days. Is this mentioned in the position sizing related 
> >>> sections of the manual? If not, this information should be added). 
> >>> Reading the description of UpdateStats(), it seems like I could achieve 
> >>> this by setting the second (TimInsideBar) parameter to "2". When I put 
> >>> "bo.UpdateStats( bar, 2 );" into my code, at least the position sizes are 
> >>> calculated exactly the way I want them to.
> >>> But there are several warnings about doing this in the method's 
> >>> description. Can I unintentionally mess something up by doing this?
> >>>
> >>> Thanks.
> >>>
> >>> --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
>  Hello,
> 
>  Sorry, the method name is actually UpdateStats()
> 
>  Best regards,
>  Tomasz Janeczko
>  amibroker.com
> 
>  On 2010-07-16 14:06, rise_t575 wrote:
> > Probably I'm blind, but I cannot find any information about the 
> > mentioned UpdateEquity() function, any searches in the online/offline 
> > manual result nothing. Could someone provide me with a link?
> >
> > Thanks.
> >
> >
> > --- In amibroker@yahoogroups.com, Tomasz Janeczkowrote:
> >>  Hello,
> >>
> >> The value of bo.Equity is correct.
> >>
> >> And your findings are incorrect.
> >> "Use previous bar equity" works as described in the manual.
> >>
> >> You are making mistake in your thinking/debugging.
> >> Your formula is checking bo.Equity BEFORE calling 
> >> ProcessTradeSignals(). And it is giving you last known
> >> equity value. That is the reason of your incorrect findings.
> >>
> >> If you are using custom backtester interface, there are clearly 
> >

Re: [amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread Tomasz Janeczko
  Hello,

One more thing to add: as an alternative to going low-level, you could iterate 
through open positions list on your own
(GetFirstOpenPos/GetNextOpenPos) get number of shares (Shares property) and 
multiply by Close price (trade object has GetPrice(bar, "C") method for that), 
then 
add to bo.Cash and you get the closing equity value that way, without need to 
call UpdateStats

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-16 19:17, Tomasz Janeczko wrote:
>  Hello,
>
> Generally speaking  you should be using low-level backtest for that.
> Guessing from your rather short descriptions, I think that you are trying to 
> override normal spsPercentOfEquity
> position size processing and use your own.
>
> The example codes for using low-level interface are included at the end of 
> this article:
> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
>
> ProcessTradeSignals not only processes signals but also does what 
> UpdateStats() is doing therefore
> you should not mix both since exposure will be counted twice.
>
> Using low-level mode avoids that.
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
>
> On 2010-07-16 18:56, rise_t575 wrote:
>>
>> One last question for clarification:
>>
>> 1) On one hand, I have to call bo.ProcessTradeSignals() for updating equity.
>> 2) On the other hand, I have to calculate position sizes *before* calling 
>> bo.ProcessTradeSignals().
>> 3) But for calculating the correct position sizes, my position sizing code 
>> has to have access to the updated equity.
>>
>> So using UpdateStats() in this case is *mandatory*, correct?
>>
>> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>>>Hello,
>>>
>>> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
>>> TimeInsideBar = 2
>>> two things in addition to updating equity happen:
>>> a) interest earnings are added (from free cash)
>>> b) position exposure and portfolio stats are calculated
>>>
>>> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) 
>>> more than once per bar.
>>>
>>> One thing you should think of:  be aware that if you are using current bar 
>>> closing equity for
>>> position sizing, you are generating possible future data leak.
>>> How is that so? It is easy - assume that your position sizing depends on 
>>> current equity,
>>> you can calculate bar's open equity and open position equal to the 
>>> difference between
>>> open equity and close equity of the same bar. And you generate single bar 
>>> trade.
>>> This way you have the system that has 100% winning trades, because it is 
>>> using future leak in
>>> position sizing.
>>> That is the reason AmiBroker DOES NOT use close equity of current bar for 
>>> position sizing.
>>> It either uses previous bar close equity or equity value at the open.
>>>
>>> Best regards,
>>> Tomasz Janeczko
>>> amibroker.com
>>>
>>> On 2010-07-16 15:29, rise_t575 wrote:
 I see - thanks.

 Actually I would like to use equity calculated from closing prices of the 
 current bar (by searching the web, I've found that normally, AB calculates 
 equity 
 for position sizing with opening prices of the current bar - and not being 
 aware of this has caused me some major headaches the last couple of days. 
 Is 
 this mentioned in the position sizing related sections of the manual? If 
 not, this information should be added). Reading the description of 
 UpdateStats(), 
 it seems like I could achieve this by setting the second (TimInsideBar) 
 parameter to "2". When I put "bo.UpdateStats( bar, 2 );" into my code, at 
 least the 
 position sizes are calculated exactly the way I want them to.
 But there are several warnings about doing this in the method's 
 description. Can I unintentionally mess something up by doing this?

 Thanks.

 --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
> Hello,
>
> Sorry, the method name is actually UpdateStats()
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
>
> On 2010-07-16 14:06, rise_t575 wrote:
>> Probably I'm blind, but I cannot find any information about the 
>> mentioned UpdateEquity() function, any searches in the online/offline 
>> manual result 
>> nothing. Could someone provide me with a link?
>>
>> Thanks.
>>
>>
>> --- In amibroker@yahoogroups.com, Tomasz Janeczkowrote:
>>>  Hello,
>>>
>>> The value of bo.Equity is correct.
>>>
>>> And your findings are incorrect.
>>> "Use previous bar equity" works as described in the manual.
>>>
>>> You are making mistake in your thinking/debugging.
>>> Your formula is checking bo.Equity BEFORE calling 
>>> ProcessTradeSignals(). And it is giving you last known
>>> equity value. That is the reason of your incorrect findings.
>>>
>>> If you are using custom backtester interface, t

Re: [amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread Tomasz Janeczko
  Hello,

Generally speaking  you should be using low-level backtest for that.
Guessing from your rather short descriptions, I think that you are trying to 
override normal spsPercentOfEquity
position size processing and use your own.

The example codes for using low-level interface are included at the end of this 
article:
http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/

ProcessTradeSignals not only processes signals but also does what UpdateStats() 
is doing therefore
you should not mix both since exposure will be counted twice.

Using low-level mode avoids that.

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-16 18:56, rise_t575 wrote:
>
> One last question for clarification:
>
> 1) On one hand, I have to call bo.ProcessTradeSignals() for updating equity.
> 2) On the other hand, I have to calculate position sizes *before* calling 
> bo.ProcessTradeSignals().
> 3) But for calculating the correct position sizes, my position sizing code 
> has to have access to the updated equity.
>
> So using UpdateStats() in this case is *mandatory*, correct?
>
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>>Hello,
>>
>> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
>> TimeInsideBar = 2
>> two things in addition to updating equity happen:
>> a) interest earnings are added (from free cash)
>> b) position exposure and portfolio stats are calculated
>>
>> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) 
>> more than once per bar.
>>
>> One thing you should think of:  be aware that if you are using current bar 
>> closing equity for
>> position sizing, you are generating possible future data leak.
>> How is that so? It is easy - assume that your position sizing depends on 
>> current equity,
>> you can calculate bar's open equity and open position equal to the 
>> difference between
>> open equity and close equity of the same bar. And you generate single bar 
>> trade.
>> This way you have the system that has 100% winning trades, because it is 
>> using future leak in
>> position sizing.
>> That is the reason AmiBroker DOES NOT use close equity of current bar for 
>> position sizing.
>> It either uses previous bar close equity or equity value at the open.
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>>
>> On 2010-07-16 15:29, rise_t575 wrote:
>>> I see - thanks.
>>>
>>> Actually I would like to use equity calculated from closing prices of the 
>>> current bar (by searching the web, I've found that normally, AB calculates 
>>> equity for position sizing with opening prices of the current bar - and not 
>>> being aware of this has caused me some major headaches the last couple of 
>>> days. Is this mentioned in the position sizing related sections of the 
>>> manual? If not, this information should be added). Reading the description 
>>> of UpdateStats(), it seems like I could achieve this by setting the second 
>>> (TimInsideBar) parameter to "2". When I put "bo.UpdateStats( bar, 2 );" 
>>> into my code, at least the position sizes are calculated exactly the way I 
>>> want them to.
>>> But there are several warnings about doing this in the method's 
>>> description. Can I unintentionally mess something up by doing this?
>>>
>>> Thanks.
>>>
>>> --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
 Hello,

 Sorry, the method name is actually UpdateStats()

 Best regards,
 Tomasz Janeczko
 amibroker.com

 On 2010-07-16 14:06, rise_t575 wrote:
> Probably I'm blind, but I cannot find any information about the mentioned 
> UpdateEquity() function, any searches in the online/offline manual result 
> nothing. Could someone provide me with a link?
>
> Thanks.
>
>
> --- In amibroker@yahoogroups.com, Tomasz Janeczkowrote:
>>  Hello,
>>
>> The value of bo.Equity is correct.
>>
>> And your findings are incorrect.
>> "Use previous bar equity" works as described in the manual.
>>
>> You are making mistake in your thinking/debugging.
>> Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). 
>> And it is giving you last known
>> equity value. That is the reason of your incorrect findings.
>>
>> If you are using custom backtester interface, there are clearly defined 
>> points where *you* are in charge
>> and when AB is in charge (and can update anything). It will NOT do any 
>> "magical steps" out of blue right after
>> for( bar = 0; bar> equity to the current bar you either
>> must call ProcessTradeSignals()   (it will update equity and process 
>> signals) OR... if you want to have
>> current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
>> UpdateEquity( bar, 0 ) function.
>>
>> The difference that "Use previous bar equity" makes in case of CBT i

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


One last question for clarification:

1) On one hand, I have to call bo.ProcessTradeSignals() for updating equity.
2) On the other hand, I have to calculate position sizes *before* calling 
bo.ProcessTradeSignals().
3) But for calculating the correct position sizes, my position sizing code has 
to have access to the updated equity.

So using UpdateStats() in this case is *mandatory*, correct?

--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
> TimeInsideBar = 2
> two things in addition to updating equity happen:
> a) interest earnings are added (from free cash)
> b) position exposure and portfolio stats are calculated
> 
> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) more 
> than once per bar.
> 
> One thing you should think of:  be aware that if you are using current bar 
> closing equity for
> position sizing, you are generating possible future data leak.
> How is that so? It is easy - assume that your position sizing depends on 
> current equity,
> you can calculate bar's open equity and open position equal to the difference 
> between
> open equity and close equity of the same bar. And you generate single bar 
> trade.
> This way you have the system that has 100% winning trades, because it is 
> using future leak in
> position sizing.
> That is the reason AmiBroker DOES NOT use close equity of current bar for 
> position sizing.
> It either uses previous bar close equity or equity value at the open.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-16 15:29, rise_t575 wrote:
> >
> > I see - thanks.
> >
> > Actually I would like to use equity calculated from closing prices of the 
> > current bar (by searching the web, I've found that normally, AB calculates 
> > equity for position sizing with opening prices of the current bar - and not 
> > being aware of this has caused me some major headaches the last couple of 
> > days. Is this mentioned in the position sizing related sections of the 
> > manual? If not, this information should be added). Reading the description 
> > of UpdateStats(), it seems like I could achieve this by setting the second 
> > (TimInsideBar) parameter to "2". When I put "bo.UpdateStats( bar, 2 );" 
> > into my code, at least the position sizes are calculated exactly the way I 
> > want them to.
> > But there are several warnings about doing this in the method's 
> > description. Can I unintentionally mess something up by doing this?
> >
> > Thanks.
> >
> > --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >>Hello,
> >>
> >> Sorry, the method name is actually UpdateStats()
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >>
> >> On 2010-07-16 14:06, rise_t575 wrote:
> >>> Probably I'm blind, but I cannot find any information about the mentioned 
> >>> UpdateEquity() function, any searches in the online/offline manual result 
> >>> nothing. Could someone provide me with a link?
> >>>
> >>> Thanks.
> >>>
> >>>
> >>> --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
>  Hello,
> 
>  The value of bo.Equity is correct.
> 
>  And your findings are incorrect.
>  "Use previous bar equity" works as described in the manual.
> 
>  You are making mistake in your thinking/debugging.
>  Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). 
>  And it is giving you last known
>  equity value. That is the reason of your incorrect findings.
> 
>  If you are using custom backtester interface, there are clearly defined 
>  points where *you* are in charge
>  and when AB is in charge (and can update anything). It will NOT do any 
>  "magical steps" out of blue right after
>  for( bar = 0; bar<   BarCount; bar++ ) loop. If you want to update 
>  equity to the current bar you either
>  must call ProcessTradeSignals()   (it will update equity and process 
>  signals) OR... if you want to have
>  current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
>  UpdateEquity( bar, 0 ) function.
> 
>  The difference that "Use previous bar equity" makes in case of CBT is 
>  that ***INSIDE*** ProcessTradeSignals()
>  it will use either previous bar or current bar equity, depending on 
>  setting, and it will affect the size
>  of position open (if you are using spsPercentOfEquity or otherwise 
>  depend on available equity)
> 
>  Recommended reading:
>  http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> 
> 
>  Best regards,
>  Tomasz Janeczko
>  amibroker.com
> 
>  On 2010-07-15 20:15, rise_t575 wrote:
> > Hi,
> >
> > I've just found out what is happening, but I have not the slightest 
> > idea why.
> >
> > The backtester is *always* using previous bar equity for positions 
> 

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


Tomasz,

Great explanation - thanks! In fact, you could add this explanation regarding 
TimeInsideBar to the UpdateStats() section of the AB manual as well. It's a 
great help in order to understand things better.

--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
> TimeInsideBar = 2
> two things in addition to updating equity happen:
> a) interest earnings are added (from free cash)
> b) position exposure and portfolio stats are calculated
> 
> You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) more 
> than once per bar.
> 
> One thing you should think of:  be aware that if you are using current bar 
> closing equity for
> position sizing, you are generating possible future data leak.
> How is that so? It is easy - assume that your position sizing depends on 
> current equity,
> you can calculate bar's open equity and open position equal to the difference 
> between
> open equity and close equity of the same bar. And you generate single bar 
> trade.
> This way you have the system that has 100% winning trades, because it is 
> using future leak in
> position sizing.
> That is the reason AmiBroker DOES NOT use close equity of current bar for 
> position sizing.
> It either uses previous bar close equity or equity value at the open.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-16 15:29, rise_t575 wrote:
> >
> > I see - thanks.
> >
> > Actually I would like to use equity calculated from closing prices of the 
> > current bar (by searching the web, I've found that normally, AB calculates 
> > equity for position sizing with opening prices of the current bar - and not 
> > being aware of this has caused me some major headaches the last couple of 
> > days. Is this mentioned in the position sizing related sections of the 
> > manual? If not, this information should be added). Reading the description 
> > of UpdateStats(), it seems like I could achieve this by setting the second 
> > (TimInsideBar) parameter to "2". When I put "bo.UpdateStats( bar, 2 );" 
> > into my code, at least the position sizes are calculated exactly the way I 
> > want them to.
> > But there are several warnings about doing this in the method's 
> > description. Can I unintentionally mess something up by doing this?
> >
> > Thanks.
> >
> > --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >>Hello,
> >>
> >> Sorry, the method name is actually UpdateStats()
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >>
> >> On 2010-07-16 14:06, rise_t575 wrote:
> >>> Probably I'm blind, but I cannot find any information about the mentioned 
> >>> UpdateEquity() function, any searches in the online/offline manual result 
> >>> nothing. Could someone provide me with a link?
> >>>
> >>> Thanks.
> >>>
> >>>
> >>> --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
>  Hello,
> 
>  The value of bo.Equity is correct.
> 
>  And your findings are incorrect.
>  "Use previous bar equity" works as described in the manual.
> 
>  You are making mistake in your thinking/debugging.
>  Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). 
>  And it is giving you last known
>  equity value. That is the reason of your incorrect findings.
> 
>  If you are using custom backtester interface, there are clearly defined 
>  points where *you* are in charge
>  and when AB is in charge (and can update anything). It will NOT do any 
>  "magical steps" out of blue right after
>  for( bar = 0; bar<   BarCount; bar++ ) loop. If you want to update 
>  equity to the current bar you either
>  must call ProcessTradeSignals()   (it will update equity and process 
>  signals) OR... if you want to have
>  current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
>  UpdateEquity( bar, 0 ) function.
> 
>  The difference that "Use previous bar equity" makes in case of CBT is 
>  that ***INSIDE*** ProcessTradeSignals()
>  it will use either previous bar or current bar equity, depending on 
>  setting, and it will affect the size
>  of position open (if you are using spsPercentOfEquity or otherwise 
>  depend on available equity)
> 
>  Recommended reading:
>  http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> 
> 
>  Best regards,
>  Tomasz Janeczko
>  amibroker.com
> 
>  On 2010-07-15 20:15, rise_t575 wrote:
> > Hi,
> >
> > I've just found out what is happening, but I have not the slightest 
> > idea why.
> >
> > The backtester is *always* using previous bar equity for positions 
> > sizing, although this setting is *not* ticked, and I haven't included 
> > the corresponding SetOption function.
> >
> > In fact, the backtests and the debugging lo

Re: [amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread Tomasz Janeczko
  Hello,

You can call UpdateStats( bar, 2 ) but please call it once per bar. When 
TimeInsideBar = 2
two things in addition to updating equity happen:
a) interest earnings are added (from free cash)
b) position exposure and portfolio stats are calculated

You can get incorrect exposure figures if you call UpdateStats( bar, 2 ) more 
than once per bar.

One thing you should think of:  be aware that if you are using current bar 
closing equity for
position sizing, you are generating possible future data leak.
How is that so? It is easy - assume that your position sizing depends on 
current equity,
you can calculate bar's open equity and open position equal to the difference 
between
open equity and close equity of the same bar. And you generate single bar trade.
This way you have the system that has 100% winning trades, because it is using 
future leak in
position sizing.
That is the reason AmiBroker DOES NOT use close equity of current bar for 
position sizing.
It either uses previous bar close equity or equity value at the open.

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-16 15:29, rise_t575 wrote:
>
> I see - thanks.
>
> Actually I would like to use equity calculated from closing prices of the 
> current bar (by searching the web, I've found that normally, AB calculates 
> equity for position sizing with opening prices of the current bar - and not 
> being aware of this has caused me some major headaches the last couple of 
> days. Is this mentioned in the position sizing related sections of the 
> manual? If not, this information should be added). Reading the description of 
> UpdateStats(), it seems like I could achieve this by setting the second 
> (TimInsideBar) parameter to "2". When I put "bo.UpdateStats( bar, 2 );" into 
> my code, at least the position sizes are calculated exactly the way I want 
> them to.
> But there are several warnings about doing this in the method's description. 
> Can I unintentionally mess something up by doing this?
>
> Thanks.
>
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>>Hello,
>>
>> Sorry, the method name is actually UpdateStats()
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>>
>> On 2010-07-16 14:06, rise_t575 wrote:
>>> Probably I'm blind, but I cannot find any information about the mentioned 
>>> UpdateEquity() function, any searches in the online/offline manual result 
>>> nothing. Could someone provide me with a link?
>>>
>>> Thanks.
>>>
>>>
>>> --- In amibroker@yahoogroups.com, Tomasz Janeczko   wrote:
 Hello,

 The value of bo.Equity is correct.

 And your findings are incorrect.
 "Use previous bar equity" works as described in the manual.

 You are making mistake in your thinking/debugging.
 Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). 
 And it is giving you last known
 equity value. That is the reason of your incorrect findings.

 If you are using custom backtester interface, there are clearly defined 
 points where *you* are in charge
 and when AB is in charge (and can update anything). It will NOT do any 
 "magical steps" out of blue right after
 for( bar = 0; bar<   BarCount; bar++ ) loop. If you want to update equity 
 to the current bar you either
 must call ProcessTradeSignals()   (it will update equity and process 
 signals) OR... if you want to have
 current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
 UpdateEquity( bar, 0 ) function.

 The difference that "Use previous bar equity" makes in case of CBT is that 
 ***INSIDE*** ProcessTradeSignals()
 it will use either previous bar or current bar equity, depending on 
 setting, and it will affect the size
 of position open (if you are using spsPercentOfEquity or otherwise depend 
 on available equity)

 Recommended reading:
 http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/


 Best regards,
 Tomasz Janeczko
 amibroker.com

 On 2010-07-15 20:15, rise_t575 wrote:
> Hi,
>
> I've just found out what is happening, but I have not the slightest idea 
> why.
>
> The backtester is *always* using previous bar equity for positions 
> sizing, although this setting is *not* ticked, and I haven't included the 
> corresponding SetOption function.
>
> In fact, the backtests and the debugging logs are exactly identical when 
> UsePrevBarEquityForPosSizing is True and when it is False.
>
> Is this some bug or isn't that setting being used when using CBT for 
> position sizing?
>
> Thanks in advance!
>
> --- In amibroker@yahoogroups.com, "rise_t575"wrote:
>> Hello,
>>
>> The following are the (debug) outputs of a tested position sizing 
>> algorithm.
>>
>> I've attached a) part of the code , b) the output of the _TRACE() 
>> function fr

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


I see - thanks.

Actually I would like to use equity calculated from closing prices of the 
current bar (by searching the web, I've found that normally, AB calculates 
equity for position sizing with opening prices of the current bar - and not 
being aware of this has caused me some major headaches the last couple of days. 
Is this mentioned in the position sizing related sections of the manual? If 
not, this information should be added). Reading the description of 
UpdateStats(), it seems like I could achieve this by setting the second 
(TimInsideBar) parameter to "2". When I put "bo.UpdateStats( bar, 2 );" into my 
code, at least the position sizes are calculated exactly the way I want them to.
But there are several warnings about doing this in the method's description. 
Can I unintentionally mess something up by doing this?
 
Thanks.

--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> Sorry, the method name is actually UpdateStats()
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-16 14:06, rise_t575 wrote:
> >
> > Probably I'm blind, but I cannot find any information about the mentioned 
> > UpdateEquity() function, any searches in the online/offline manual result 
> > nothing. Could someone provide me with a link?
> >
> > Thanks.
> >
> >
> > --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >>Hello,
> >>
> >> The value of bo.Equity is correct.
> >>
> >> And your findings are incorrect.
> >> "Use previous bar equity" works as described in the manual.
> >>
> >> You are making mistake in your thinking/debugging.
> >> Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). 
> >> And it is giving you last known
> >> equity value. That is the reason of your incorrect findings.
> >>
> >> If you are using custom backtester interface, there are clearly defined 
> >> points where *you* are in charge
> >> and when AB is in charge (and can update anything). It will NOT do any 
> >> "magical steps" out of blue right after
> >> for( bar = 0; bar<  BarCount; bar++ ) loop. If you want to update equity 
> >> to the current bar you either
> >> must call ProcessTradeSignals()   (it will update equity and process 
> >> signals) OR... if you want to have
> >> current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
> >> UpdateEquity( bar, 0 ) function.
> >>
> >> The difference that "Use previous bar equity" makes in case of CBT is that 
> >> ***INSIDE*** ProcessTradeSignals()
> >> it will use either previous bar or current bar equity, depending on 
> >> setting, and it will affect the size
> >> of position open (if you are using spsPercentOfEquity or otherwise depend 
> >> on available equity)
> >>
> >> Recommended reading:
> >> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> >>
> >>
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >>
> >> On 2010-07-15 20:15, rise_t575 wrote:
> >>> Hi,
> >>>
> >>> I've just found out what is happening, but I have not the slightest idea 
> >>> why.
> >>>
> >>> The backtester is *always* using previous bar equity for positions 
> >>> sizing, although this setting is *not* ticked, and I haven't included the 
> >>> corresponding SetOption function.
> >>>
> >>> In fact, the backtests and the debugging logs are exactly identical when 
> >>> UsePrevBarEquityForPosSizing is True and when it is False.
> >>>
> >>> Is this some bug or isn't that setting being used when using CBT for 
> >>> position sizing?
> >>>
> >>> Thanks in advance!
> >>>
> >>> --- In amibroker@yahoogroups.com, "rise_t575"   wrote:
>  Hello,
> 
>  The following are the (debug) outputs of a tested position sizing 
>  algorithm.
> 
>  I've attached a) part of the code , b) the output of the _TRACE() 
>  function from within the CBT code (the TRACE function had been placed 
>  within the most inner "if{}" code block), and c) the output of the AA 
>  Results window (Detailed Log).
> 
>  Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is 
>  still at its intial value (10), so it hasn't been adjusted for price 
>  changes of the position taken at the close of day 1 (which did exist).
> 
>  Since this equity value is used for calculation of the position size of 
>  subsequent signals, this is a problem.
> 
>  On the other hand, the output of the AA Results windows on day 2 is 
>  correct (99823.2)
> 
>  And - no - "Use previous bar equity for position sizing" is not 
>  activated.
> 
>  Does anyone have an idea why bo.equity delivers incorrect values in this 
>  case?
> 
>  Thanks in advance!
> 
>  Part of CBT code in question:
> 
>    for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
>  bo.GetNextSignal( bar ) )
>    {
>    if ( sig.IsEntry() )
>    {
>    

Re: [amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread Tomasz Janeczko
  Hello,

Sorry, the method name is actually UpdateStats()

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-16 14:06, rise_t575 wrote:
>
> Probably I'm blind, but I cannot find any information about the mentioned 
> UpdateEquity() function, any searches in the online/offline manual result 
> nothing. Could someone provide me with a link?
>
> Thanks.
>
>
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>>Hello,
>>
>> The value of bo.Equity is correct.
>>
>> And your findings are incorrect.
>> "Use previous bar equity" works as described in the manual.
>>
>> You are making mistake in your thinking/debugging.
>> Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). And 
>> it is giving you last known
>> equity value. That is the reason of your incorrect findings.
>>
>> If you are using custom backtester interface, there are clearly defined 
>> points where *you* are in charge
>> and when AB is in charge (and can update anything). It will NOT do any 
>> "magical steps" out of blue right after
>> for( bar = 0; bar<  BarCount; bar++ ) loop. If you want to update equity to 
>> the current bar you either
>> must call ProcessTradeSignals()   (it will update equity and process 
>> signals) OR... if you want to have
>> current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
>> UpdateEquity( bar, 0 ) function.
>>
>> The difference that "Use previous bar equity" makes in case of CBT is that 
>> ***INSIDE*** ProcessTradeSignals()
>> it will use either previous bar or current bar equity, depending on setting, 
>> and it will affect the size
>> of position open (if you are using spsPercentOfEquity or otherwise depend on 
>> available equity)
>>
>> Recommended reading:
>> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
>>
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>>
>> On 2010-07-15 20:15, rise_t575 wrote:
>>> Hi,
>>>
>>> I've just found out what is happening, but I have not the slightest idea 
>>> why.
>>>
>>> The backtester is *always* using previous bar equity for positions sizing, 
>>> although this setting is *not* ticked, and I haven't included the 
>>> corresponding SetOption function.
>>>
>>> In fact, the backtests and the debugging logs are exactly identical when 
>>> UsePrevBarEquityForPosSizing is True and when it is False.
>>>
>>> Is this some bug or isn't that setting being used when using CBT for 
>>> position sizing?
>>>
>>> Thanks in advance!
>>>
>>> --- In amibroker@yahoogroups.com, "rise_t575"   wrote:
 Hello,

 The following are the (debug) outputs of a tested position sizing 
 algorithm.

 I've attached a) part of the code , b) the output of the _TRACE() function 
 from within the CBT code (the TRACE function had been placed within the 
 most inner "if{}" code block), and c) the output of the AA Results window 
 (Detailed Log).

 Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is 
 still at its intial value (10), so it hasn't been adjusted for price 
 changes of the position taken at the close of day 1 (which did exist).

 Since this equity value is used for calculation of the position size of 
 subsequent signals, this is a problem.

 On the other hand, the output of the AA Results windows on day 2 is 
 correct (99823.2)

 And - no - "Use previous bar equity for position sizing" is not activated.

 Does anyone have an idea why bo.equity delivers incorrect values in this 
 case?

 Thanks in advance!

 Part of CBT code in question:

   for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
 bo.GetNextSignal( bar ) )
   {
   if ( sig.IsEntry() )
   {
   currEquity = bo.Equity;
   pointVal = sig.PointValue;
   cbtAtr = StaticVarGet( "statAtr" + sig.Symbol );
   psUnits = int( currEquity * ( pctVolaRisk / 100 
 ) / ( cbtAtr[bar] * pointVal ) );
[_TRACE]
   sig.PosSize = ( 2000 + psUnits ) * -1;
   }
   }



 DebugView Output:
 [2856] Date: 20.01.2000 Symbol: FDRY Equity: 10 Cash: 10 ATR: 
 14.383258 Units: 69
 [2856] Date: 21.01.2000 Symbol: PCLN Equity: 10 Cash: 89818.2 ATR: 
 27.671930 Units: 36
 [2856] Date: 21.01.2000 Symbol: TYC Equity: 10 Cash: 89818.2 ATR: 
 14.318740 Units: 69
 [2856] Date: 25.01.2000 Symbol: AKAM Equity: 98382.8 Cash: 59163.1 ATR: 
 27.247997 Units: 36
 [2856] Date: 03.02.2000 Symbol: IBM Equity: 97308.7 Cash: 49107.9 ATR: 
 4.628230 Units: 210
 [2856] Date: 04.02.2000 Symbol: FDRY Equity: 97846.4 Cash: 42716.2 ATR: 
 13.667122 Units:

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


Probably I'm blind, but I cannot find any information about the mentioned 
UpdateEquity() function, any searches in the online/offline manual result 
nothing. Could someone provide me with a link?

Thanks.


--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> The value of bo.Equity is correct.
> 
> And your findings are incorrect.
> "Use previous bar equity" works as described in the manual.
> 
> You are making mistake in your thinking/debugging.
> Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). And 
> it is giving you last known
> equity value. That is the reason of your incorrect findings.
> 
> If you are using custom backtester interface, there are clearly defined 
> points where *you* are in charge
> and when AB is in charge (and can update anything). It will NOT do any 
> "magical steps" out of blue right after
> for( bar = 0; bar < BarCount; bar++ ) loop. If you want to update equity to 
> the current bar you either
> must call ProcessTradeSignals()   (it will update equity and process signals) 
> OR... if you want to have
> current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
> UpdateEquity( bar, 0 ) function.
> 
> The difference that "Use previous bar equity" makes in case of CBT is that 
> ***INSIDE*** ProcessTradeSignals()
> it will use either previous bar or current bar equity, depending on setting, 
> and it will affect the size
> of position open (if you are using spsPercentOfEquity or otherwise depend on 
> available equity)
> 
> Recommended reading:
> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> 
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-15 20:15, rise_t575 wrote:
> >
> > Hi,
> >
> > I've just found out what is happening, but I have not the slightest idea 
> > why.
> >
> > The backtester is *always* using previous bar equity for positions sizing, 
> > although this setting is *not* ticked, and I haven't included the 
> > corresponding SetOption function.
> >
> > In fact, the backtests and the debugging logs are exactly identical when 
> > UsePrevBarEquityForPosSizing is True and when it is False.
> >
> > Is this some bug or isn't that setting being used when using CBT for 
> > position sizing?
> >
> > Thanks in advance!
> >
> > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> >> Hello,
> >>
> >> The following are the (debug) outputs of a tested position sizing 
> >> algorithm.
> >>
> >> I've attached a) part of the code , b) the output of the _TRACE() function 
> >> from within the CBT code (the TRACE function had been placed within the 
> >> most inner "if{}" code block), and c) the output of the AA Results window 
> >> (Detailed Log).
> >>
> >> Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is 
> >> still at its intial value (10), so it hasn't been adjusted for price 
> >> changes of the position taken at the close of day 1 (which did exist).
> >>
> >> Since this equity value is used for calculation of the position size of 
> >> subsequent signals, this is a problem.
> >>
> >> On the other hand, the output of the AA Results windows on day 2 is 
> >> correct (99823.2)
> >>
> >> And - no - "Use previous bar equity for position sizing" is not activated.
> >>
> >> Does anyone have an idea why bo.equity delivers incorrect values in this 
> >> case?
> >>
> >> Thanks in advance!
> >>
> >> Part of CBT code in question:
> >>
> >>  for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
> >> bo.GetNextSignal( bar ) )
> >>  {
> >>  if ( sig.IsEntry() )
> >>  {
> >>  currEquity = bo.Equity;
> >>  pointVal = sig.PointValue;
> >>  cbtAtr = StaticVarGet( "statAtr" + sig.Symbol );
> >>  psUnits = int( currEquity * ( pctVolaRisk / 100 ) 
> >> / ( cbtAtr[bar] * pointVal ) );
> >>[_TRACE]
> >>  sig.PosSize = ( 2000 + psUnits ) * -1;
> >>  }
> >>  }
> >>
> >>
> >>
> >> DebugView Output:
> >> [2856] Date: 20.01.2000 Symbol: FDRY Equity: 10 Cash: 10 ATR: 
> >> 14.383258 Units: 69
> >> [2856] Date: 21.01.2000 Symbol: PCLN Equity: 10 Cash: 89818.2 ATR: 
> >> 27.671930 Units: 36
> >> [2856] Date: 21.01.2000 Symbol: TYC Equity: 10 Cash: 89818.2 ATR: 
> >> 14.318740 Units: 69
> >> [2856] Date: 25.01.2000 Symbol: AKAM Equity: 98382.8 Cash: 59163.1 ATR: 
> >> 27.247997 Units: 36
> >> [2856] Date: 03.02.2000 Symbol: IBM Equity: 97308.7 Cash: 49107.9 ATR: 
> >> 4.628230 Units: 210
> >> [2856] Date: 04.02.2000 Symbol: FDRY Equity: 97846.4 Cash: 42716.2 ATR: 
> >> 13.667122 Units: 71
> >>
> >>
> >> AA Results Output:
> >> 20.01.2000
> >>Entry signals(score):FDRY=Buy(1),
> >>Exit signals:
> >>Enter Long, FDRY, Price: 147.563, Shares: 69, Commission: 0, Rank: 

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


Btw - could you (or someone else) tell me where these equity values within the 
AA Results list (Detailed Log) are derived from that are stated after e. g. 
"ENTER LONG,..." lines?

Thanks.

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> 
> 
> Tomasz,
> 
> Thanks for this info - I'll definitely check it out.
> 
> I think a lot of such problems originate from a lack of *complete* 
> understanding how CBT (or a complete backtest for that matter) *internally* 
> works, i. e. what AB is processing and when, in which order, where exactly 
> does CBT code come in, etc.
> 
> Of course, you as AB's developer are aware of all of these things (how all of 
> the functionality is interrelated), as well as those who have been using AB 
> for a rather long time.
> But for someone quite new to AB, this can be pretty hard in the beginning - 
> even after reading all of the CBT related info spread out in the manual. E. 
> g., I have read all of the corresponding sections of the manual (and then 
> some), but have obviously missed the article you mentioned in AB's User's 
> Knowledge Base.
> 
> --- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
> >
> >   Hello,
> > 
> > The value of bo.Equity is correct.
> > 
> > And your findings are incorrect.
> > "Use previous bar equity" works as described in the manual.
> > 
> > You are making mistake in your thinking/debugging.
> > Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). 
> > And it is giving you last known
> > equity value. That is the reason of your incorrect findings.
> > 
> > If you are using custom backtester interface, there are clearly defined 
> > points where *you* are in charge
> > and when AB is in charge (and can update anything). It will NOT do any 
> > "magical steps" out of blue right after
> > for( bar = 0; bar < BarCount; bar++ ) loop. If you want to update equity to 
> > the current bar you either
> > must call ProcessTradeSignals()   (it will update equity and process 
> > signals) OR... if you want to have
> > current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
> > UpdateEquity( bar, 0 ) function.
> > 
> > The difference that "Use previous bar equity" makes in case of CBT is that 
> > ***INSIDE*** ProcessTradeSignals()
> > it will use either previous bar or current bar equity, depending on 
> > setting, and it will affect the size
> > of position open (if you are using spsPercentOfEquity or otherwise depend 
> > on available equity)
> > 
> > Recommended reading:
> > http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> > 
> > 
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > 
> > On 2010-07-15 20:15, rise_t575 wrote:
> > >
> > > Hi,
> > >
> > > I've just found out what is happening, but I have not the slightest idea 
> > > why.
> > >
> > > The backtester is *always* using previous bar equity for positions 
> > > sizing, although this setting is *not* ticked, and I haven't included the 
> > > corresponding SetOption function.
> > >
> > > In fact, the backtests and the debugging logs are exactly identical when 
> > > UsePrevBarEquityForPosSizing is True and when it is False.
> > >
> > > Is this some bug or isn't that setting being used when using CBT for 
> > > position sizing?
> > >
> > > Thanks in advance!
> > >
> > > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> > >> Hello,
> > >>
> > >> The following are the (debug) outputs of a tested position sizing 
> > >> algorithm.
> > >>
> > >> I've attached a) part of the code , b) the output of the _TRACE() 
> > >> function from within the CBT code (the TRACE function had been placed 
> > >> within the most inner "if{}" code block), and c) the output of the AA 
> > >> Results window (Detailed Log).
> > >>
> > >> Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is 
> > >> still at its intial value (10), so it hasn't been adjusted for price 
> > >> changes of the position taken at the close of day 1 (which did exist).
> > >>
> > >> Since this equity value is used for calculation of the position size of 
> > >> subsequent signals, this is a problem.
> > >>
> > >> On the other hand, the output of the AA Results windows on day 2 is 
> > >> correct (99823.2)
> > >>
> > >> And - no - "Use previous bar equity for position sizing" is not 
> > >> activated.
> > >>
> > >> Does anyone have an idea why bo.equity delivers incorrect values in this 
> > >> case?
> > >>
> > >> Thanks in advance!
> > >>
> > >> Part of CBT code in question:
> > >>
> > >>  for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
> > >> bo.GetNextSignal( bar ) )
> > >>  {
> > >>  if ( sig.IsEntry() )
> > >>  {
> > >>  currEquity = bo.Equity;
> > >>  pointVal = sig.PointValue;
> > >>  cbtAtr = StaticVarGet( "statAtr" + sig.Symbol );
> > >>  psUnits = int(

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread rise_t575


Tomasz,

Thanks for this info - I'll definitely check it out.

I think a lot of such problems originate from a lack of *complete* 
understanding how CBT (or a complete backtest for that matter) *internally* 
works, i. e. what AB is processing and when, in which order, where exactly does 
CBT code come in, etc.

Of course, you as AB's developer are aware of all of these things (how all of 
the functionality is interrelated), as well as those who have been using AB for 
a rather long time.
But for someone quite new to AB, this can be pretty hard in the beginning - 
even after reading all of the CBT related info spread out in the manual. E. g., 
I have read all of the corresponding sections of the manual (and then some), 
but have obviously missed the article you mentioned in AB's User's Knowledge 
Base.

--- In amibroker@yahoogroups.com, Tomasz Janeczko  wrote:
>
>   Hello,
> 
> The value of bo.Equity is correct.
> 
> And your findings are incorrect.
> "Use previous bar equity" works as described in the manual.
> 
> You are making mistake in your thinking/debugging.
> Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). And 
> it is giving you last known
> equity value. That is the reason of your incorrect findings.
> 
> If you are using custom backtester interface, there are clearly defined 
> points where *you* are in charge
> and when AB is in charge (and can update anything). It will NOT do any 
> "magical steps" out of blue right after
> for( bar = 0; bar < BarCount; bar++ ) loop. If you want to update equity to 
> the current bar you either
> must call ProcessTradeSignals()   (it will update equity and process signals) 
> OR... if you want to have
> current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
> UpdateEquity( bar, 0 ) function.
> 
> The difference that "Use previous bar equity" makes in case of CBT is that 
> ***INSIDE*** ProcessTradeSignals()
> it will use either previous bar or current bar equity, depending on setting, 
> and it will affect the size
> of position open (if you are using spsPercentOfEquity or otherwise depend on 
> available equity)
> 
> Recommended reading:
> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
> 
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> 
> On 2010-07-15 20:15, rise_t575 wrote:
> >
> > Hi,
> >
> > I've just found out what is happening, but I have not the slightest idea 
> > why.
> >
> > The backtester is *always* using previous bar equity for positions sizing, 
> > although this setting is *not* ticked, and I haven't included the 
> > corresponding SetOption function.
> >
> > In fact, the backtests and the debugging logs are exactly identical when 
> > UsePrevBarEquityForPosSizing is True and when it is False.
> >
> > Is this some bug or isn't that setting being used when using CBT for 
> > position sizing?
> >
> > Thanks in advance!
> >
> > --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
> >> Hello,
> >>
> >> The following are the (debug) outputs of a tested position sizing 
> >> algorithm.
> >>
> >> I've attached a) part of the code , b) the output of the _TRACE() function 
> >> from within the CBT code (the TRACE function had been placed within the 
> >> most inner "if{}" code block), and c) the output of the AA Results window 
> >> (Detailed Log).
> >>
> >> Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is 
> >> still at its intial value (10), so it hasn't been adjusted for price 
> >> changes of the position taken at the close of day 1 (which did exist).
> >>
> >> Since this equity value is used for calculation of the position size of 
> >> subsequent signals, this is a problem.
> >>
> >> On the other hand, the output of the AA Results windows on day 2 is 
> >> correct (99823.2)
> >>
> >> And - no - "Use previous bar equity for position sizing" is not activated.
> >>
> >> Does anyone have an idea why bo.equity delivers incorrect values in this 
> >> case?
> >>
> >> Thanks in advance!
> >>
> >> Part of CBT code in question:
> >>
> >>  for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
> >> bo.GetNextSignal( bar ) )
> >>  {
> >>  if ( sig.IsEntry() )
> >>  {
> >>  currEquity = bo.Equity;
> >>  pointVal = sig.PointValue;
> >>  cbtAtr = StaticVarGet( "statAtr" + sig.Symbol );
> >>  psUnits = int( currEquity * ( pctVolaRisk / 100 ) 
> >> / ( cbtAtr[bar] * pointVal ) );
> >>[_TRACE]
> >>  sig.PosSize = ( 2000 + psUnits ) * -1;
> >>  }
> >>  }
> >>
> >>
> >>
> >> DebugView Output:
> >> [2856] Date: 20.01.2000 Symbol: FDRY Equity: 10 Cash: 10 ATR: 
> >> 14.383258 Units: 69
> >> [2856] Date: 21.01.2000 Symbol: PCLN Equity: 10 Cash: 89818.2 ATR: 
> >> 27.671930 Un

Re: [amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-16 Thread Tomasz Janeczko
  Hello,

The value of bo.Equity is correct.

And your findings are incorrect.
"Use previous bar equity" works as described in the manual.

You are making mistake in your thinking/debugging.
Your formula is checking bo.Equity BEFORE calling ProcessTradeSignals(). And it 
is giving you last known
equity value. That is the reason of your incorrect findings.

If you are using custom backtester interface, there are clearly defined points 
where *you* are in charge
and when AB is in charge (and can update anything). It will NOT do any "magical 
steps" out of blue right after
for( bar = 0; bar < BarCount; bar++ ) loop. If you want to update equity to the 
current bar you either
must call ProcessTradeSignals()   (it will update equity and process signals) 
OR... if you want to have
current bar equity WITHOUT calling ProcessTradeSignals, you have to call 
UpdateEquity( bar, 0 ) function.

The difference that "Use previous bar equity" makes in case of CBT is that 
***INSIDE*** ProcessTradeSignals()
it will use either previous bar or current bar equity, depending on setting, 
and it will affect the size
of position open (if you are using spsPercentOfEquity or otherwise depend on 
available equity)

Recommended reading:
http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/


Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-15 20:15, rise_t575 wrote:
>
> Hi,
>
> I've just found out what is happening, but I have not the slightest idea why.
>
> The backtester is *always* using previous bar equity for positions sizing, 
> although this setting is *not* ticked, and I haven't included the 
> corresponding SetOption function.
>
> In fact, the backtests and the debugging logs are exactly identical when 
> UsePrevBarEquityForPosSizing is True and when it is False.
>
> Is this some bug or isn't that setting being used when using CBT for position 
> sizing?
>
> Thanks in advance!
>
> --- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>> Hello,
>>
>> The following are the (debug) outputs of a tested position sizing algorithm.
>>
>> I've attached a) part of the code , b) the output of the _TRACE() function 
>> from within the CBT code (the TRACE function had been placed within the most 
>> inner "if{}" code block), and c) the output of the AA Results window 
>> (Detailed Log).
>>
>> Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is still 
>> at its intial value (10), so it hasn't been adjusted for price changes 
>> of the position taken at the close of day 1 (which did exist).
>>
>> Since this equity value is used for calculation of the position size of 
>> subsequent signals, this is a problem.
>>
>> On the other hand, the output of the AA Results windows on day 2 is correct 
>> (99823.2)
>>
>> And - no - "Use previous bar equity for position sizing" is not activated.
>>
>> Does anyone have an idea why bo.equity delivers incorrect values in this 
>> case?
>>
>> Thanks in advance!
>>
>> Part of CBT code in question:
>>
>>  for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
>> bo.GetNextSignal( bar ) )
>>  {
>>  if ( sig.IsEntry() )
>>  {
>>  currEquity = bo.Equity;
>>  pointVal = sig.PointValue;
>>  cbtAtr = StaticVarGet( "statAtr" + sig.Symbol );
>>  psUnits = int( currEquity * ( pctVolaRisk / 100 ) / 
>> ( cbtAtr[bar] * pointVal ) );
>>  [_TRACE]
>>  sig.PosSize = ( 2000 + psUnits ) * -1;
>>  }
>>  }
>>
>>
>>
>> DebugView Output:
>> [2856] Date: 20.01.2000 Symbol: FDRY Equity: 10 Cash: 10 ATR: 
>> 14.383258 Units: 69
>> [2856] Date: 21.01.2000 Symbol: PCLN Equity: 10 Cash: 89818.2 ATR: 
>> 27.671930 Units: 36
>> [2856] Date: 21.01.2000 Symbol: TYC Equity: 10 Cash: 89818.2 ATR: 
>> 14.318740 Units: 69
>> [2856] Date: 25.01.2000 Symbol: AKAM Equity: 98382.8 Cash: 59163.1 ATR: 
>> 27.247997 Units: 36
>> [2856] Date: 03.02.2000 Symbol: IBM Equity: 97308.7 Cash: 49107.9 ATR: 
>> 4.628230 Units: 210
>> [2856] Date: 04.02.2000 Symbol: FDRY Equity: 97846.4 Cash: 42716.2 ATR: 
>> 13.667122 Units: 71
>>
>>
>> AA Results Output:
>> 20.01.2000
>>  Entry signals(score):FDRY=Buy(1),
>>  Exit signals:
>>  Enter Long, FDRY, Price: 147.563, Shares: 69, Commission: 0, Rank: 1, 
>> Equity 10, Margin Loan: 0, Fx rate: 1
>>  1 Open Positions: , FDRY (+69), Equity: 10, Cash: 89818.2
>>
>> 21.01.2000
>>  Entry signals(score):PCLN=Buy(1), TYC=Buy(1),
>>  Exit signals:
>>  Enter Long, PCLN, Price: 381, Shares: 36, Commission: 0, Rank: 1, 
>> Equity 100237, Margin Loan: 0, Fx rate: 1
>>  Enter Long, TYC, Price: 245.493, Shares: 69, Commission: 0, Rank: 1, 
>> Equity 100237, Margin Loan: 0, Fx rate: 1
>>  3 Open Positions: , FDRY (+69), , PCLN (+36), , TYC (+

[amibroker] Re: Incorrect value of bo.Equity ...? AB ALWAYS using equity of previous bar PS

2010-07-15 Thread rise_t575


Hi,

I've just found out what is happening, but I have not the slightest idea why.

The backtester is *always* using previous bar equity for positions sizing, 
although this setting is *not* ticked, and I haven't included the corresponding 
SetOption function.

In fact, the backtests and the debugging logs are exactly identical when 
UsePrevBarEquityForPosSizing is True and when it is False.

Is this some bug or isn't that setting being used when using CBT for position 
sizing?

Thanks in advance!

--- In amibroker@yahoogroups.com, "rise_t575"  wrote:
>
> Hello,
> 
> The following are the (debug) outputs of a tested position sizing algorithm.
> 
> I've attached a) part of the code , b) the output of the _TRACE() function 
> from within the CBT code (the TRACE function had been placed within the most 
> inner "if{}" code block), and c) the output of the AA Results window 
> (Detailed Log).
> 
> Note that on the _TRACE() output, the equity on day 2 (21.01.2000) is still 
> at its intial value (10), so it hasn't been adjusted for price changes of 
> the position taken at the close of day 1 (which did exist).
> 
> Since this equity value is used for calculation of the position size of 
> subsequent signals, this is a problem.
> 
> On the other hand, the output of the AA Results windows on day 2 is correct 
> (99823.2)
> 
> And - no - "Use previous bar equity for position sizing" is not activated.
> 
> Does anyone have an idea why bo.equity delivers incorrect values in this case?
> 
> Thanks in advance!
> 
> Part of CBT code in question:
> 
> for ( sig = bo.GetFirstSignal( bar ); sig; sig = 
> bo.GetNextSignal( bar ) )
> {
> if ( sig.IsEntry() )
> {
> currEquity = bo.Equity;
> pointVal = sig.PointValue;
> cbtAtr = StaticVarGet( "statAtr" + sig.Symbol );
> psUnits = int( currEquity * ( pctVolaRisk / 100 ) / ( 
> cbtAtr[bar] * pointVal ) );
>   [_TRACE]
> sig.PosSize = ( 2000 + psUnits ) * -1;
> }
> }
> 
> 
> 
> DebugView Output:
> [2856] Date: 20.01.2000 Symbol: FDRY Equity: 10 Cash: 10 ATR: 
> 14.383258 Units: 69
> [2856] Date: 21.01.2000 Symbol: PCLN Equity: 10 Cash: 89818.2 ATR: 
> 27.671930 Units: 36
> [2856] Date: 21.01.2000 Symbol: TYC Equity: 10 Cash: 89818.2 ATR: 
> 14.318740 Units: 69
> [2856] Date: 25.01.2000 Symbol: AKAM Equity: 98382.8 Cash: 59163.1 ATR: 
> 27.247997 Units: 36
> [2856] Date: 03.02.2000 Symbol: IBM Equity: 97308.7 Cash: 49107.9 ATR: 
> 4.628230 Units: 210
> [2856] Date: 04.02.2000 Symbol: FDRY Equity: 97846.4 Cash: 42716.2 ATR: 
> 13.667122 Units: 71
> 
> 
> AA Results Output:
> 20.01.2000
>   Entry signals(score):FDRY=Buy(1), 
>   Exit signals:
>   Enter Long, FDRY, Price: 147.563, Shares: 69, Commission: 0, Rank: 1, 
> Equity 10, Margin Loan: 0, Fx rate: 1
>   1 Open Positions: , FDRY (+69), Equity: 10, Cash: 89818.2
> 
> 21.01.2000
>   Entry signals(score):PCLN=Buy(1), TYC=Buy(1), 
>   Exit signals:
>   Enter Long, PCLN, Price: 381, Shares: 36, Commission: 0, Rank: 1, 
> Equity 100237, Margin Loan: 0, Fx rate: 1
>   Enter Long, TYC, Price: 245.493, Shares: 69, Commission: 0, Rank: 1, 
> Equity 100237, Margin Loan: 0, Fx rate: 1
>   3 Open Positions: , FDRY (+69), , PCLN (+36), , TYC (+69), Equity: 
> 99823.2, Cash: 59163.1
> 
> 24.01.2000
>   Entry signals(score):
>   Exit signals:
>   3 Open Positions: , FDRY (+69), , PCLN (+36), , TYC (+69), Equity: 
> 98382.8, Cash: 59163.1
> 
> 25.01.2000
>   Entry signals(score):AKAM=Buy(1), 
>   Exit signals:
>   Enter Long, AKAM, Price: 279.313, Shares: 36, Commission: 0, Rank: 1, 
> Equity 98825.1, Margin Loan: 0, Fx rate: 1
>   4 Open Positions: , FDRY (+69), , PCLN (+36), , TYC (+69), , AKAM 
> (+36), Equity: 98806.8, Cash: 49107.9
>