Amibroker-OLE-Interface
view release on metacpan or search on metacpan
lib/Amibroker/OLE/Interface.pm view on Meta::CPAN
sub new {
my @list = @_;
my $class = shift @list;
push @list, {} unless @list and _is_arg( $list[-1] );
my $self = _check_valid_args(@list);
croak("No Database path supplied to Amibroker : $!\n")
unless $self->{dbpath};
croak("Invalid Database path to Amibroker : $!\n")
unless -d $self->{dbpath};
bless $self, $class if defined $self;
return $self;
}
=head2 start_amibroker_engine()
Starts the Amibroker Engine and Loads the database
Code Example
$obj->start_amibroker_engine();
=cut
sub start_amibroker_engine {
my $self = shift;
$self->{broker} = Win32::OLE->new('Broker.Application')
or croak("Can't load Broker.Application : $!\n");
print "Amibroker Started\n" if $self->{verbose};
$self->{broker}->LoadDatabase( $self->{dbpath} )
or croak(
"Can't load Database, seems like the format is not supported: $!\n");
print "Database loaded to Amibroker\n" if $self->{verbose};
return 1;
}
=head2 run_analysis()
You can run various analysis based on the action supplied.
But before that you need to pass APX file,
APX file is an important file to Amibroker engine. It is like the rule book to the amibroker.
The analysis project file (.apx extension) is human-readable self-explanatory XML-format file that can be written/edited/modified from any language / any text editor.
APX file includes all settings and formula needed in single file that is required to run analysis.
APX file instructs what the amibroker engine has to do.
NOTE: Be very careful in creating the apx file.
You can either manually create the apx file or by automatically by a script.
There should be no errors in the content of APX file, else the analysis of the Amibroker fails.
How to create apx file manually:
=over 3
=item * Open Amibroker -> Analysis window -> Settings
=item * Edit settings as per your requirement
=item * Menu-> File-> Save_AS -> select (.apx extenstion)
For more infor on apx file, check this forum : L<http://amibrokerforum.proboards.com/thread/57/analysis-project-files-apx>
$obj->run_analysis( action => 2 ) method allows to run asynchronously scan/explorations/backtest/optimizations.
Action parameter can be one of the following values:
0 : Scan
1 : Exploration
2 : Portfolio Backtest
3 : Individual Backtest
4 : Portfolio Optimization
5 : Individual Optimization (supported starting from v5.69)
6 : Walk Forward Test
Symbol would be appended with '-I' => for current month contract future or '-II' for next month contract future
Eg: for Nifty, Symbol would be 'Nifty-I'.
This is just an example, you should check your database for the exact symbol name.
If the Symbol passed to this function is not present in your amibroker database, then the analysis is bound to fail.
result_file is the path where you want to dump the result of the Amibroker analysis.
result_file file should NOT be created manually, it will be created automatically by the Amibroker engine when the analysis runs. You have to just pass the filename with the path.
=back
=over 1
=item B<parameters to run_analysis method>
=back
=over 4
=item * action is compulsory
=item * symbol is compulsory
=item * apx_file is compulsory
=item * result_file is Optional - Default will be stored in C:/result.csv
Code Example
$obj->run_analysis( { action => 2,
symbol => 'NIFTY-I',
apx_file => "C:/amibroker/apx/path/nifty.apx",
result_file => "C:/amibroker/result/path/report.csv"
} );
=back
=cut
sub run_analysis {
my @list = @_;
my $self = shift @list;
my $args = _check_valid_args(@list);
croak("Invalid apx file : $!\n") unless -e $args->{apx_file};
$args->{apx_file} =~ s/\//\\\\/g;
$args->{result_file} =~ s/\//\\\\/g if ( $args->{result_file} );
$self->{broker}->ActiveDocument->{Name} = $args->{symbol};
my $analysis = $self->{broker}->AnalysisDocs->Open( $args->{apx_file} )
( run in 2.351 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )