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

[amibroker] Re: Risk/Yield Map



PureBytes Links

Trading Reference Links

Mark,

Another way of doing this yourself is via the custum Gfx-charts. 
Below is my early attempt to achieve this. You will need to adjust 
the code to your settings. Also, you will notice that it is a 
very "early" attempt, as I could not yet get the actual values of 
return, respectively risk (i.e. standev) aligned with my x-axis and y-
axis (somehow the pixel-dimensions-thing does not intuit with my 
brain).

One of the potential extensions is to add relative weights for each 
asset, and then use it to create efficient frontiers, etc.

Anyway, hope it is of use to you or anybody else.

PS

GfxSetOverlayMode( 2 );

ChWL=Param("ChWL",5,1,15);

WLSymbols = CategoryGetSymbols(categoryWatchlist,ChWL);

RskLB = Param("Risk-LB",AnnPer,MonthPer,3*AnnPer);

HRet = -1000; LRet = 10000; HRsk = -10; LRsk = 0;

for( NumTickers=0; (Sym = StrExtract( WLSymbols, NumTickers )) != ""; 
NumTickers++ )
{
	SetForeign(Sym,True);
	Prijs = C;
	Ret = MA(ln(Prijs/Ref(Prijs,-AnnPer)),5*AnnPer)*100;
	VarSet(Sym+"Ret",Ret);
	Rsk = SDsam(ln(Prijs/Ref(Prijs,-1)),RskLB)*sqrt(AnnPer)*100;
	VarSet(Sym+"Rsk",Rsk);
	RestorePriceArrays();

	HRet = IIf (SelectedValue(Ret)>HRet, SelectedValue(Ret),HRet);
	LRet = IIf (SelectedValue(Ret)<LRet, SelectedValue(Ret),LRet);
	HRsk = IIf (SelectedValue(Rsk)>HRsk, SelectedValue(Rsk),HRsk);
	LRsk = IIf (SelectedValue(Rsk)<LRsk, SelectedValue(Rsk),LRsk);
		
}

//HRet = SelectedValue(HRet); 
//LRet = LastValue(LRet); 
//HRsk = LastValue(HRsk); 
//LRsk = LastValue(LRsk); 

RetRange = HRet - LRet;

RskRange = HRsk;

PxW= Status("pxwidth");
PxH = Status("pxheight");

ChartMargin = 10 ;// Equals startpoint drawing chart-window upper-left
HMargin = 10 ;
VMargin = 10 ;

RelSizeCh = (1-ChartMargin/100);// =0.9

CH = PxH*RelSizeCh;
CW = PxW * RelSizeCh;
//PxW-ChartMargin;

NrLvs = 10;

YaxGap = CH/NrLvs;
XaxGap = CW/NrLvs;

MaxY = ChartMargin + 2; // Max y-val = Upper Left within chart
MaxX = CW ; // Max x-val = Lower Right within chart
MinX = ChartMargin+70;
MinY = CH ;
RangeY = MinY - MaxY;

RetStepSize = RetRange / NrLvs;
RskStepSize = RskRange / NrLvs;

GfxSelectPen ( colorBlack ); 
//GfxRectangle ( PxH, y1, x2, y2 );
GfxRectangle ( MinX, MaxY, MaxX, MinY);
                  
GfxSelectFont( "MS Serif", 8,800);
//PrintTxtInCell( "CorrM @:\n"+NumToStr(ActD,formatDateTime), 0, 
0,CW, CH, HA, VA, 1);

GfxSetTextColor (colorBlack); 
GfxTextOut ("Return (in %)", MaxY , MaxY );

DrawL = (ChartMargin); // Top of graph
Val = HRet; NearZeroP = Val; NearZeroN = -10000; ZeroL = 0;

for ( z = 0 ; z < NrLvs+1   ; z++ ) 
{ 
  if (z>0)
{DrawL = DrawL+YaxGap; 
  Val = Val - RetStepSize;}

	if (Val>0) 
		{
			NearZeroP = Min (NearZeroP,Val);
			ZeroL++; 
		}
	else NearZeroN = Max(NearZeroN, Val);

  
  if (DrawL<CH) GfxTextOut ( WriteVal (Val, 1.2 ),  MaxY, DrawL);


	if (z==NrLvs) 
	{
		ZeroDL = (MaxY+10)+(YaxGap*ZeroL)+(NearZeroP/
(NearZeroP+abs(NearZeroN))*YaxGap);
		GfxTextOut ( WriteVal (0.0, 1.0 ),   MaxY, ZeroDL);
		NextZeroDL = ZeroDL;
	}

}

RskL = LRsk;

for (r=0; r<NrLvs+1 ; r++)
{

if (r==0) RskL=0;
else RskL = RskL + RskStepSize;

GfxTextOut ( "Risk (in %)", CW, CH+10);
GfxTextOut ( WriteVal (RskL, 1.2 ),   MinX+XaxGap*r, MinY+10);
}

for( NumTickers=0; (Sym2 = StrExtract( WLSymbols, NumTickers )) !
= ""; NumTickers++ )
{
	YVal = SelectedValue(VarGet(Sym2+"Ret"));
	XVal = SelectedValue(VarGet(Sym2+"Rsk"));

	YRank = YVal/HRet;
	XRank = XVal/HRsk;

//YRank=0.1; XRank=0.1;
	GfxTextOut ( Sym2 + " "+WriteVal (YVal, 1.2 )+"/"+WriteVal 
(XVal, 1.2 ),  XRank*MaxX, MinY -(YRank*RangeY));
}




--- In amibroker@xxxxxxxxxxxxxxx, "MarkK" <MailYahoo@xxx> wrote:
>
> Is there a way to run the Risk/Yield Map on a watch list or part of 
the
> complete database and not the whole thing?
> And if so how can not find it in the instructions
> 
> 
> Thank you
> 
>  
> 
> MarkK
>




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/