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

[amibroker] Re: Get StdDev of Custom Metric



PureBytes Links

Trading Reference Links



Hi,

You are misusing arrays and array indexing. StDev returns an array and will use the 'periods' last bars for the calculation at each bar. You are stuffing all your R values at the beginning of the array, but the most recent value of StDev would be based on values at the end of the array. Besides, you are really only interested in a single calculation, not an array of calculations.

Finally, array size is limited by the number of bars under study. If you had more trades than bars, your approach would fail due to invalid array indexing.

Try the following instead:

R = sumR = sumR2 = 0;

for (trade = bo.getFirstTrade(); trade; trade = bo.getNextTrade()) {
  R = ...;

  trades++;
  sumR += R;
  sumR2 += R^2;
}

if (trades > 0) {
  stdDev = sqrt((sumR2 - (sumR^2 / trades)) / trades);
}

The algorithm above is based on the population version of method 2 published here: http://www.easycalculation.com/statistics/learn-standard-deviation.php

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "davemabe2000" <davemabe@xxx> wrote:
>
> I need to get the standard deviation of a custom metric that I'm
> computing by iterating through each trade in the BacktesterObject. The
> problem is that StDev takes an array.
>
> How do I build an array within the loop to compute the StDev of after
> the loop completes? Here's what I'm doing:
>
> if (Status("action") == actionPortfolio) {
> bo = GetBacktesterObject();
> bo.Backtest(1);
> num_trades = 0;
> all_rmultiples = 0;
> for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade()) {
> num_trades++;
> // ... getting r_multiple value here
> all_rmultiples[num_trades-1] = r_multiple;
> }
> rmultiple_stddev = StDev(all_rmultiples, num_trades - 1);
> bo.AddCustomMetric("StdDevRs", rmultiple_stddev);
> }
>
>
> StdDevRs is always blank in the backtest report. Any advice?
>



__._,_.___


**** 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___