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

RE: [amibroker] Re: Still More Detailed Coding Challenges



PureBytes Links

Trading Reference Links

Mike:

Thanks.  The line you refer to actually works fine.  I originally had a "+"
in it and the summation got more negative just fine.  I could have made the
sum positive or created a positive sum, which I did.

The problem is the count of NoDn, which not only is EMPTY but the debugview
program reports is having a value of {NAN} whatever that is.

Anyway, thanks for trying to help.

Ken 

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of Mike
Sent: Saturday, August 16, 2008 7:44 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Still More Detailed Coding Challenges

Try changing the line:
MnGainDnSum[k] = MnGainDnSum[k-1] - MnGain1[k];

To:
MnGainDnSum[k] = MnGainDnSum[k-1] + MnGain1[k];

Note that by subtracting a negative, you are adding rather than getting more
negative. If not intended, this would then throw off the calculation for:

BD = (MnGainDnSum / NumDn)^2;
SdDn = sqrt(AD - BD);

Possibly resulting in an erronous attempt to take sqrt of a negative number?

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Ken Close" <ken45140@xxx> wrote:
>
> How do I discover these?
>  
> I need a loop to calculate a custom Standard Deviation for monthly
returns
> that are only positive.
> I was successful and came up with StDevs that matched calculations
in Excel.
> I used the following loop routine (first one below).  But my
problem came
> when I copied the routine and changed some variable names in order
to
> calculate StDevs of the monthly returns that are negative.  Same
code, same
> structure, slightly different variable names.  In the case of the
negative
> return routines, the variable to hold the number of months that have 
> negative values is Empty and stays empty, and it is not obvious why
it stays
> empty.  I have tried all sorts of variations, including use of TRACE 
> statements and debugview...but no joy.
>  
> I hope someone with loop and subscripted variable experience will
glance
> into the details and "discover" why the first routine works and the
second
> one does not.
>  
> Thanks.
>  
> Positive routine which works:
> In both of these, monthly returns are represented by MnGain Sums of 
> gains and squares of sums of gains are obvious NoUp is a count of 
> number of up months Everything is the same in the second routine 
> except for name
changes to get
> negative returns
>  
> The MYSTERY is why the variable NoDn is Empty.  An even deeper
mystery is
> why, when using _TRACE statements,
> the indicator in the debugview window for NoDn is {NAN} instead of
{EMPTY}.
>  
> Help!
>  
> // Routine to calculate StdDev of Positive Monthly Gains k = BarNo; 
> NoUp[FirstBar-1] = 0; GainUpSq[FirstBar-1] = 0; 
> MnGainUpSum[FirstBar-1] = 0; for (k=FirstBar-1; k < LastBar ; k++ ) { 
> if (MnGain1[k] > 0) { MnGainUpSum[k] = MnGainUpSum[k-1] + MnGain1[k]; 
> GainUpSq[k] = GainUpSq[k-1] + (MnGain1[k])^2; NoUp[k] = NoUp[k-1] + 1; 
> } else { MnGainUpSum[k] = MnGainUpSum[k-1]; GainUpSq[k] = 
> GainUpSq[k-1]; NoUp[k] = NoUp[k-1]; } } A = (GainUpSq) / NoUp; B = 
> (MnGainUpSum / NoUp)^2; SdUp = sqrt(A - B);
>  
> Negative return routine which has NoDn array Empty (or with
{NAN} "value" in
> debugview
>  
> // Routine to calculate StdDev of Negative Monthly Gains k = BarNo; 
> NumDn[FirstBar-1] = 0; _TRACE("k = " + WriteVal(NumDn[102],1.0)); 
> GainDnSq[FirstBar-1] = 0; MnGainDnSum[FirstBar-1] = 0; for 
> (k=FirstBar-1; k < LastBar ; k++ ) { if (MnGain1[k] < 0) { 
> MnGainDnSum[k] = MnGainDnSum[k-1] - MnGain1[k]; GainDnSq[k] = 
> GainDnSq[k-1] + (MnGain1[k])^2; NumDn[k] = NumDn[k-1] + 1; // 
> _TRACE("k = " + WriteVal(NumDn[k],1.0)); } else { MnGainDnSum[k] = 
> MnGainDnSum[k-1]; GainDnSq[k] = GainDnSq[k-1]; NumDn[k] = NumDn[k-1]; 
> } } AD = (GainDnSq) / NumDn; BD = (MnGainDnSum / NumDn)^2; SdDn = 
> sqrt(AD - BD);
>



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

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




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

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/