[amibroker] Re: Annualized Standard Deviation?

 

Your code here returns an array, not a single number:
portfolioEq = Foreign( "~~~Equity", "C" );
annStDev = (StDev( portfolioEq, 2321 )) * sqrt( 252 );

Also, I'm not sure the call to Foreign will necessarily have accurate numbers prior to the CBT, as the documentation says this array is only accurate after the backtest is complete. I *think* before then it is only a preliminary calculation of buy/sell signal performance, without adjustments for costs, applystops, etc.

Try this. Assuming you are testing the whole length of your array, in the CBT do,

     bo = GetBacktesterObject();
     bo.Backtest();
  std = LastValue(StDev(bo.EquityArray, barcount-1)); // returns a number
  std *= sqrt(252);
  bo.AddCustomMetric( "AnnStDev", std); 



---In amibroker@yahoogroups.com, <sladbrook@...> wrote :

Hi

I'd like to add code to my system for Annualized Standard Deviation. I'd like it printed out to the backtest report as a custom metric. I've been experimenting and cant get anything to work. Please help. Examples of my code, that DONT work, are below. The number 2321 represents the number of bars I have.


portfolioEq = Foreign( "~~~Equity", "C" );
annStDev = (StDev( portfolioEq, 2321 )) * sqrt( 252 );
StaticVarSet( "PortfolioEquity", annStDev );

SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
 {
 bo = GetBacktesterObject();
 bo.Backtest();
 annualSD = StaticVarGet( "PortfolioEquity" );
 bo.AddCustomMetric( "AnnStDev", annualSD );
 }



SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
 {
 bo = GetBacktesterObject();
 bo.Backtest();
 StaticVarSet( "PortfolioEquity", bo.EquityArray() );
 }

if ( Status( "action" ) == actionIndicator )
 {
 portfolioEq = StaticVarGet( "PortfolioEquity" );
 annStDev = (StDev( portfolioEq, 2321 )) * sqrt( 252 );
 //bo.AddCustomMetric( "AnnStDev", annStDev );
 }



Thanks for any help.


CK

__._,_.___

Posted by: rosenberggregg@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
**** 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/


.

__,_._,___

Related Posts


EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng
:lv