GT::Tools - Various helper functions


This modules provides several helper functions that can be used in all modules and scripts.

There are 5 groupings


It provides mathematical functions, that can be imported with use GT::Tools qw(:math) :


Returns PI.


Returns the minimum of all given arguments.


Returns the maximum of all given arguments.


Returns 1 for a positive (or null) value, -1 for a negative value.


It provides helper functions to manage arguments in "Generic" objects. You can import those functions with use GT::Tools qw(:generic) :


Returns the number associated to the first the object described by the arguments.


And a few other very-specific functions :

use GT::Tools qw(:conf) :


Return the long name of the system as described in the configuration file.

resolve_object_alias($alias, @param)

Return the complete description of the object designed by "alias". @param is the array of parameters as returned by GT::ArgsTree::parse_args().

Object aliases can be defined in global files (as defined in the option Path::Aliases::<object_kind>), for each kind of object (e.g., Signals, Indicators, etc.), or in user-specific files (~/.gt/aliases/<object_kind>).

Such aliases are defined via the syntax <alias_name> <definition>

For example MyMean { I:Generic:Eval ( #1 + #2 ) / 2 }

An object alias can also be defined in the option file with the syntax Aliases::<object_kind>::<alias_name> <definition>

For example:

 Aliases::Indicators::MyMean  { I:Generic:Eval ( #1 + #2 ) / 2 }

Then you can use this alias in any other place where you could have used a standard indicator as argument. Here's how you would reference it with custom parameters :

 { @I:MyMean 50 {I:RSI} }

If you don't need any parameters then you can just say "@I:MyMean".

my $l = long_name($short)
my $s = short_name($long)

Most module names can be shortened with some standard abreviations. Those functions let you switch between the long and the short version of the names. The recognized abreviations are :


use GT::Tools qw(:isin) :


This computes the checksum of a given code. The whole ISIN is returned.


Validate the ISIN and its checksum.


use GT::Tools qw(:timeframe) :

GetTimeFrameData ($code, $timeframe, $db, $max_loaded_items)

Returns a prices and a calculator object with data for the required $code in the specified $timeframe. It uses $db object to fetch the data. If for instance, weekly data is requested, but only daily data is available, the weekly data is calculated from the daily data.

Optionally, you can set the configuration file directive DB::timeframes_available to specify which timeframes are available. For instance: DB::timeframes_available 5min,hour,day

parse_date_str ( \$date_string, \$err_msg )

Returns 1 if \$date_string is valid parsable date, zero (or null) otherwise \$date_string will be altered to be a gt compliant date string on return \$err_msg is optional

If the user has Date::Manip installed it allows the use of date strings that can be parsed by Date::Manip in addition the to defacto standard date-time format accepted by GT (YYYY-MM-DD HH:MM:SS) time part is optional

Date::Manip is not required, without it users cannot use short-cuts to specify date strings. such short cuts include --start '6 months ago' --end 'today'

The date string checking includes verifying the date string format is valid and the date is a valid date (and time if provided)

Errors will be displayed and the script will terminate.

Application usage examples:

with Date::Manip installed

 % --timeframe day --start '6 months ago' \
         --end 'today' market_file 'today' system_file

without Date::Manip you will need to use:

 % --timeframe day --start 2007-04-24 \
         --end 2007-10-24 market_file 2007-10-24 system_file
 % --timeframe week --start 2007-04-24 
         --end 2007-10-24 market_file 2007-10-24 system_file

Usage of parse_date_str in application script

  use GT::Tools qw( :timeframe );  
  # tag name to get &parse_date_str visibility
  my $err_msg;
  # get date string from command line
  my $date = shift;
  my ( $d_yr, $d_mn, $d_dy, $d_tm );
  if ( ! parse_date_str( \$date, \$err_msg ) ) {
    die "Error: $err_msg\n";
  } else {
    ( $d_yr, $d_mn, $d_dy, $d_tm ) = split /[- ]/, $date;
find_calculator($code, $timeframe, $full, $start, $end, $nb_item, $max_loaded_item)

Find a calculator: Returns $calc (the calculator), as well as $first and $last (indices used by the calculator).

The interval examined (bound by $first and $last) is computed as follows (stop whenever $first and $last have been determined): 1. if present, use --start (otherwise default $first to 2 years back) and --end (otherwise default $last to last price) 2. use --nb-item (from first or last, whichever has been determined), if present 3. use first or last price, whichever has not yet been determined, if --full is present 4. otherwise, use two years worth of data.

Note that the values given to --start and --end are relative to the selected time frame (i.e., if timeframe is "day", these indicate a date; if timeframe is "week", these indicate a week; etc.). Format is "YYYY-MM-DD" for dates, "YYYY-WW" for weeks, "YYYY-MM" for months, and "YYYY" for years.

check_dates($timeframe, $start, $end, $date)

Converts the given dates into the proper dates relative to the chosen time frame, if necessary. For example, if a date 2000-02-01 is given with --timeframe=week, this date is converted to 2000-05.

Verifies that the start date is before the end.

If a third date is given, verifies that this date is between the start and end dates.