-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stats.java
65 lines (54 loc) · 1.2 KB
/
Stats.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package Monte;
import java.util.ArrayList;
public class Stats {
ArrayList<Double>_initial;//initial arraylist of payouts zero
int curr_iter; // current iteration idx
double mu;
double sigma;
double secondMom;
public Stats(){
this._initial= new ArrayList<Double>();
mu = 0;
sigma = 0;
secondMom = 0;
curr_iter = 0;
}
public void setExpectation(ArrayList<Double> initial){
this._initial = initial;
double sum = 0;
for(int n = 0; n < initial.size(); n++){
sum += initial.get(n);
}
this.mu = sum/initial.size();
}
public void setSigma(){
this.sigma = Math.sqrt(secondMom-mu*mu);
}
public double getExpectation(){
return this.mu;
}
public double getSigma(){
return this.sigma;
}
public double getSecondMoments(){
return this.secondMom;
}
public int getTimes(){
return this.curr_iter;
}
public void newstats(double newPayout){
_initial.add(newPayout);
curr_iter++;
if(curr_iter == 1){
mu = newPayout;
sigma = 0;
return;
}
this.mu =( mu * (curr_iter-1) + newPayout)/(curr_iter);
double r = 0;
for(int i =0; i < curr_iter; i++){
r = r + (_initial.get(i) - mu) * (_initial.get(i) - mu);
}
sigma = Math.sqrt(r/curr_iter);
}
}