@@ -77,104 +77,104 @@ private <T extends Quote> Mono<CommonStatisticsDto> calcStatistics(List<T> quote
77
77
78
78
<T extends Quote > void calcStatistics5Years (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
79
79
List <T > quotes5Year = quotes .stream ()
80
- .filter (myQuote -> myQuote .getCreatedAt ().after (this .createBeforeDate (0 , 5 ))).toList ();
80
+ .filter (myQuote -> myQuote .getCreatedAt ().after (StatisticService .createBeforeDate (0 , 5 ))).toList ();
81
81
commonStatisticsDto .setRange5Year (
82
- new RangeDto (this .getMinMaxValue (quotes5Year , false ), this .getMinMaxValue (quotes5Year , true )));
83
- commonStatisticsDto .setPerformance5Year (this .calcPerformance (quotes5Year ));
84
- commonStatisticsDto .setAvgVolume5Year (this .calcAvgVolume (quotes5Year ));
85
- commonStatisticsDto .setVolatility5Year (this .calcVolatility (quotes5Year ));
82
+ new RangeDto (StatisticService .getMinMaxValue (quotes5Year , false ), StatisticService .getMinMaxValue (quotes5Year , true )));
83
+ commonStatisticsDto .setPerformance5Year (StatisticService .calcPerformance (quotes5Year ));
84
+ commonStatisticsDto .setAvgVolume5Year (StatisticService .calcAvgVolume (quotes5Year ));
85
+ commonStatisticsDto .setVolatility5Year (StatisticService .calcVolatility (quotes5Year ));
86
86
}
87
87
88
88
<T extends Quote > void calcStatistics2Years (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
89
89
List <T > quotes2Year = quotes .stream ()
90
- .filter (myQuote -> myQuote .getCreatedAt ().after (this .createBeforeDate (0 , 2 ))).toList ();
90
+ .filter (myQuote -> myQuote .getCreatedAt ().after (StatisticService .createBeforeDate (0 , 2 ))).toList ();
91
91
commonStatisticsDto .setRange2Year (
92
- new RangeDto (this .getMinMaxValue (quotes2Year , false ), this .getMinMaxValue (quotes2Year , true )));
93
- commonStatisticsDto .setPerformance2Year (this .calcPerformance (quotes2Year ));
94
- commonStatisticsDto .setAvgVolume2Year (this .calcAvgVolume (quotes2Year ));
95
- commonStatisticsDto .setVolatility2Year (this .calcVolatility (quotes2Year ));
92
+ new RangeDto (StatisticService .getMinMaxValue (quotes2Year , false ), StatisticService .getMinMaxValue (quotes2Year , true )));
93
+ commonStatisticsDto .setPerformance2Year (StatisticService .calcPerformance (quotes2Year ));
94
+ commonStatisticsDto .setAvgVolume2Year (StatisticService .calcAvgVolume (quotes2Year ));
95
+ commonStatisticsDto .setVolatility2Year (StatisticService .calcVolatility (quotes2Year ));
96
96
}
97
97
98
98
<T extends Quote > void calcStatistics1Year (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
99
99
List <T > quotes1Year = quotes .stream ()
100
- .filter (myQuote -> myQuote .getCreatedAt ().after (this .createBeforeDate (0 , 1 ))).toList ();
100
+ .filter (myQuote -> myQuote .getCreatedAt ().after (StatisticService .createBeforeDate (0 , 1 ))).toList ();
101
101
commonStatisticsDto .setRange1Year (
102
- new RangeDto (this .getMinMaxValue (quotes1Year , false ), this .getMinMaxValue (quotes1Year , true )));
103
- commonStatisticsDto .setPerformance1Year (this .calcPerformance (quotes1Year ));
104
- commonStatisticsDto .setAvgVolume1Year (this .calcAvgVolume (quotes1Year ));
105
- commonStatisticsDto .setVolatility1Year (this .calcVolatility (quotes1Year ));
102
+ new RangeDto (StatisticService .getMinMaxValue (quotes1Year , false ), StatisticService .getMinMaxValue (quotes1Year , true )));
103
+ commonStatisticsDto .setPerformance1Year (StatisticService .calcPerformance (quotes1Year ));
104
+ commonStatisticsDto .setAvgVolume1Year (StatisticService .calcAvgVolume (quotes1Year ));
105
+ commonStatisticsDto .setVolatility1Year (StatisticService .calcVolatility (quotes1Year ));
106
106
}
107
107
108
108
<T extends Quote > void calcStatistics6Months (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
109
109
List <T > quotes6Month = quotes .stream ()
110
- .filter (myQuote -> myQuote .getCreatedAt ().after (this .createBeforeDate (6 , 0 ))).toList ();
111
- commonStatisticsDto .setPerformance6Month (this .calcPerformance (quotes6Month ));
112
- commonStatisticsDto .setAvgVolume6Month (this .calcAvgVolume (quotes6Month ));
113
- commonStatisticsDto .setVolatility6Month (this .calcVolatility (quotes6Month ));
110
+ .filter (myQuote -> myQuote .getCreatedAt ().after (StatisticService .createBeforeDate (6 , 0 ))).toList ();
111
+ commonStatisticsDto .setPerformance6Month (StatisticService .calcPerformance (quotes6Month ));
112
+ commonStatisticsDto .setAvgVolume6Month (StatisticService .calcAvgVolume (quotes6Month ));
113
+ commonStatisticsDto .setVolatility6Month (StatisticService .calcVolatility (quotes6Month ));
114
114
commonStatisticsDto .setRange6Month (
115
- new RangeDto (this .getMinMaxValue (quotes6Month , false ), this .getMinMaxValue (quotes6Month , true )));
115
+ new RangeDto (StatisticService .getMinMaxValue (quotes6Month , false ), StatisticService .getMinMaxValue (quotes6Month , true )));
116
116
}
117
117
118
118
<T extends Quote > void calcStatistics3Months (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
119
119
List <T > quotes3Month = quotes .stream ()
120
- .filter (myQuote -> myQuote .getCreatedAt ().after (this .createBeforeDate (3 , 0 ))).toList ();
120
+ .filter (myQuote -> myQuote .getCreatedAt ().after (StatisticService .createBeforeDate (3 , 0 ))).toList ();
121
121
commonStatisticsDto .setRange3Month (
122
- new RangeDto (this .getMinMaxValue (quotes3Month , false ), this .getMinMaxValue (quotes3Month , true )));
123
- commonStatisticsDto .setPerformance3Month (this .calcPerformance (quotes3Month ));
124
- commonStatisticsDto .setAvgVolume3Month (this .calcAvgVolume (quotes3Month ));
125
- commonStatisticsDto .setVolatility3Month (this .calcVolatility (quotes3Month ));
122
+ new RangeDto (StatisticService .getMinMaxValue (quotes3Month , false ), StatisticService .getMinMaxValue (quotes3Month , true )));
123
+ commonStatisticsDto .setPerformance3Month (StatisticService .calcPerformance (quotes3Month ));
124
+ commonStatisticsDto .setAvgVolume3Month (StatisticService .calcAvgVolume (quotes3Month ));
125
+ commonStatisticsDto .setVolatility3Month (StatisticService .calcVolatility (quotes3Month ));
126
126
}
127
127
128
128
<T extends Quote > void calcStatistics1Month (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
129
- Date beforeDate = this .createBeforeDate (1 , 0 );
129
+ Date beforeDate = StatisticService .createBeforeDate (1 , 0 );
130
130
List <T > quotes1Month = quotes .stream ()
131
131
.filter (myQuote -> myQuote .getCreatedAt ().after (beforeDate )).toList ();
132
132
commonStatisticsDto .setRange1Month (
133
- new RangeDto (this .getMinMaxValue (quotes1Month , false ), this .getMinMaxValue (quotes1Month , true )));
134
- commonStatisticsDto .setAvgVolume1Month (this .calcAvgVolume (quotes1Month ));
135
- commonStatisticsDto .setPerformance1Month (this .calcPerformance (quotes1Month ));
136
- commonStatisticsDto .setVolatility1Month (this .calcVolatility (quotes1Month ));
133
+ new RangeDto (StatisticService .getMinMaxValue (quotes1Month , false ), StatisticService .getMinMaxValue (quotes1Month , true )));
134
+ commonStatisticsDto .setAvgVolume1Month (StatisticService .calcAvgVolume (quotes1Month ));
135
+ commonStatisticsDto .setPerformance1Month (StatisticService .calcPerformance (quotes1Month ));
136
+ commonStatisticsDto .setVolatility1Month (StatisticService .calcVolatility (quotes1Month ));
137
137
}
138
138
139
- private <T extends Quote > BigDecimal calcVolatility (List <T > quotes ) {
139
+ private static <T extends Quote > BigDecimal calcVolatility (List <T > quotes ) {
140
140
final BigDecimal average = quotes .size () < 3 ? BigDecimal .ZERO
141
- : quotes .stream ().map (myQuote -> this .getLastValue (myQuote ))
141
+ : quotes .stream ().map (myQuote -> StatisticService .getLastValue (myQuote ))
142
142
.reduce (BigDecimal .ZERO , (acc , value ) -> acc .add (value ))
143
143
.divide (BigDecimal .valueOf (quotes .size ()), MathContext .DECIMAL128 );
144
- BigDecimal variance = quotes .size () < 3 ? BigDecimal .ZERO : quotes .stream ().map (myQuote -> this .getLastValue (myQuote )).map (lastValue -> lastValue .subtract (average ))
144
+ BigDecimal variance = quotes .size () < 3 ? BigDecimal .ZERO : quotes .stream ().map (myQuote -> StatisticService .getLastValue (myQuote )).map (lastValue -> lastValue .subtract (average ))
145
145
.map (avgDifference -> avgDifference .multiply (avgDifference ))
146
146
.reduce (BigDecimal .ZERO , (acc , value ) -> acc .add (value )).divide (BigDecimal .valueOf (quotes .size ()), MathContext .DECIMAL128 );
147
147
BigDecimal volatility = variance .sqrt (MathContext .DECIMAL128 );
148
148
return volatility ;
149
149
}
150
150
151
- private <T extends Quote > BigDecimal calcAvgVolume (List <T > quotes ) {
151
+ private static <T extends Quote > BigDecimal calcAvgVolume (List <T > quotes ) {
152
152
return quotes .size () < 3 ? BigDecimal .ZERO
153
- : quotes .stream ().map (myQuote -> this .getVolume (myQuote ))
153
+ : quotes .stream ().map (myQuote -> StatisticService .getVolume (myQuote ))
154
154
.reduce (BigDecimal .ZERO , (acc , value ) -> acc .add (value ))
155
155
.divide (BigDecimal .valueOf (quotes .size ()), MathContext .DECIMAL128 );
156
156
}
157
157
158
- private <T extends Quote > BigDecimal getVolume (T myQuote ) {
158
+ private static <T extends Quote > BigDecimal getVolume (T myQuote ) {
159
159
return myQuote instanceof QuoteBs ? ((QuoteBs ) myQuote ).getLast () : ((QuoteBf ) myQuote ).getLast_price ();
160
160
}
161
161
162
- private <T extends Quote > Double calcPerformance (List <T > quotes ) {
162
+ private static <T extends Quote > Double calcPerformance (List <T > quotes ) {
163
163
return quotes .size () < 3 ? 0.0
164
- : ((this .getLastValue (quotes .get (quotes .size ()-1 )).doubleValue () / this .getLastValue (quotes .get (0 )).doubleValue ()) - 1 ) * 100 ;
164
+ : ((StatisticService .getLastValue (quotes .get (quotes .size ()-1 )).doubleValue () / StatisticService .getLastValue (quotes .get (0 )).doubleValue ()) - 1 ) * 100 ;
165
165
}
166
166
167
- private <T extends Quote > BigDecimal getMinMaxValue (List <T > quotes , boolean max ) {
168
- Stream <BigDecimal > valueStream = quotes .stream ().map (myQuote -> this .getLastValue (myQuote ));
167
+ private static <T extends Quote > BigDecimal getMinMaxValue (List <T > quotes , boolean max ) {
168
+ Stream <BigDecimal > valueStream = quotes .stream ().map (myQuote -> StatisticService .getLastValue (myQuote ));
169
169
return max ? valueStream .max (BigDecimal ::compareTo ).orElse (BigDecimal .ZERO )
170
170
: valueStream .min (BigDecimal ::compareTo ).orElse (BigDecimal .ZERO );
171
171
}
172
172
173
- private <T extends Quote > BigDecimal getLastValue (T myQuote ) {
173
+ private static <T extends Quote > BigDecimal getLastValue (T myQuote ) {
174
174
return myQuote instanceof QuoteBs ? ((QuoteBs ) myQuote ).getLast () : ((QuoteBf ) myQuote ).getLast_price ();
175
175
}
176
176
177
- private Date createBeforeDate (int months , int years ) {
177
+ private static Date createBeforeDate (int months , int years ) {
178
178
return Date .from (LocalDate .now ().minusMonths (months ).minusYears (years ).atStartOfDay ()
179
179
.atZone (ZoneId .systemDefault ()).toInstant ());
180
180
}
0 commit comments