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

RE: [amibroker] Re: Advice on Populating New Set of Industries



PureBytes Links

Trading Reference Links

OK, Below is the edited script.
 
/*
** AmiBroker/Win32 scripting Example
**
** File:  Industries.js
** Created:  Tomasz Janeczko, November 26th, 2000
** Last updated: Tomasz Janeczko, December 17th, 2000
** Purpose:  Import industy assignments
** Language:  JavaScript (Windows Scripting Host)
**
** The data is stored in lines with following format
** <ticker>,<market number>,<full name>,<industry number>
** or
** <ticker>,<market number>,<"full name">,<industry number>
**
** Modified 5/6/2001 by Brett Forrester
**
** Modified 2002/07/24 by U.Mutlu: added function RemoveCommasWithinFields()
**   This solves the problem described in "Importing Instructions.txt" by
Larry M.
**   You should also set $BREAKONERR 0  in formats\AQH.format. And also
there
**   better set $MARKET 254. This causes all unspecified (new) tickers to be
placed
**   in market area 254. After importing a market you should move those in
market area 254
**   to the right market. I created MARKETNAME_UNSPEC for inspecting them
first...
**   New entries in Tick_MktID_Name_IndID.csv should use the second form
above if
**   company title contains blanks (i.e.. Consists of more than a word). 
**
*/
 
/* script for importing ticker, market, full name, and industry assignment
number */
WScript.Echo( "Script Started. Wait until end popup MSG comes..." );
 
/* change this next line according to your data file name */
ImportStocks("industry_data.csv");
 
WScript.Echo( "Finished" );
 
 
 
Function RemoveCommasWithinFields(str)
  { // UM: my very first Javascript function :-)
    // Here commas within "..." and also all " chars are removed 
    // from the input string str. Function returns (modified) str
 
    Var strNew = "";
    Var ch;
 
    f = false;
    For (I = 0; I < str.length; I++)
      {
        Ch = str.charAt(I);
 
        // skip " char
        If (ch == '\"')
          {
            f = !f;
            Continue;
          } 
 
        // skip comma within "..."
        If (f && (ch == ','))
          Continue;
        
        StrNew = strNew + ch;
      }
 
 // if (f)
 //   WScript.Echo("Error in line: " + str);
 
    Return strNew;
  }
 

