-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock_data.vb
93 lines (48 loc) · 2.05 KB
/
stock_data.vb
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
Sub ticker_data():
' create column labels
Cells(1, 10).Value = "ticker"
Cells(1, 11).Value = "yearly change"
Cells(1, 12).Value = "percent change"
Cells(1, 13).Value = "total stock volume"
total_volume = 0
open_price = 0
close_price = 0
' variable to grab ticker label in column 1
ticker = Cells(2, 1).Value
' MsgBox (ticker)
' variable for opening price of stock
open_price = Cells(2, 3).Value
' MsgBox (open_price)
output = 2
' For Loop to loop through all rows
For Row = 2 To 797711
total_volume = total_volume + Cells(Row, 7).Value
' If statement: If the next row changes tickers then grab the closing price for that ticker
If Cells(Row + 1, 1) <> ticker Then
close_price = Cells(Row, 6).Value
' MsgBox = (close_price)
' formula to calculate the change in close - open
Change = close_price - open_price
open_price = Cells(Row + 1, 3)
Cells(output, 11).Value = Change
Cells(output, 10).Value = Cells(Row, 1).Value
' how do i get the volume to sum
Cells(output, 13).Value = total_volume
total_volume = 0
ticker = Cells(Row + 1, 1).Value
' formula to calculate percent change
open_price = Cells(Row, 3).Value
percent_change = (close_price - open_price) / close_price
Cells(output, 12).Value = percent_change
output = output + 1
End If
Next Row
' for loop for conditional formatting
For Color = 2 To 3169
If Cells(Color, 11).Value < 0 Then
Cells(Color, 11).Interior.Color = RGB(255, 0, 0)
Else:
Cells(Color, 11).Interior.Color = RGB(0, 255, 0)
End If
Next Color
End Sub