January 23, 2016
When we use File->Import ASCII to import data, we can choose import file format using one pre-defined import format definitions. As it is explained in the manual (http://www.amibroker.com/guide/d_ascii.html) it is also possible to create our custom import definitions to match data we are trying to import. This article explains all the required steps.
The easiest method to create import definition is to use File->Import Wizard. In the first page, select at least one file in the format we want to import and on the second page configure columns:
This all easy when we are importing quotation data, but when we are importing non-quotation data such as category assignments, we can not select appropriate columns using Import Wizard. In such case we need to type-in appropriate $FORMAT command in the “Additional commands” field of Import Wizard.
For example if we have file with categories like this:
"DDD","3D Systems Corporation","Technology","Computer Software: Prepackaged Software",1 "MMM","3M Company","Health Care","Medical/Dental Instruments",1 "WBAI","500.com Limited","Consumer Services","Services-Misc. Amusement & Recreation",1 "WUBA","58.com Inc.","Technology","Computer Software: Programming, Data Processing",1 "AHC","A.H. Belo Corporation","Consumer Services","Newspapers/Magazines",1 "ATEN","A10 Networks, Inc.","Technology","Computer Communications Equipment",1 "AIR","AAR Corp.","Capital Goods","Aerospace",1 "AAN","Aaron's, Inc.","Technology","Diversified Commercial Services",1
We need to add the following commands in the “Additional commands” field of Import Wizard
$FORMAT Ticker,FullName,SectorName,IndustryName,Group $OVERWRITE 1 $CLEANSECTORS 1 $SORTSECTORS 1
First line tells AmiBroker the column meaning, second line tells it to overwrite existing data. Last two lines tell AmiBroker to wipe existing category structure and sort imported sectors alphabetically. Be sure NOT to specify $CLEANSECTORS command when you do NOT want to wipe existing category structure.
We also need to mark “No quotation data” box in the second page of Import wizard to tell AmiBroker that the file that we are importing does not contain quotes and it should switch off all price checking.
Finally, in the last step of the wizard save the format definition:
Once we do this, next time we use File->Import ASCII a new selection My own format will appear in the Files of type combo box in the file selector dialog.
It is worth noting that import definitions are plain text files that are stored in “Formats” subfolder of AmiBroker directory, and the list of available import definitions that appears in “Files of type” combo box, is also a plain text file called “import.types” that is located in the same subfolder. So, advanced users may also modify those files directly using plain text editor such as Notepad. It is all explained in great detail in the manual http://www.amibroker.com/guide/d_ascii.html