Framework/Utils/Builder.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 108 CC 3 SCAR 11.8
CC
3
Cov
0%
build_asset
12.0
build_expiry_conventions
2.0
build_trading_calendar
2.0
CRAP 3.2
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::Spot;
17 use Quant::Framework::Spot::DatabaseAPI;
18 use Quant::Framework::Utils::UnderlyingConfig;
19  
20 =head2 for_date
21  
22 The date for which we wish data
23  
24 =cut
25  
26 has for_date => (
27 is => 'ro',
28 isa => 'Maybe[Date::Utility]',
29 default => undef,
30 );
31  
32 =head2 chronicle_reader
33  
34 Instance of Data::Chronicle::Reader for reading data
35  
36 =cut
37  
38 has chronicle_reader => (
39 is => 'ro',
40 isa => 'Data::Chronicle::Reader',
41 );
42  
43 =head2 chronicle_writer
44  
45 Instance of Data::Chronicle::Writer to write data to
46  
47 =cut
48  
49 has chronicle_writer => (
50 is => 'ro',
51 isa => 'Data::Chronicle::Writer',
52 );
53  
54 =head2 underlying_config
55  
56 UnderlyingConfig used to create/initialize Q::F modules
57  
58 =cut
59  
60 has underlying_config => (
61 is => 'ro',
62 isa => 'Quant::Framework::Utils::UnderlyingConfig',
63 );
64  
65 =head2 build_expiry_conventions
66  
67 Creates a default instance of ExpiryConventions according to current parameters (chronicle, for_date, underlying_config)
68  
69 =cut
70  
71 sub build_expiry_conventions {
72 my $self = shift;
73  
74 my $quoted_currency = Quant::Framework::Currency->new({
75 symbol => $self->underlying_config->quoted_currency_symbol,
76 for_date => $self->for_date,
77 chronicle_reader => $self->chronicle_reader,
78 chronicle_writer => $self->chronicle_writer,
79 });
80  
81 return Quant::Framework::ExpiryConventions->new({
82 chronicle_reader => $self->chronicle_reader,
83 is_forex_market => $self->underlying_config->market_name eq 'forex',
84 symbol => $self->underlying_config->symbol,
85 for_date => $self->for_date,
86 asset => $self->build_asset,
87 quoted_currency => $quoted_currency,
88 asset_symbol => $self->underlying_config->asset_symbol,
89 calendar => $self->build_trading_calendar,
90 });
91 }
92  
93 =head2 build_trading_calendar
94  
95 Creates a default instance of TradingCalendar according to current parameters (chronicle, for_date, underlying_config)
96  
97 =cut
98  
99 sub build_trading_calendar {
100 my $self = shift;
101  
102 return Quant::Framework::TradingCalendar->new({
103 symbol => $self->underlying_config->exchange_name,
104 chronicle_reader => $self->chronicle_reader,
105 for_date => $self->for_date,
106 underlying_config => $self->underlying_config,
107 });
108 }
109  
110 =head2 build_interest_rate
111  
112 Creates an instance of InterestRate module using current configuration
113  
114 =cut
115  
116 sub build_interest_rate {
117 my $self = shift;
118  
119 return Quant::Framework::InterestRate->new({
120 symbol => $self->underlying_config->symbol,
121 underlying_config => $self->underlying_config,
122 for_date => $self->for_date,
123 chronicle_reader => $self->chronicle_reader,
124 chronicle_writer => $self->chronicle_writer,
125 });
126 }
127  
128 =head2 build_dividend
129  
130 Creates a default instance of Dividend according to current parameters (chronicle, for_date, underlying_config)
131  
132 =cut
133  
134 sub build_dividend {
135 my $self = shift;
136  
137 return Quant::Framework::Dividend->new({
138 symbol => $self->underlying_config->symbol,
139 underlying_config => $self->underlying_config,
140 for_date => $self->for_date,
141 chronicle_reader => $self->chronicle_reader,
142 chronicle_writer => $self->chronicle_writer,
143 });
144 }
145  
146 =head2 build_asset
147  
148 Creates a default instance of Asset/Currency according to current parameters (chronicle, for_date, underlying_config)
149  
150 =cut
151  
152 sub build_asset {
153 my $self = shift;
154  
155 return unless $self->underlying_config->asset_symbol;
156 my $type = $self->underlying_config->asset_class;
157  
158 my $which = $type eq 'currency' ? 'Quant::Framework::Currency' : 'Quant::Framework::Asset';
159  
160 return $which->new({
161 symbol => $self->underlying_config->asset_symbol,
162 for_date => $self->for_date,
163 chronicle_reader => $self->chronicle_reader,
164 chronicle_writer => $self->chronicle_writer,
165 });
166 }
167  
168 =head2 build_currency
169  
170 Creates a default instance of Currency according to current parameters (chronicle, for_date, underlying_config)
171  
172 =cut
173  
174 sub build_currency {
175 my $self = shift;
176  
177 return Quant::Framework::Currency->new({
178 symbol => $self->underlying_config->asset_symbol,
179 for_date => $self->for_date,
180 chronicle_reader => $self->chronicle_reader,
181 chronicle_writer => $self->chronicle_writer,
182 });
183 }
184  
185 =head2 build_feed_api
186  
187 Returns an instance of Quant::Framework::Spot::DatabaseAPI which can be used
188 to read historical spot values
189  
190 =cut
191  
192 sub build_feed_api {
193 my $self = shift;
194  
195 return Quant::Framework::Spot::DatabaseAPI->new($self->underlying_config->spot_db_args);
196 }
197  
198 =head2 build_spot
199  
200 Returns an instance of Quant::Framework::Spot which can be used to read live or historical
201 spot
202  
203 =cut
204  
205 sub build_spot {
206 my $self = shift;
207  
208 return Quant::Framework::Spot->new({
209 for_date => $self->for_date,
210 underlying_config => $self->underlying_config,
211 calendar => $self->build_trading_calendar,
212 feed_api => $self->build_feed_api,
213 });
214 }
215  
216 1;