-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStock.java
More file actions
166 lines (159 loc) · 4.45 KB
/
Copy pathStock.java
File metadata and controls
166 lines (159 loc) · 4.45 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import java.util.*;
public class Stock{
//all the instance variables needed for this class
protected double volatility; //about 0-5
protected double curVal;//depends
protected double momentum; //about -2 - 2
protected double momVol; // about 0- 1
protected String name;
protected int amtOwned;
protected ArrayList<Double> prices;
protected ArrayList<Headline> heads= new ArrayList<Headline>();
protected ArrayList<String> nouns= new ArrayList<String>();
protected ArrayList<String> verbs= new ArrayList<String>();
protected ArrayList<Double> ws= new ArrayList<Double>();
protected ArrayList<Boolean> cms = new ArrayList<Boolean>();
private double changeAmount;
public Stock(String nm, double cV, double vol, double mom, ArrayList<Double> p, double mV){
name = nm;
curVal = cV;
volatility = vol;
momentum = mom;
prices = p;
momVol = mV;
amtOwned = 0;
}
// Precond Nouns,Verbs,ws,cms, are all the same length
//postcond; a stock with headlines
public Stock(String nm, double cV, double vol, double mom, ArrayList<Double> p, double mV, ArrayList<String> n, ArrayList<String> v, ArrayList<Double> w, ArrayList<Boolean> cm){
name = nm;
curVal = cV;
volatility = vol;
momentum = mom;
prices = p;
momVol = mV;
amtOwned = 0;
nouns = n;
verbs =v;
ws = w;
cms = cm;
GenerateHeadlines();
}
//rounder for 2 floating points
public static double rounder(double u){
int temp = (int)(u *100);
double ret = temp/100.0;
return ret;
}
//returning headline method
public Headline GenerateHeadline(String n,String v,double w, boolean cm){
Headline h = new Headline(n,v,w,cm,name);
return h;
}
//headline is changed in method
public void GenerateHeadlines(){
for(int i =0; i < verbs.size(); i++){
Headline a = GenerateHeadline(nouns.get(i),verbs.get(i),ws.get(i),cms.get(i));
heads.add(a);
}
}
//give random header
public Headline getRandoHead(){
int random =(int)( Math.random()*(heads.size()));
return heads.get(random);
}
//get methods
public double getChangeAmount(){
return changeAmount;}
public int getAmtOwned(){
return amtOwned;}
public int setAmtOwned(int u){
int temp1 = amtOwned;
amtOwned = u;
return temp1;}
public double getMomVol(){
return momVol;
}
public double getVolatility(){
return volatility;
}
public double getCurVal(){
return curVal;
}
public String getName(){
return name;
}
public ArrayList<Double> getPrices(){
return prices;
}
public double getMomentum(){
return momentum;
}
//######################################################
//set methods
public double setVolatility(double u){
double temp1 = volatility;
volatility = u;
return temp1;
}
public double setCurVal(double u){
double temp1 = curVal;
curVal = u;
return temp1;
}
public String setName(String u){
String temp1 = name;
name = u;
return temp1;
}
public ArrayList<Double> setPrices(ArrayList<Double> u){
ArrayList<Double> temp1 = prices;
prices = u;
return temp1;
}
public double setMomentum(double u){
double temp1 = momentum;
momentum = u;
return temp1;
}
//adds price to end of ArrayList
public void addPrice(double d){
prices.add(d);}
//progress finds next weeks value
public ArrayList<Double> progress(){
double oldPrice = curVal;
double newPrice =curVal;
ArrayList<Double> weekly = new ArrayList<Double>();
for(int i = 0; i < 1; i++){
oldPrice= newPrice;
double rnd = Math.random();
//gen random num
double changePercent = volatility * rnd;
double newrand = (Math.random() * 11) -5;
double changeAmount;
//if random num in range is greater than momentum
if ( newrand >= momentum){
//take away some
changeAmount = oldPrice * (-1 * changePercent/100);
momentum += (-1 * momVol * changePercent/1000);
}
else{
//add some
changeAmount = oldPrice * (1 * changePercent/100) ;
momentum += (1 * momVol * changePercent/1000);
}
newPrice = oldPrice + changeAmount ;
prices.add(newPrice);
weekly.add(newPrice);
curVal = newPrice;
}
return weekly;
}
//uses graph to return a graph of entire history
public String toString(){
String retstr = "Current value : " +rounder( curVal); //" %change : " + ((curVal - prices.get(prices.size()))/100) + "\n";
Graph g = new Graph(this);
retstr += g.printGraph();
return retstr;
}
}