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

[amibroker] Re: PositionSize based on Equity and Trade Risk



PureBytes Links

Trading Reference Links

Very nice Brenton.  Thank you.  At first glance this looks like the best way to go.  It seems to work pretty well although I see a few of my trade losses are bigger than my risk percentage.  I'll need to hand calculate a few trades to figure out what's going on.  More than likely it's probably something simple like a round off errors.

Best Regards,

David

--- In amibroker@xxxxxxxxxxxxxxx, Brenton Hill <bphill0105@xxx> wrote:
>
> Dave
> 
> Look up SetPositionSize function
> 
> *SetPositionSize( size, method )
> 
> *
> 
> /method/ (ARRAY) defines how 'size' is interpreted
> 
>     * spsValue (=1) - dollar value of size (as in previous versions)
>     * spsPercentOfEquity (=2) - size expressed as percent of
>       portfolio-level equity (size must be from ..100 (for regular
>       accounts) or .1000 for margin accounts)
>     * spsShares (=4) - size expressed in shares/contracts (size must be
>        > 0 )
>     * spsPercentOfPosition (=3) - size expressed as percent of currently
>       open position (for SCALING IN and SCALING OUT ONLY)
>     * spsNoChange (=0) - don't change previously set size for given bar
> 
> the second option allows a % of portfolio-level equity, which (as far as 
> I know) works out position size from the current portfolio equity during 
> in a backtest.
> 
> Some simple maths will allow you to convert this to trade size based on 
> risking a percent of portfolio equity per trade.
> 
> For any trade you want
> 
> TradeSize = RiskPct*Equity/StopSize
> 
> re-arrange it a bit
> 
> TradeSize = RiskPct/StopSize*Equity
> 
> therefore the Percent of Equity for the trade is RiskPct/StopSize
> 
> So use this in the SetPostionSize call. ie
> 
> SetPositionSize(RiskPct/StopSize,spsPercentOfEquity);
> 
> Personally I don't believe in compounding profits in backtesting, so 
> don't test this way myself, but that's another arguement.
> 
> Brenton
> *
> 
> *
> 
> dbwyatt_1999 wrote:
> >
> >
> > Thanks James, the issue I have is not with calculating risk; it's the 
> > fact that I need to use the custom Phase 2 backtester to get the 
> > portfolio Equity value of each bar and most of my system logic 
> > including my stop price calculations are currently in the regular 
> > Phase 1 backtester code. Once the backtester moves from Phase 1 to 
> > Phase 2, my Phase 2 custom backtester code does not have access to my 
> > array variables calculated in Phase 1 (unless I'm not doing something 
> > correctly). I'm trying to figure out the easiest way to get my stop 
> > prices calculated in Phase 1 into my Phase 2 custom backtester code so 
> > that I can calculate a position size based on a percentage of the 
> > portfolio equity and the initial risk of each trade.
> >
> > I could be going about this all wrong, but my goal is simply to 
> > calculate a quantity (i.e. number of futures contracts) for each trade 
> > based on a percentage of the current portfolio equity divided by the 
> > trade risk (i.e. abs(EntryPrice - StopPrice)*PointValue*TickSize).
> >
> > Regards,
> >
> > David
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%40yahoogroups.com>, 
> > James <jamesmemphis@> wrote:
> > >
> > > David,
> > >
> > > I haven't gotten to the point of selecting position size, however, 
> > if you know your entry price and initial stop, you can use something 
> > like the following to determine initial dollar risk:
> > > Prange = PHighPrice - PLowPrice;
> > > MaxLoss = PointValue* PRange;
> > > MaxLossLimit = Optimize("MaxLoss", 1000, 150, 4000, 25);
> > >
> > > In this case I am going long at PhighPrice with an initial  stop a 
> > PLowPrice and not taking the trade if the MaxLoss exceeds a certain 
> > level. From this point you could calculate the MaxLoss as a % of 
> > equity. Does this help?
> > >
> > > James
> > >
> > >
> > >
> > >
> > > ________________________________
> > > From: dbwyatt_1999 <dbw451@>
> > > To: amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%40yahoogroups.com>
> > > Sent: Saturday, May 30, 2009 7:39:47 AM
> > > Subject: [amibroker] PositionSize based on Equity and Trade Risk
> > >
> > >
> > >
> > >
> > >
> > > I know setting PositionSize based on Equity and Trade Risk has been 
> > the topic of numerous threads and writeups, but I'm missing some 
> > understanding. I'm backtesting a portfolio of futures contracts and 
> > would like to set the Position size of each trade based on each 
> > trade's risk (i.e. abs(entryPrice - stopPrice)) and a percent of the 
> > current portfolio Equity value. I understand that to get the current 
> > portfolio Equity, I need to use the custom backtester. The custom 
> > backtester also gives me access to all the data I need to calculate a 
> > new PosSize except my stopPrice values.
> > >
> > > What is the easiest way to access my backtester Phase 1 stopPrice 
> > array in the custom Phase 2 backtester for each trade so that I can 
> > calculate a new PosSize? Using AddToComposite( ) and Foreign() does 
> > not seem like an option because I want my individual stop values for 
> > each instrument, not a portfolio composite of all stop values. Or 
> > maybe I would have to create a separate composite for each instrument. 
> > Or do I have to resort to something like writing and reading files or 
> > developing a custom DLL to store the stopPrices between the backtester 
> > Phase 1 and the custom backtester Phase 2? Hopefully, I'm just not 
> > understanding something and there is an easier way. I would think that 
> > accessing Phase 1 backtester variables in Phase 2 would be pretty 
> > common; especially for calculating custom metrics.
> > >
> > > Thanks for any suggestions or insights.
> > >
> > > Regards,
> > >
> > > David
> > >
> >
> > 
> >
> >
> > __________ Information from ESET NOD32 Antivirus, version of virus 
> > signature database 4117 (20090530) __________
> >
> > The message was checked by ESET NOD32 Antivirus.
> >
> > http://www.eset.com
> 
> 
> 
> 
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4117 (20090530) __________
> 
> The message was checked by ESET NOD32 Antivirus.
> 
> http://www.eset.com
>




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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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/