Hi Thomaz,

I still notice this problem. Here is an example code:

SetCustomBacktestProc("");

if( Status("action") == actionPortfolio )
{
  bo = GetBacktesterObject();
 
  bo.PreProcess(); // Initialize backtester
 
  for(bar=0; bar < BarCount; bar++)
  {
       bo.UpdateStats(bar, 2);  //  Update MAE/MFE stats for bar

                CurEquity = bo.Equity;

                for (sig = bo.GetFirstSignal(bar); sig; sig = 
bo.GetNextSignal(bar))
        {       //  Loop through all signals at this bar

                                if ( sig.IsEntry() ) 
                                {
                        NbShares= -ceil(sig.PosSize*CurEquity/100/
(sig.price+0.01)) ;
                                        _TRACE
("Symbol,"+sig.Symbol+", NbShares calculated:"+ NbShares + ", 
PosValueCalculated:"+NbShares*sig.price+", PosSize:"+sig.PosSize+" 
CurEquity:"+CurEquity+", Sig.Price:"+sig.Price); 
                                }
                }


                bo.ProcessTradeSignals( bar );


                for( pos = bo.GetFirstOpenPos(); pos; pos = 
bo.GetNextOpenPos() )
                {
                        _TRACE("Symbol,"+pos.Symbol+", 
realShares:"+pos.shares + ", PosValue:"+pos.getpositionvalue()+", 
L/S:"+pos.islong()+", Price:"+pos.getprice(bar,"C")+", 
CurEquity:"+CurEquity); 
                }

   }



        bo.PostProcess(); // Finalize backtester
}


PositionSize= -5;

Buy = 1;
Sell=0;


I run this code on a yahoo database and I notice I have very 
different NbSHares calculated from the real NbShares.


Here are some trace samples:
[14300] Symbol  AALA     realShares     60955    PosValue       24382
         L/S    -1       Price  0.41     CurEquity      5000
[14300] Symbol  AALA     NbShares calculated    59523    
PosValueCalculated      24404.4  PosSize        -5 CurEquity    500000
         Sig.Price      0.41                                    
                                                                
[14300] Symbol  AAME     realShares     16510    PosValue       24765
         L/S    -1       Price  01/01/51         CurEquity      500000
[14300] Symbol  AAME     NbShares calculated    16447    
PosValueCalculated      24835    PosSize        -5 CurEquity    500000
         Sig.Price      01/01/51                                
                                                                
They are differences. I use thess settings:

Min. shares=1
Round lot size=1
commissions in $ per share/contract=0.01


Can you help?

Regards,
Olivier
                                                                
--- In [email protected], "Tomasz Janeczko" <[EMAIL PROTECTED]> 
wrote:
>
> I can ensure you that AmiBroker would round DOWN to 1000.
> 
> You have mistakes elsewhere in your formula and/or settings, but 
unless you 
> send FULL formula and settings to SUPPORT, no one would able to 
help you.
> 
> You may not be aware of the settings you are using specifically
> if you are using today or previous day equity for position sizing
> and what is your actual equity. Your "CurEquity" may not be actual 
equity
> but something else like initial equity causing confusion in your 
understanding
> of calculations. Again:
> FULL formula, SETTINGS and send them to SUPPORT
> 
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "olivier_molongo" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Sunday, November 16, 2008 9:47 PM
> Subject: [amibroker] Incorrect rounding of shares in backtester!
> 
> 
> > Hello,
> > 
> > How can I get the number of shares that would be bought on a 
given 
> > signal in low level CBT?
> > 
> > I use the formula :
> > 
> > NbShares=-ceil
(sig.PosSize*CurEquity/100/sig.price/sig.RoundLotSize)
> > *sig.RoundLotSize;
> > 
> > I don't get the exact number of shares bought or sold by AB. As 
an 
> > exemple, with:
> > 
> > CurEquity=500000-5
> > PosSize=-5
> > sig.Price=22.86
> > sig.RoundLotSize=100
> > 
> > my formua gives NbShares=1000. The exact value is 1093 rounded to 
> > 1000.
> > 
> > The signal processed trades 1100 shares. The position value for 
1100 
> > shares is 25113 that is above the 5% equity limit given by 
PosSize 
> > (25000=5% * 500000). 
> > 
> > Amibroker default calculation seems incorrect.
> > 
> > WHat is the formula used by AB?
> > 
> > Regards,
> > Olivier
> > 
> > 
> > ------------------------------------
> > 
> > **** IMPORTANT ****
> > This group is for the discussion between users only.
> > This is *NOT* technical support channel.
> > 
> > *********************
> > TO GET TECHNICAL 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
> > 
> > 
> >
>


Reply via email to