-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestnum2.java
More file actions
37 lines (32 loc) · 976 Bytes
/
Copy pathTestnum2.java
File metadata and controls
37 lines (32 loc) · 976 Bytes
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
public class Testnum2{
public static void creatnum(double init, double volatility, double momentum){
double oldPrice = init;
double newPrice =init;
for(int i = 0; i < 365; i++){
oldPrice= newPrice;
double rnd = Math.random();
double changePercent = volatility * rnd;
double newrand = (Math.random() * 10) -5;
double changeAmount;
if ( newrand >= momentum){
changeAmount = oldPrice * (-1 * changePercent/100);
//momentum += (-1 * changePercent/1000);
}
else{
changeAmount = oldPrice * (1 * changePercent/100) ;
//momentum += (1 * changePercent/1000);
}
newPrice = oldPrice + changeAmount ;
/*if (newPrice < MIN_PRICE) {
newPrice += Math.abs(changeAmount) * 2;
} else if (newPrice > MAX_PRICE) {
newPrice -= Math.abs(changeAmount) * 2;
}
*/
System.out.println(newPrice);
}
}
public static void main(String[] args){
creatnum(900,3.0,-0.0);
}
}