The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Finance::GeniusTrader::Tools - Various helper functions

DESCRIPTION

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

There are 5 groupings

  • math -- min, max, pi, sign

  • generic -- extract_object_number

  • conf -- resolve_alias resolve_object_alias long_name short_name

  • isin -- isin_checksum isin_validate isin_create_from_local

  • timeframe -- get_timeframe_data parse_date_str find_calculator check_dates

math

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

PI()

Returns PI.

min(...)

Returns the minimum of all given arguments.

max(...)

Returns the maximum of all given arguments.

sign($value)

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

generic

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

extract_object_number(@args)

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

conf

And a few other very-specific functions :

use Finance::GeniusTrader::Tools qw(:conf) :

resolve_alias($alias)

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 Finance::GeniusTrader::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 :

  • Analyzers:: = A:

  • CloseStrategy:: = CS:

  • Generic:: = G:

  • Indicators:: = I:

  • MoneyManagement:: = MM:

  • OrderFactory:: = OF:

  • Signals:: = S:

  • Systems:: = SY:

  • TradeFilters:: = TF:

isin

use Finance::GeniusTrader::Tools qw(:isin) :

isin_checksum($code)

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

isin_validate($isin)

Validate the ISIN and its checksum.

timeframe

use Finance::GeniusTrader::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

  • input params must be references to the object

  • if called in void context with bad date value the internal error handling will put error message text on stderr and die called

  • date ref var may be altered to conform to std date-time format

  • error string will contain details about bad date-time string

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

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

without Date::Manip you will need to use:

 %    scan.pl --timeframe day --start 2007-04-24 \
         --end 2007-10-24 market_file 2007-10-24 system_file

 or

 %    scan.pl --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 Finance::GeniusTrader::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.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 592:

You forgot a '=back' before '=head3'

Around line 628:

'=item' outside of any '=over'