Also, FWIW, you probably want to track the StDev of the ROC() in the daily equity value, and not of the daily equity value itself. Here's code I use, if it helps,
function SafeROC(sourceArray, period) { //begin safeROC
//This calculates ROC in a function with proper divide-by-zero checking and the "absolute" parameter
//set to true, to correctly handle the movement of negative numbers.
result = IIf(AlmostEqual(sourceArray, 0), //If the numerator is zero
Nz(ROC(sourceArray, period, true)/100, 0), //If the denominator is also zero, return 0
Nz(ROC(sourceArray, period, true)/100, 100)); // Otherwise, numerator is positive
// so return a high-value in case of divide
// by zero error
return result;
} //end SafeROC
function Volatility(sourceArray, measurePeriod, reportPeriod) { //begin Volatility
//Calculates volatility over a measuring period and reports it back scaled to reporting period
dailyChg = SafeROC(sourceArray, 1);
result = GetStdDev(dailyChg, measurePeriod)*sqrt(reportPeriod);
return Nz(result);
} //end Volatility
__._,_.___
Posted by: rosenberggregg@yahoo.com
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (3) |
**** 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/
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/
.
__,_._,___
EmoticonEmoticon