| 1 | package Finance::GeniusTrader::DateTime::Week; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # This file is distributed under the terms of the General Public License | ||
| 5 | # version 2 or (at your option) any later version. | ||
| 6 | |||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use vars qw(); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use Finance::GeniusTrader::DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 0 | ▶ | use Date::Calc qw(Week_of_Year Monday_of_Week); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | #ALL# use Log::Log4perl qw(:easy); | ||
| 13 | use Time::Local; | ||
| 14 | |||
| 15 | =head1 Finance::GeniusTrader::DateTime::Week | ||
| 16 | |||
| 17 | This module treat dates describing a week. They have the following format : | ||
| 18 | YYYY-WW | ||
| 19 | |||
| 20 | WW being the week number. | ||
| 21 | |||
| 22 | =cut | ||
| 23 | sub map_date_to_time { | ||
| 24 | my ($date) = @_; | ||
| 25 | my ($y, $w) = split /-/, $date; | ||
| 26 | my ($year, $month, $day) = Monday_of_Week($w, $y); | ||
| 27 | return timelocal(0, 0, 0, $day, $month - 1, $year - 1900); | ||
| 28 | } | ||
| 29 | |||
| 30 | sub map_time_to_date { | ||
| 31 | my ($time) = @_; | ||
| 32 | my ($sec, $min, $hour, $d, $m, $y, $wd, $yd) = localtime($time); | ||
| 33 | #DEB# DEBUG "$time => $y-$m-$d"; | ||
| 34 | my ($week, $year) = Week_of_Year($y + 1900, $m + 1, $d); | ||
| 35 | return sprintf("%04d-%02d", $year, $week); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub timeframe_ratio { | ||
| 39 | my ($tf) = @_; | ||
| 40 | |||
| 41 | #WAR# WARN "timeframe must be smaller than a week" unless ($tf < $WEEK); | ||
| 42 | |||
| 43 | $tf == $DAY && return 5; | ||
| 44 | return Finance::GeniusTrader::DateTime::timeframe_ratio($DAY, $tf) * 5; | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; | ||