@@ -77,104 +77,104 @@ private <T extends Quote> Mono<CommonStatisticsDto> calcStatistics(List<T> quote
7777
7878 <T extends Quote > void calcStatistics5Years (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
7979 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 ();
8181 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 ));
8686 }
8787
8888 <T extends Quote > void calcStatistics2Years (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
8989 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 ();
9191 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 ));
9696 }
9797
9898 <T extends Quote > void calcStatistics1Year (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
9999 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 ();
101101 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 ));
106106 }
107107
108108 <T extends Quote > void calcStatistics6Months (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
109109 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 ));
114114 commonStatisticsDto .setRange6Month (
115- new RangeDto (this .getMinMaxValue (quotes6Month , false ), this .getMinMaxValue (quotes6Month , true )));
115+ new RangeDto (StatisticService .getMinMaxValue (quotes6Month , false ), StatisticService .getMinMaxValue (quotes6Month , true )));
116116 }
117117
118118 <T extends Quote > void calcStatistics3Months (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
119119 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 ();
121121 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 ));
126126 }
127127
128128 <T extends Quote > void calcStatistics1Month (List <T > quotes , CommonStatisticsDto commonStatisticsDto ) {
129- Date beforeDate = this .createBeforeDate (1 , 0 );
129+ Date beforeDate = StatisticService .createBeforeDate (1 , 0 );
130130 List <T > quotes1Month = quotes .stream ()
131131 .filter (myQuote -> myQuote .getCreatedAt ().after (beforeDate )).toList ();
132132 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 ));
137137 }
138138
139- private <T extends Quote > BigDecimal calcVolatility (List <T > quotes ) {
139+ private static <T extends Quote > BigDecimal calcVolatility (List <T > quotes ) {
140140 final BigDecimal average = quotes .size () < 3 ? BigDecimal .ZERO
141- : quotes .stream ().map (myQuote -> this .getLastValue (myQuote ))
141+ : quotes .stream ().map (myQuote -> StatisticService .getLastValue (myQuote ))
142142 .reduce (BigDecimal .ZERO , (acc , value ) -> acc .add (value ))
143143 .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 ))
145145 .map (avgDifference -> avgDifference .multiply (avgDifference ))
146146 .reduce (BigDecimal .ZERO , (acc , value ) -> acc .add (value )).divide (BigDecimal .valueOf (quotes .size ()), MathContext .DECIMAL128 );
147147 BigDecimal volatility = variance .sqrt (MathContext .DECIMAL128 );
148148 return volatility ;
149149 }
150150
151- private <T extends Quote > BigDecimal calcAvgVolume (List <T > quotes ) {
151+ private static <T extends Quote > BigDecimal calcAvgVolume (List <T > quotes ) {
152152 return quotes .size () < 3 ? BigDecimal .ZERO
153- : quotes .stream ().map (myQuote -> this .getVolume (myQuote ))
153+ : quotes .stream ().map (myQuote -> StatisticService .getVolume (myQuote ))
154154 .reduce (BigDecimal .ZERO , (acc , value ) -> acc .add (value ))
155155 .divide (BigDecimal .valueOf (quotes .size ()), MathContext .DECIMAL128 );
156156 }
157157
158- private <T extends Quote > BigDecimal getVolume (T myQuote ) {
158+ private static <T extends Quote > BigDecimal getVolume (T myQuote ) {
159159 return myQuote instanceof QuoteBs ? ((QuoteBs ) myQuote ).getLast () : ((QuoteBf ) myQuote ).getLast_price ();
160160 }
161161
162- private <T extends Quote > Double calcPerformance (List <T > quotes ) {
162+ private static <T extends Quote > Double calcPerformance (List <T > quotes ) {
163163 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 ;
165165 }
166166
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 ));
169169 return max ? valueStream .max (BigDecimal ::compareTo ).orElse (BigDecimal .ZERO )
170170 : valueStream .min (BigDecimal ::compareTo ).orElse (BigDecimal .ZERO );
171171 }
172172
173- private <T extends Quote > BigDecimal getLastValue (T myQuote ) {
173+ private static <T extends Quote > BigDecimal getLastValue (T myQuote ) {
174174 return myQuote instanceof QuoteBs ? ((QuoteBs ) myQuote ).getLast () : ((QuoteBf ) myQuote ).getLast_price ();
175175 }
176176
177- private Date createBeforeDate (int months , int years ) {
177+ private static Date createBeforeDate (int months , int years ) {
178178 return Date .from (LocalDate .now ().minusMonths (months ).minusYears (years ).atStartOfDay ()
179179 .atZone (ZoneId .systemDefault ()).toInstant ());
180180 }
0 commit comments