-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstockPerfScripts.R
More file actions
72 lines (51 loc) · 2.39 KB
/
Copy pathstockPerfScripts.R
File metadata and controls
72 lines (51 loc) · 2.39 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
#########################################################
## Compute performance from technicalsLoop.R output
## [in stockTechnicals folder]
stockPerfScripts <- function() {
library(quantmod)
perfSource = "/Users/ehren/Documents/StockAnalysis/stockTechnicals/"
destinationPath = "/Users/ehren/Documents/StockAnalysis/dailySummaries/"
perfFiles = list.files(path=perfSource,pattern=".csv")
totalFiles = length(perfFiles)
fileCount = 0
startTime = Sys.time()
dailyData <- read.zoo(paste(perfSource,"A.csv",sep=""), header = TRUE, sep = ",")
fileDate <- end(dailyData) #get latest date from data
dailyData <- data.frame(Symbols=NA,Date=index(dailyData),coredata(dailyData)) #add column for symbol
#dailyData <- dailyData[nrow(dailyData),]
dailyData <- dailyData[! is.na(dailyData$Symbols),]
for (ii in perfFiles){
data <- read.zoo(paste(perfSource,ii,sep=""), header = TRUE, sep = ",")
data <- data[end(data),]
data <- data.frame(Date=index(data),coredata(data)) #name the index column "Date"
## ticker string
Symbol <- substr(ii,1,nchar(ii)-4)
data <- data.frame(Symbols=NA,coredata(data))
#start() and end() for xts indexes
data$Symbols[1] <- Symbol
dailyData <- rbind(dailyData,data)
fileCount = fileCount + 1
# print(paste(ii, " of", fileCount, " of ", totalFiles, " completed.", sep=""))
} #end main for loop
## Fix sloppy looking names of columns
names(dailyData)[names(dailyData) == 'Delt.1.arithmetic'] <- 'Delta1*'
names(dailyData)[names(dailyData) == 'Delt.5.arithmetic'] <- 'Delta5*'
names(dailyData)[names(dailyData) == 'atr'] <- 'ATR'
#chop out the date column since it's repetitive
# dailyData <- dailyData[,! colnames(dailyData) %in% c("Date")]
## Get data sorted for top ten biggest relative movers of the day...
dailyData <- dailyData[order(dailyData$Delta1),]
# Remove any data that is not from today's price history
dailyData <- dailyData[dailyData$Date == max(dailyData$Date),]
#Get worst Delt performers
topDecreases <- dailyData[((nrow(dailyData)-9):nrow(dailyData)),]
# Get best Delt Performers
topIncreases <- dailyData[1:10,]
# Bind the two sets
dailyDelt1 <- rbind(topIncreases,topDecreases)
## Write the Daily Delts (1-day) to a .csv file at destintionPath location
write.table(dailyDelt1, file=paste(destinationPath, fileDate,"_DailyDelt_1.csv",sep=""), na="", sep=",", row.names = FALSE)
print("Analysis completed.")
print(Sys.time() - startTime)
print(fileCount)
}