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

Re: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?


  • To: <amibroker@xxxxxxxxxxxxxxx>
  • Subject: Re: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?
  • From: "Chris DePuy" <cdepuy@xxxxxxxxx>
  • Date: Thu, 10 Jul 2008 15:23:18 -0700

PureBytes Links

Trading Reference Links

Dale and Elizabeth,
 
I think these two script and afl examples should do the trick.  The core of the .js file I started with appears to draw from some of Dale's work posted here in 2006 (I infer that from a comment Joe Landry made when he posted his export .png script).  There is one thing missing from my understanding of this script and I just ran out of time.  For some reason, when I type in iWatchlist = 13, this thing operates on my List 44.  I have no idea why, but the solution is to put the tickers you want into List 44.  I'm sure with some time this can be solved.
 
Best regards
 
 
1) call this file name optimize.js
 
/********************Amibroker open to database***********************/
AB = new ActiveXObject("Broker.Application");
AB.LoadDatabase("C:\\Program Files\\Amibroker\\Big");
AB.Visible = true;
AA=AB.Analysis;
 

iWatchList = 13;
 
Qty = AB.Stocks.Count;
 
for( i = 0; i < Qty; i++ )
{
Stk = AB.Stocks( i );
if( iWatchList < 1 )
{
  if( Stk.WatchListBits & ( 1 << iWatchList ) )
  {
   Doc = AB.Documents.Open( Stk.Ticker );
   WScript.Sleep( 4000 ); // 4 seconds delay
 
/* load formula from external file */
AA.LoadFormula("Formulas\\Custom\\Optimization example\\optimization single stock example.afl");
 
/* optional: load settings */
// AA.LoadSettings("the_path_to_the_settings_file.abs");
 
/* set apply to and range */
AA.ApplyTo = 1; // use current stock
AA.RangeMode = 0; // use all available quotes
//AA.RangeN = 1;
 
/* run explore and display report */
AA.Optimize(); //I cannot remember whether you put a 2
AA.Export("C:\\"+Stk.Ticker + ".csv");  //you'd ideally change this name to the ticker name
 
   Doc.Close();
  }
}
else
{
  if( Stk.WatchListBits2 & ( 1 << ( iWatchList - 1 )) )
  {
   Doc = AB.Documents.Open( Stk.Ticker );
 
/* load formula from external file */
AA.LoadFormula("Formulas\\Custom\\Optimization example\\optimization single stock example.afl");
 
/* optional: load settings */
// AA.LoadSettings("the_path_to_the_settings_file.abs");
 
/* set apply to and range */
AA.ApplyTo = 1; // use current stock
AA.RangeMode = 0; // use all available quotes
//AA.RangeN = 1;
 
/* run explore and display report */
AA.Optimize(); //I cannot remember whether you put a 2
AA.Export("C:\\"+Stk.Ticker + ".csv");  //you'd ideally change this name to the ticker name
   Doc.Close();
 
  }
}
 
}
 
 
2) call this file c:\program files\amibroker\Formulas\Custom\Optimization example\optimization single stock example.afl
per1=Optimize("per1",50,20,100,10);
per2=Optimize("per2",50,20,100,10);
 
Buy = Cover= Cross(MA(C,per1),MA(C,per2));
Sell = Short = Cross(MA(C,per2),MA(C,per1));
 
 
 
----- Original Message -----
From: dingo
Sent: Thursday, July 10, 2008 1:38 PM
Subject: RE: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

contact me off line.
 
d


From: amibroker@xxxxxxxxxps.com [mailto:amibroker@yahoogroups.com] On Behalf Of Chris DePuy
Sent: Thursday, July 10, 2008 4:28 PM
To: amibroker@xxxxxxxxxps.com
Subject: Re: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

d, I've been on this wild goose chase, as I had said in the email below.  Would you care to shed some light on how to script this?
 
----- Original Message -----
From: dingo
Sent: Thursday, July 10, 2008 1:18 PM
Subject: RE: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

I've already got a script to do the job. Just wanted to make sure you weren't sending someone off on  a wild goose chase.
 
d


From: amibroker@xxxxxxxxxps.com [mailto:amibroker@yahoogroups.com] On Behalf Of Chris DePuy
Sent: Thursday, July 10, 2008 4:14 PM
To: amibroker@xxxxxxxxxps.com
Subject: Re: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

dingo, I don't think it'll produce a neat output as I had written it, no.  I haven't done this type of thing in a while, but when I did I recall running each test separately for each ticker and then scrolling to the right to read the report.
 
Creating a .js script that would call each ticker separately and then save the results to a .csv file is one possible solution.  I cannot figure out how to get Amibroker to scroll through the list of stock tickers in a watchlist using the Stock object and then how to rename the report.csv to ticker.csv below.  Besides that, this should work.  (One note, a wild way to do this would be to have a separate ..tls file for each stock and then have amiquote retrieve each .tls file in a directory using Example 2 in http://www.amibroker..com/guide/objects.html ).  If someone wants to chime in here and help with these outstanding issues, that'd be nice.
 
 
/********************Amibroker open to database***********************/
AB = new ActiveXObject("Broker.Application");
AB.LoadDatabase("C:\\Program Files\\Amibroker\\Big");
AB.Visible = true;
 
/* retrieve automatic analysis object */
AA = AB.Analysis;
 
/* here is where you'd call the ticker name*/
 
/* load formula from external file */
AA.LoadFormula("Formulas\\Custom\\yourfilename.afl");
 
/* optional: load settings */
// AA.LoadSettings("the_path_to_the_settings_file.abs");
 
/* set apply to and range */
AA.ApplyTo = 2; // use current stock
AA.RangeMode = 1; // use all available quotes
AA.RangeN = 1;
 
/* run explore and display report */
AA.Optimize(); //I cannot remember whether you put a 2 or something else in here; recent beta docs say something about this, i think
AA.Export("C:\\report.csv");  //you'd ideally change this name to the ticker name
 

/********************Amibroker Save Database***********************/
AB.SaveDatabase();
/********************Amibroker Save Database (end)***********************/
 
AB.Quit();
 
----- Original Message -----
From: dingo
Sent: Thursday, July 10, 2008 12:23 PM
Subject: RE: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

Are you sure that the individually optimized params will appear on the resultant report?
 
d


From: amibroker@xxxxxxxxxps.com [mailto:amibroker@yahoogroups.com] On Behalf Of Chris DePuy
Sent: Thursday, July 10, 2008 3:17 PM
To: amibroker@xxxxxxxxxps.com
Subject: Re: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

Elizabeth, the short answer is yes.  It requires that you call out parameters that are specific to the ticker for each iteration the array processor goes through.
 
So, you'd do something like this for each ticker:
 

if (Name()=="AAPL")

{

period=Optimize("period",53,5,100,8);

}

----- Original Message -----

Sent: Wednesday, July 09, 2008 11:45 PM
Subject: [amibroker] Optimization of basket of stocks at individual stock level - possible with Ami ?

Hello All,

I would greatly appreciate if someone can tell me wheather it is
possible to optimize a basket of stocks at individual stock level using
Amibroker. ie. to get separate optimal parameters for each stock in the
basket.

Thanks in advance

Elizabeth

__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___