line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::TW::TAIFEX::Product; |
2
|
4
|
|
|
4
|
|
26
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
141
|
|
3
|
4
|
|
|
4
|
|
27
|
use Any::Moose; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
48
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Finance::TW::TAIFEX::Contract - Product on TAIFEX |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 METHODS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with any_moose('X::Traits'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has name => (is => "ro", isa => "Str"); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has exchange => (is => "ro", isa => "Finance::TW::TAIFEX"); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has '+_trait_namespace' => ( default => 'Finance::TW::TAIFEX' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _near_term { |
22
|
4
|
|
|
4
|
|
8
|
my ($self, $date) = @_; |
23
|
4
|
|
|
|
|
16
|
my $settlement = $self->find_settlement_day($date); |
24
|
4
|
100
|
|
|
|
19
|
if ( $date->day > $settlement->day ) { |
25
|
2
|
|
|
|
|
26
|
$settlement = $settlement->add( months => 1); |
26
|
|
|
|
|
|
|
} |
27
|
4
|
|
|
|
|
1282
|
return $settlement; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 near_term DATE |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Returns the near term contract of the product at DATE in YYYYMM format. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub near_term { |
37
|
4
|
|
|
4
|
1
|
4845
|
my ($self, $date) = @_; |
38
|
4
|
|
|
|
|
22
|
return $self->_near_term($date)->strftime('%Y%m'); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 near_term_contract DATE |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns the near term contract object for product at DATE. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub near_term_contract { |
48
|
0
|
|
|
0
|
1
|
0
|
my ($self, $date) = @_; |
49
|
0
|
|
|
|
|
0
|
my $near_term = $self->_near_term($date); |
50
|
0
|
|
|
|
|
0
|
return Finance::TW::TAIFEX::Contract->new( |
51
|
|
|
|
|
|
|
product => $self, |
52
|
|
|
|
|
|
|
year => $near_term->year, |
53
|
|
|
|
|
|
|
month => $near_term->month); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 find_settlement_day DATE |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Find the settlement day of the near term contract at DATE. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub find_settlement_day { |
63
|
6
|
|
|
6
|
1
|
409
|
my ($self, $date) = @_; |
64
|
6
|
|
|
|
|
30
|
my $settlement = $self->default_settlement_day($date); |
65
|
|
|
|
|
|
|
|
66
|
6
|
|
|
|
|
4594
|
while (!$self->exchange->is_trading_day($settlement)) { |
67
|
20
|
|
|
|
|
128
|
$settlement->add( days => 1 ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
57
|
return $settlement |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
74
|
4
|
|
|
4
|
|
4064
|
no Any::Moose; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
22
|
|
75
|
|
|
|
|
|
|
1; |