OK, this works. Batch optimizer with cycling date range and multiple
files. Outputs full optimization reports for each test with formula
name and date range in title.
Balin
/*Batch Optimizer
Batch Optimizes multiple formulae, cycling each formula through multiple
date ranges
Outputs optimization report for each test with formula name and date
range in title
Before each batch, manually code your desired Filter (ieWatchlist, etc),
the date you
want the tests to begin ("year", in the for init), when you want them to
end (year in middle
of for definition, and the length of each range ("rangeLength").
Put all the formulae you wish to test in one folder and enter the folder
name in the first line
of the script. Run the .js and come back when it is all done. Take up
golf.
*/
BatchOptimizeFolder="C:\\Program Files\\Amibroker\\BatchOpt";
WScript.Echo("Batch Optimizer Variable Date Ranges.js ");
var AB,AA;
var year,rangeLength;
var fileName,reportName;
var fileSysObj, folder, folderCount;
AB=new ActiveXObject("Broker.Application");
AA=AB.Analysis;
AA.ClearFilters();
AA.RangeMode=3; // 3: from-to date
AA.ApplyTo=2; // 2: Use filters
AA.Filter(0,"WatchList") = 13; // 0: include watchlist #:
//AA.LoadSettings("C:\\.....\\SettingFilexxx");
rangeLength=2;
for ( year=2000; year<2005; year=year+rangeLength )
{
fromDate=new Date(year,00,01);
toDate=new Date(year+rangeLength,00,01);
AA.RangeFromDate= fromDate.getVarDate();
AA.RangeToDate= toDate.getVarDate();
fileSysObj=new ActiveXObject ("Scripting.FileSystemObject");
folder= fileSysObj.GetFolder(BatchOptimizeFolder);
folderCount=new Enumerator (folder.files);
for ( ; !folderCount.atEnd(); folderCount.moveNext() )
{
fileName= "" + folderCount.item();
if (fileName.substr(fileName.length-4).toUpperCase() == ".AFL")
{
if (AA.LoadFormula (fileName))
{
AA.Optimize (0); // 0: portfolio 1: individual 2: old
reportName=fileName.substring(0,fileName.length-4) + "-" +year
+"-" + (year+rangeLength)+".html";
AA.Export (reportName);
}
}
}
}
WScript.Echo ("Batch Optimization Completed");