-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestnum.java
More file actions
33 lines (27 loc) · 824 Bytes
/
Copy pathTestnum.java
File metadata and controls
33 lines (27 loc) · 824 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
public class Testnum{
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 = 2 * volatility * rnd;
if (changePercent > volatility) {
changePercent -= (2 * volatility);
}
double changeAmount = oldPrice * changePercent/100 + momentum;
newPrice = oldPrice + changeAmount;
momentum = (changeAmount/10);
/*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,2.3,10);
}
}