-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain2.java
More file actions
73 lines (64 loc) · 2.75 KB
/
Main2.java
File metadata and controls
73 lines (64 loc) · 2.75 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
package com.company;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
try{
Scanner input = new Scanner(new File("C:\\Users\\Shraddha\\Downloads\\INFY_15days_data (1).csv"));
String data ="";
ArrayList<Double> lastClosePrice = new ArrayList<Double>();
ArrayList<Double> openPrice = new ArrayList<Double>();
ArrayList<Double> highPrice = new ArrayList<Double>();
ArrayList<Double> lowPrice = new ArrayList<Double>();
ArrayList<Double> lastPrice = new ArrayList<Double>();
ArrayList<Double> closePrice = new ArrayList<Double>();
int i=0;
while(input.hasNextLine()){
data = input.nextLine();
if(i==0){
i++;
}
else {
String[] dataSplit = data.split(",");
lastClosePrice.add(Double.parseDouble(dataSplit[2]));
openPrice.add(Double.parseDouble(dataSplit[3]));
highPrice.add(Double.parseDouble(dataSplit[4]));
lowPrice.add(Double.parseDouble(dataSplit[5]));
lastPrice.add(Double.parseDouble(dataSplit[6]));
closePrice.add(Double.parseDouble(dataSplit[7]));
i++;
}
}
System.out.println();
double sum = 0.0;
for (Double j : closePrice) {
sum = sum + j;
}
double average = sum/closePrice.size();
System.out.printf("Average is %.2f\n",average);
double diff = 0.0;
double value = 0.0;
double maximum = closePrice.get(0);
for (double temp : closePrice) {
if (temp >= maximum) {
maximum = temp;
} else {
diff = maximum - temp;
value = Math.max(diff, value);
}
}
System.out.printf("Max Drawdown of the given stock: %.2f\n",value);
double maxPotential = 0.0;
for(int j=0;j<openPrice.size();j++){
maxPotential = maxPotential + Math.abs(openPrice.get(j)-closePrice.get(j));
}
System.out.printf("Max Return Potential : %.2f\n",maxPotential);
double percentage = Math.floor((100*maxPotential)/openPrice.get(0)*100)/100;
System.out.println("Percentage max Return Potential: " + percentage +"%");
}
catch (Exception e){
System.out.println("Something is not right.");
}
}
}