Amibroker-OLE-Interface
view release on metacpan or search on metacpan
lib/Amibroker/OLE/Interface.pm view on Meta::CPAN
my $obj = Amibroker::OLE::Interface->new( { verbose => 1,
dbpath => "C:/amibroker/dbpath"
} );
$obj->start_amibroker_engine();
$obj->run_analysis( { action => 2,
symbol => 'NIFTY-I',
apx_file => 'C:/amibroker/apx/path/nifty.apx',
result_file => 'C:/amibroker/result/path/report.csv'} );
$obj->shutdown_amibroker_engine();
=head1 DESCRIPTION
Amibroker is one of the most used Automated trading and charting software in the world.
Visit Amibroker website for information : L<https://www.amibroker.com/>
Amibroker has provided OLE Automation framework, to interact with Amibroker engine from external scripts/programs.
You can refer to the AmiBroker's OLE Automation Object Model guide: L<https://www.amibroker.com/guide/objects.html>
This module will help programmers who use Amibroker to access the objects easily in perl.
=head1 PREREQUISITE
Prerequisite to use this module : You need to have Amibroker v.5 and above (32-bit or 64-bit) installed in your system.
=head2 new()
Constructor to create the object for interacting with Amibroker engine.
The new() class method starts a new instance of an Amibroker OLE Interface object. It returns a reference to this object or undef if the creation failed.
Eg: Amibroker::OLE::Interface->new()
=over 1
=item B<Parameters to the constructor>
=back
=over 2
=item * Verbose is optional
=item * dbpath is compulsory - dbpath should be valid Amibroker database path.
For how to create database, please check here : L<https://www.amibroker.com/guide/w_dbsettings.html>
Code Example
$obj = Amibroker::OLE::Interface->new( verbose => 1, dbpath => "C:/amibroker/dbpath");
=back
=cut
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)
( run in 2.844 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )