@@ -21,37 +21,38 @@ export class TwoSidedExponentialAverage extends SeriesSmoothing {
21
21
22
22
let last_sum = 0
23
23
let last_weight = 0
24
+ let last_step = ind . series [ 0 ] . step
24
25
for ( let j = 0 ; j < ind . series . length ; j ++ ) {
25
- f_sum . push ( last_sum * smoothingFactor + ind . series [ j ] . value )
26
- f_weights . push ( last_weight * smoothingFactor + 1 )
26
+ let smooth_gap = Math . pow ( smoothingFactor , Math . abs ( ind . series [ j ] . step - last_step ) )
27
+ f_sum . push ( last_sum * smooth_gap + ind . series [ j ] . value )
28
+ f_weights . push ( last_weight * smooth_gap + 1 )
27
29
28
30
last_sum = f_sum [ j ]
29
31
last_weight = f_weights [ j ]
32
+ last_step = ind . series [ j ] . step
30
33
}
31
34
32
35
last_sum = 0
33
36
last_weight = 0
37
+ last_step = ind . series [ ind . series . length - 1 ] . step
34
38
for ( let j = ind . series . length - 1 ; j >= 0 ; j -- ) {
35
- b_sum . push ( last_sum * smoothingFactor + ind . series [ j ] . value )
36
- b_weights . push ( last_weight * smoothingFactor + 1 )
39
+ let smooth_gap = Math . pow ( smoothingFactor , Math . abs ( ind . series [ j ] . step - last_step ) )
40
+ b_sum . push ( last_sum * smooth_gap + ind . series [ j ] . value )
41
+ b_weights . push ( last_weight * smooth_gap + 1 )
37
42
38
43
last_sum = b_sum [ b_sum . length - 1 ]
39
44
last_weight = b_weights [ b_weights . length - 1 ]
45
+ last_step = ind . series [ j ] . step
40
46
}
41
47
b_weights . reverse ( )
42
48
b_sum . reverse ( )
43
49
44
- for ( let j = 0 ; j < ind . series . length - 1 ; j ++ ) {
45
- let smoothed = ( f_sum [ j ] + smoothingFactor * b_sum [ j + 1 ] ) /
46
- ( f_weights [ j ] + smoothingFactor * b_weights [ j + 1 ] )
50
+ for ( let j = 0 ; j < ind . series . length ; j ++ ) {
51
+ let smoothed = ( f_sum [ j ] + b_sum [ j ] - ind . series [ j ] . value ) /
52
+ ( f_weights [ j ] + b_weights [ j ] - 1 )
47
53
result . push ( { step : ind . series [ j ] . step , value : ind . series [ j ] . value ,
48
54
smoothed : smoothed , lastStep : ind . series [ j ] . lastStep } )
49
55
}
50
- result . push ( { step : ind . series [ ind . series . length - 1 ] . step , value : ind . series [ ind . series . length - 1 ] . value ,
51
- smoothed : f_sum [ ind . series . length - 1 ] / f_weights [ ind . series . length - 1 ] ,
52
- lastStep : ind . series [ ind . series . length - 1 ] . lastStep } )
53
-
54
-
55
56
56
57
ind . series = result
57
58
}
0 commit comments