-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVolAnalysis.R
More file actions
48 lines (36 loc) · 1.56 KB
/
Copy pathVolAnalysis.R
File metadata and controls
48 lines (36 loc) · 1.56 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
VolAnalysis <- function(priceThreshold = NULL) {
######### FUNCTION VARIABLES ##################
priceThreshold = 10 #priceThreshold # penny stock price threshold
volSummary = data.frame(Symbol=NA, Date = NA, TenDayChange=NA, VolMax=NA)
######### BOOKEEPING STUFF ####################
thePath = "/Users/ehren/Documents/StockAnalysis/volatilityData/"
theFiles = list.files(path=thePath, pattern=".csv")
errorTable <- data.frame(NUMBER=NA, TIME=NA, SYMBOL=NA, ERROR=NA) # table to write error messages to
errorPath = "/Users/ehren/Documents/StockAnalysis/volatilityData/errorLog/"
pennyCount = 0
k=1
row=1
###############################################
while (k <= length(theFiles)) {
vdata <- read.zoo(paste(thePath,theFiles[k], sep=""), header = TRUE, sep=",")
if ( last(vdata$adj. > priceThreshold && ncol(vdata) > 2) ) {
# vdata[as.Date('2016-06-02'),]
volChange <- diff(vdata$tenVol[(nrow(vdata)-1):nrow(vdata),])
volMax <- last(vdata$tenVol)
volSummary[(nrow(volSummary)+1),] <- NA
volSummary$Symbol[row] = substr(theFiles[k], 1, nchar(theFiles)-4)
volSummary$Date[row] = as.Date(index(vdata[nrow(vdata)]))
volSummary$TenDayChange[row] = volChange
volSummary$VolMax[row] = volMax
row = row + 1
k = k + 1
print(k)
} # end priceThreshold if
else {
pennyCount = pennyCount + 1
print(paste("Penny stock count = ", pennyCount, sep=""))
k = k + 1
} # end priceThreshold else
}# end while
return(volSummary)
} #end function