Framework/Utils/Builder.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 93 CC 4 SCAR 13.4
CC
4
Cov
0%
build_asset
12.0
build_trading_calendar
6.0
build_expiry_conventions
2.0
CRAP 3.8
1 package Quant::Framework::Utils::Builder;
2 use 5.010;
3  
4 use strict;
5 use warnings;
6  
7 use Moose;
8  
9 use List::Util qw( min );
10 use Quant::Framework::TradingCalendar;
11 use Quant::Framework::InterestRate;
12 use Quant::Framework::Currency;
13 use Quant::Framework::Asset;
14 use Quant::Framework::Dividend;
15 use Quant::Framework::ExpiryConventions;
16 use Quant::Framework::Utils::UnderlyingConfig;
17  
18 =head2 for_date
19  
20 The date for which we wish data
21  
22 =cut
23  
24 has for_date => (
25 is => 'ro',
26 isa => 'Maybe[Date::Utility]',
27 default => undef,
28 );
29  
30 =head2 chronicle_reader
31  
32 Instance of Data::Chronicle::Reader for reading data
33  
34 =cut
35  
36 has chronicle_reader => (
37 is => 'ro',
38 isa => 'Data::Chronicle::Reader',
39 );
40  
41 =head2 chronicle_writer
42  
43 Instance of Data::Chronicle::Writer to write data to
44  
45 =cut
46  
47 has chronicle_writer => (
48 is => 'ro',
49 isa => 'Data::Chronicle::Writer',
50 );
51  
52 =head2 underlying_config
53  
54 UnderlyingConfig used to create/initialize Q::F modules
55  
56 =cut
57  
58 has underlying_config => (
59 is => 'ro',
60 isa => 'Quant::Framework::Utils::UnderlyingConfig',
61 );
62  
63 =head2 build_expiry_conventions
64  
65 Creates a default instance of ExpiryConventions according to current parameters (chronicle, for_date, underlying_config)
66  
67 =cut
68  
69 sub build_expiry_conventions {
70 my $self = shift;
71  
72 my $quoted_currency = Quant::Framework::Currency->new({
73 symbol => $self->underlying_config->quoted_currency_symbol,
74 for_date => $self->for_date,
75 chronicle_reader => $self->chronicle_reader,
76 chronicle_writer => $self->chronicle_writer,
77 });
78  
79 return Quant::Framework::ExpiryConventions->new({
80 chronicle_reader => $self->chronicle_reader,
81 is_forex_market => $self->underlying_config->market_name eq 'forex',
82 symbol => $self->underlying_config->symbol,
83 for_date => $self->for_date,
84 asset => $self->build_asset,
85 quoted_currency => $quoted_currency,
86 asset_symbol => $self->underlying_config->asset_symbol,
87 calendar => $self->build_trading_calendar,
88 });
89 }
90  
91 =head2 build_trading_calendar
92  
93 Creates a default instance of TradingCalendar according to current parameters (chronicle, for_date, underlying_config)
94  
95 =cut
96  
97 sub build_trading_calendar {
98 my $self = shift;
99  
100 return Quant::Framework::TradingCalendar->new({
101 symbol => $self->underlying_config->exchange_name,
102 chronicle_reader => $self->chronicle_reader,
103 ($self->underlying_config->locale) ? (locale => $self->underlying_config->locale) : (),
104 for_date => $self->for_date,
105 underlying_config => $self->underlying_config,
106 });
107 }
108  
109 =head2 build_interest_rate
110  
111 Creates an instance of InterestRate module using current configuration
112  
113 =cut
114  
115 sub build_interest_rate {
116 my $self = shift;
117  
118 return Quant::Framework::InterestRate->new({
119 symbol => $self->underlying_config->symbol,
120 underlying_config => $self->underlying_config,
121 for_date => $self->for_date,
122 chronicle_reader => $self->chronicle_reader,
123 chronicle_writer => $self->chronicle_writer,
124 });
125 }
126  
127 =head2 build_dividend
128  
129 Creates a default instance of Dividend according to current parameters (chronicle, for_date, underlying_config)
130  
131 =cut
132  
133 sub build_dividend {
134 my $self = shift;
135  
136 return Quant::Framework::Dividend->new({
137 symbol => $self->underlying_config->symbol,
138 underlying_config => $self->underlying_config,
139 for_date => $self->for_date,
140 chronicle_reader => $self->chronicle_reader,
141 chronicle_writer => $self->chronicle_writer,
142 });
143 }
144  
145 =head2 build_asset
146  
147 Creates a default instance of Asset/Currency according to current parameters (chronicle, for_date, underlying_config)
148  
149 =cut
150  
151 sub build_asset {
152 my $self = shift;
153  
154 return unless $self->underlying_config->asset_symbol;
155 my $type = $self->underlying_config->asset_class;
156  
157 my $which = $type eq 'currency' ? 'Quant::Framework::Currency' : 'Quant::Framework::Asset';
158  
159 return $which->new({
160 symbol => $self->underlying_config->asset_symbol,
161 for_date => $self->for_date,
162 chronicle_reader => $self->chronicle_reader,
163 chronicle_writer => $self->chronicle_writer,
164 });
165 }
166  
167 =head2 build_currency
168  
169 Creates a default instance of Currency according to current parameters (chronicle, for_date, underlying_config)
170  
171 =cut
172  
173 sub build_currency {
174 my $self = shift;
175  
176 return Quant::Framework::Currency->new({
177 symbol => $self->underlying_config->asset_symbol,
178 for_date => $self->for_date,
179 chronicle_reader => $self->chronicle_reader,
180 chronicle_writer => $self->chronicle_writer,
181 });
182 }
183  
184 1;