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

[amibroker] Re: ASX Setup - dividend adjusted prices



PureBytes Links

Trading Reference Links

Michael, I now have a dividend adjusted db.
These are the steps i followed.
Produce an ASX dividend adjusted db.
Inputs:
Sample DB  with dividend history to June 2005, and template DB
as provided by Michael S. G.
AFL code provided by G.Jensen with file write code adapted from 
G.Kavanagh.
1.7ghz PC with XP.
Steps:
1. Select Sample DB (in my case copied and renamed: "ASX_F_")
2. Use "z_exportDd" (source listed below) & AA EXPLORE to
prepare a 
dividend file with Datenum field appended as open interest.
3. Paste exploration to new dividend file in .csv format. Steps (2 & 
3) could be replaced with write to file using code example in other 
AFL formula below.
4. Import the new dividend file to ASX_F_. Note that type 2 and 3 
records are not altered in this step.
	Make sure DMY is selected if appropriate, "more column"s is 
selected and "open interest" is to be designated as the extra
column, 
and tick "negative prices" (actually means zero or negative).
Takes 
around 2 to 3 minutes.
5. Use SCAN in AA and "z_exportAdjDIV" (source code listed
below) to 
write out dividend adjusted data. Note that the option taken is to 
adjust prices upwards on the ex date for each dividend. Only symbols 
which have (HAD) a "-DivD" record will be written out. Writes
around 
700 symbol files in 7 minutes. You could add original close as
"open 
interest": This may facilitate later updates. 
Note also that the output has NO SUFFIX. That's because I put it
in a 
different db. If you want to import it back to ASX_F_ (whatever), you 
need to add a suffix in the AFL code and make appropriate changes to 
AB categories so as not to mix up the unadjusted and adjusted data.
6. Import the dividend adjusted files to your renamed copy of 
Template db. Note that this db does not have the datenum field in 
the "-Divd" symbols. 
Note that dividend adjusted data may give misleading results for 
anyone trading leveraged instruments, or trading options because 
dividends do not affect prices and therefore historic volatility may 
not be calculated correctly.
Note that template db has many symbols for which there has been no 
dividend.

SOURCE AFL code
/*z_exportAdjDIV*/

/*part of dividend adjustment - 
determine cumulative dividend and 
write out adjusted dividend*/
Buy=Sell=0;
x=StrLeft(Name(),3);
select=0;
select=StrLen(Name())==3;
divfile=x+"-DivD";

fd=Foreign(divfile,"i");
any=Foreign(divfile,"o");
exists=0;
for (k=0;k<BarCount;k++)
{
exists=Max(exists,any[k]);
}

div=100*Foreign(divfile,"H");
ex=IIf((fd-DateNum()==0)
AND (1==Foreign(divfile,"o"))
,1,0);
div=div*ex;

divtot=Cum(div);
divtot=IIf(IsNull(divtot),0,divtot);
divadj=divtot/100;
Filter=select AND exists;
AdjC=C+divadj;
Adjo=O+divadj;
adjh=H+divadj;
adjl=L+divadj;
AdjC=C+divadj;

quotes=(NOT IsNull(H));

Choose=(select AND quotes);
Filter=Choose;
//use scan not explore -- explore just for development
Valuei=ValueWhen((Choose),BarIndex());
first=Choose AND (Ref(Choose,-1)==0);
from=IIf(first==1,BarIndex(),0);
fromhere=0;
for( j = 1; j < BarCount; j++ )
{fromhere=Max(from[j],fromhere);
}
AddColumn(adjo,"adj o");
AddColumn(adjh,"adj h");
AddColumn(adjl,"adj l");
AddColumn(adjc,"adj c");
AddColumn(V,"v");
/*file write adapted from G.Kavanagh*/
flag=1 AND 2;// force boolean
flag=select AND exists ;
if (flag)
{
fh = fopen(
"c:\\_DataD\\ABexport\\"+Name()+"-DA.txt",
"w");
if( fh )
{

fputs("<ticker>,<date>,<open>,<high>,<low>,<close>,<volume>\n",fh);
t = Name();
y = Year();
m = Month();
d = Day();



for( i =fromhere; i < BarCount; i++ )
{
fputs( t + "," , fh );


ds = StrFormat("%02.0f/%02.0f/%02.0f,",
y[ i ], m[ i ], d[ i ]);
fputs( ds, fh );


qs = StrFormat("%.3f,%.3f,%.3f,%.3f,%.0f\n",
adjO[ i ],adjH[ i ],adjL[ i ],adjC[ i ],V[ i
] );
fputs( qs, fh );
}
}
else;
fclose( fh );
}

/**/
/*z_exportDd*/

/*part of dividend adjustment - 
write out Date in comparable format*/
x=StrLeft(Name(),8);
x=StrRight(x,4);
select=x=="DivD";
z=StrLeft(Name(),3);
//y=z=="ANZ";
dnow=DateNum();
OI=dnow;
ex=O==1;
/*with my settings ab pads quote value 
until next real quote, so have to drop those */
ex[0]=IIf(O[0]==1,1,0);//unless first bar is a dividend?
ex=IIf(Ref(ex,-1)==1,0,ex);
Filter=select AND  ex;
AddColumn(O,"O" ); 
AddColumn(H,"H" ); 
AddColumn(L,"L" ); 
AddColumn(C,"C" );
AddColumn(V,"V" ); 
AddColumn(OI,"OI:= Datenum" );












------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/DldnlA/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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

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