Function ImportStocks( filename )
{
 Var fso, f, R, str;
 Var ForReading = 1;
 Var AmiBroker;
 Var fields;
 Var stock;
 

 /* Create AmiBroker app object */
 AmiBroker = new ActiveXObject( "Broker.Application" );
 
 /* ... And file system object */
 Fso = new ActiveXObject( "Scripting.FileSystemObject" );
 
 /* open ASCII file */
 f = fso.OpenTextFile( filename, ForReading);
 
 i = 1;
 /* read the file line by line */
 While ( !f.AtEndOfStream )
 {
  Str = f.ReadLine();
                R   = RemoveCommasWithinFields(str);
  
  /* split the lines using comma as a separator */
  Fields = R.split(","); 
  
  Try
  {
   
   /* add a ticker - this is safe operation, in case that  */
   /* ticker already exists, AmiBroker returns existing one */
   Stock = AmiBroker.Stocks.Add( fields[ 0 ] ); 
      
   /* this line reads marketID which start at 0 and increments by one - blf
*/
   Stock.MarketID = parseInt( fields[ 1 ] );
 
   Stock.FullName = fields[ 2 ];
   
   /* this line reads industryID which starts at 0 and increments by 1 - blf
*/
   Stock.IndustryID = parseInt( fields[ 3 ] );
  }
  Catch( e )
  {
   WScript.echo( "There is a problem in line no." + I + ".\nThe line looks
as follows:\n'" + R + "'\nIt will be skipped and next lines will be
processed as normal" );
  }
     
  i++; 
 }
 
 /* refresh ticker list and windows */
 AmiBroker.RefreshAll();
 
}
 
Don't ofrget to adjust for line breaks before you try to run it. Were you
able to get the corrected industry_data.cvs OK?
 
 
-------Original Message-------
 
From: Grover Yowell
Date: 09/22/06 19:06:48
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Re: Advice on Populating New Set of Industries
 
Don,
I would like to receive the script which you sent but it was blocked by my
Outlook program.  Could you resend it as a .txt file?  I also would like to
set up the database.
Thanks,
Grover
 



From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of Don Lindberg
Sent: Friday, September 22, 2006 11:19
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Re: Advice on Populating New Set of Industries
 
 The script, PopulateIndustriesAndTickers_v3_0.js, must be put into your
AmiBroker/Script directory and also the industry_data.txt in the Same
directory. If you want the market ID automatically assigned, use the
attached industry_data.cvs. You must then edit
PopulateIndustriesAndTickers_v3_0.js to tell it the name of your import list
 To make things a little easier for you I have also attached an edited
version of PopulateIndustriesAndTickers_v3_0.js that will point to the
correct file.
 
Once you have put the above files in AmiBroker/Scripts directory, open your
new database, go to the Tools menu, choose customize, then choose the tools
tab,  choose New, give it the name Get Industries,then go to the Command bar
and browse to your file,PopulateIndustriesAndTickers_v3_0.js to make it the
active command. In the Initial directory bar put the full path to the
AmiBroker\Scripts directory (For Example:  C:\Program
Files\AmiBroker\Scripts\)  Now choose Close at the bottom of dialog box.
 
Back in your database screen click on the tools menu, and you should see an
entry for Get Industries (on whatever you named it). DoubleClick on this
entry and a dialog box will appear stating that the script has started.
Click OK, and wait until another dialog appears stating that the script has
finished. I will take 10 to 20 minutes depending on the speed of your
computer.
 
Once the script has completed your new database will be populated with all
the symbols, shown in their correct Exchange, Sector and Industry, but they
will have no price information. Start AmiQuote, make sure it is set to Yahoo
Historical, set the date range for the data you wish to import. Now click on
the Tools menu, choose Get ticker from AmiBroker and wait for the list to
populate. Now click on the Green arrow to start the download process and
wait for completion. Again depending on your machine speed and your Internet
connection speedit could take several hours to finish, but when done your
database will be fully populated.
 
Hope this helps.
-------Original Message-------
 
From: gsmservplus
Date: 09/22/06 09:56:24
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Advice on Populating New Set of Industries
 
Mr Don.
 
could you explain step by step how to use that script?
i`ve done first two steps, i changed industry and sector files in
amibroker directory by hemscott files from
http://finance.groups.yahoo.com/group/amibroker, i checked symbol
>categories - industries.there was everything linked to right
sectors.but now i have no idea how to do everything in step 3? i mean
where that script file goes and how to use it?
(PopulateIndustriesAndTickers_v3_0.js or Industries.js , btw first
script has  data stored in lines with following format
** <ticker>,<market number>,<full name>,<industry number>, second one
<ticker>,<full name>,<industry number>,i`ve got industry_data.txt
File from http://finance.groups.yahoo.com/group/amibroker whitch has
no market numbers.where to put file industry_data.txt. how to use it?
  thank you
 
>  Ken,
> Yes you can reassign you own definitions to the Industry/Sectors. I
have
> played with this for a modified Hemscott rating system.
> 
> Here is the procedure as simply as I can explain it.
> 
>     1) you must change the broker.industries and broker.sectors
files at the
> root of AB directory before you create your new directory.  These 2
files
> establish your structure  on any NEW database. (has no effect on
previously
> created ones). The broker.sectors file establishes your main
categories
> (whatever you decide they are). This is simply a text file you can
> manipulate with any text editor. The file counts from 0 up, so your
1st
> category will be 0, second will be 1, third will be 2, etc to the
limit of
> your categories.  There is a direct relationship Between
broker.sectors and
> broker.industries. In broker.industries you have 2 fields, a
number, and a
> description. The number is a reference back to broker.sectors. Thus
every
> entry in broker.industries MUST relate to one of the entries in
> broker.sectors.  This file is also a text file.
> 
>     2) Once you have established these two files in the format of
your
> liking you will create your new BLANK database. You then go into
> Symbol>Categories and choose the Industries tab. On the left you
will see
> all the categories you created in broker.industries. You must now
go through
> each of these categories, and (on right hand side of screen) link
them to
> one of your broker.sectors categories. This sets up your basic
structure for
> populating the new database.
> 
>     3) Populating the database is done with a script reading a
ticker file.
> I used the script "PopulateIndustriesAndTickers_v3_0.js which is
located in
> the Files section on the AmiBroker Users Group.  The ticker format
is
> <ticker>,<market number>,<Full name>, <industry number>.
> This last is the most important to you as it will put your stock
into their
> assigned category.  THE MOST IMPORTANT THING TO REMEMBER is the
industry
> number corresponds to you categories position in your
broker.industries !
> Thus if your first category was Widgets, the number you put in the
<industry
> number> post ion will be 0. Now when the script reads your ticker
all of
> your stocks numbered 0 will appear in the category Widgets.
> 
> That covers the how. I am not a writer, so I can only hope the
above makes
> sense to you. Feel free to ask me questions about the procedure and
I will
> clarify as best I can.
> 
> Hope this helps,
> 
> Don Lindberg
> 
> 
> 
> -------Original Message-------
> 
> From: Ken Close <mailto:ken45140@...>
> Date: 9/7/2006 7:21:32 AM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Advice on Populating New Set of Industries
> 
> I do not know if this can be done, but I hope someone can offer
some advice
> or point to some messages....
> 
> I want to track ATCs of most ETFs which number well over 100.
True, some
> are probably much less important now but as ETF use grows and as
more
> varieties emerge, then the number of "popular" ones is sure to grow.
> 
> I have been thinking how to organize to do this, and the only
obvious
> approach (short of an instantaneous update of the program to
increase the
> number of Watchlists) is to popular the Industry set with the ETF
members.
> 
> I see Industry slot from 0 to 100 or whatever, each named for the
symbol of
> the ETF and containing the holdings of the ETF.  I have read (and
reread)
> the "Organization of the database" and it appears that this will be
> possible, although I am not certain.
> 
> Also, it seems like some of the scripts which have been written to
populate
> normally named industries and sectors will have to be modified (how
I do not
> know yet).
> 
> What is your assessment of this approach?
> 
> Do you have other suggestions?
> 
> Can you point me to any scripts that I could use(modify) for my
purpose?
> 
> Thanks for any assistance.
> 
> Ken
> 
 
 
 
 
 
 
 
 
 
 
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