-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEST_SCRIPTS.R
More file actions
165 lines (96 loc) · 4.52 KB
/
Copy pathTEST_SCRIPTS.R
File metadata and controls
165 lines (96 loc) · 4.52 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
## Test file for developing scripts for stockData
stockPath = "/Users/ehren/Documents/StockAnalysis/stockData/"
technicalsPath = "/Users/ehren/Documents/StockAnalysis/stockTechnicals/"
theSymbol = "T.csv"
theFiles = list.files(path=thePath, pattern=".csv")
stockData = read.zoo(paste(stockPath,theSymbol,sep=""),header=TRUE, sep=",")
techData = read.zoo(paste(technicalsPath,theSymbol,sep=""),header=TRUE, sep=",")
test = match(theSymbol, theFiles)
# colnames(data) = c("open","high","low","close","volume","adj.")
data = xts(data[,c("open","high","low","close","volume","adj.")],
order.by = as.Date(data[,"Index"],format="%Y-%m-%d"))
symbolDelt = Delt(data$close,k=1,type=c("arithmetic","log"))
# dat <- matrix(runif(40,1,20),ncol=4) # make data
matplot(dat, type = c("b"),pch=1,col = 1:4) #plot
legend("topleft", legend = 1:4, col=1:4, pch=1)
###### build a matrix with rollmeans of data for MACD
pdat = as.xts(techData$MACD)
pdat <- pdat['2014/2015']
colnames(pdat)[1]= paste(substr(theSymbol,1,nchar(theSymbol)-4),"_MACD",sep = "")
# nrow(rollmean(pdat,5,na.pad = TRUE))
plotdat <- cbind(pdat, rollmean(pdat,5),
rollmean(pdat,10),
rollmean(pdat,15))
# colnames(pdat)[2]="RM_5"
colnames(plotdat)=c(paste(substr(theSymbol,1,nchar(theSymbol)-4)),"RM_5", "RM_10", "RM_15")
start=nrow(plotdat)
plotdat <- na.omit(plotdat)
enddat=nrow(plotdat)
print(start-enddat)
matplot(plotdat, type = c("b"),pch=1,col = 1:4) #plot
legend("topleft", legend = 1:4, col=1:4, pch=1)
pdat<-pdat[,! colnames(pdat) %in% c("crap","crap1")]
# roll = 2
# start = 1
# maxes = data.frame(open=NA,high=NA,low=NA,close=NA,volume=NA,adj=NA)
# rownames(maxes) <- maxes$Index
# maxes$Index=NULL
#
# maxes = xts(open=NA,high=NA,low=NA,close=NA,volume=NA,adj=NA)
# attributes(maxes)$index[1] <- as.POSIXct("2000-01-01")
# # maxes=as.xts(maxes)
# order.by = as.Date(data[,"Index"],format="%Y-%m-%d")
########################################################
######## USE WHICH.MAX TO FIND MAXIMA
## CREATE Starting Data
stockData=as.xts(stockData)
stockData=stockData['2008-7']
nrow(stockData)
maxes = read.zoo(paste(stockPath,"AAPL.csv",sep=""),header=TRUE, sep=",")
maxes = as.xts(maxes)
maxes = maxes[1,]
maxes[1,] = NA
attributes(maxes)$index[1] <- as.POSIXct("2000-01-01")
####
endrow = nrow(stockData)
####
localMaxIndex = which.max(stockData$close) #get first local maximum
localMaxIndex
nextMax = stockData[localMaxIndex,]
nextMax
maxes=rbind(maxes,nextMax)
maxes
stockData = stockData[(localMaxIndex+2):nrow(stockData),]
nrow(stockData)
maxes
##########################################################
# MAKE POINTS for plotting - does not work right now
maxes=na.omit(maxes) #remove the NA row in initial xts object for maxes
stockData = read.zoo(paste(stockPath,theSymbol,sep=""),header=TRUE, sep=",")
plot.xts(stockData$close)
points( maxes$close, col="red", pch=19, cex=15 )
###### COMPARE TICKER SYMBOLS LIST ##########################################################
oldSymbolFile = '//Users/ehren/Documents/StockAnalysis/tickerSymbols_01.csv'
newSymbolFile = '//Users/ehren/Documents/StockAnalysis/tickerSymbols.csv'
ETFListFile = '//Users/ehren/Documents/StockAnalysis/ETFList.csv'
oldSymbols = read.csv(oldSymbolFile, header=FALSE, sep=",")
newSymbols = read.csv(newSymbolFile, header=FALSE, sep=",")
ETFList = read.csv(ETFListFile, header=FALSE, sep=",")
nrow(newSymbols)-nrow(oldSymbols)
Date=c("7/3/2007","7/5/2007","7/6/2007","7/9/2007","7/10/2007","7/11/2007","7/12/2007","7/13/2007","7/16/2007","7/17/2008","7/18/2007")
Close=c(106.58,108.05,109.03,108.97,108.63,109.1,109.28,108.6,109.66,110.77,111.08)
Change=c(NA, 1.38,0.91,-0.06,-0.31,0.43,0.16,-0.62,0.98,1.01,0.28)
bex = data.frame(Date=Date,Close=Close,Change=Change)
# Read more: Option Volatility: Historical Volatility | Investopedia http://www.investopedia.com/university/optionvolatility/volatility2.asp#ixzz49iAjXaRe
# Follow us: Investopedia on Facebook
#################### BUILD HISTORICAL VOLATILITY ##################################
library(gmailr)
mime() %>%
to("webehren@gmail.com") %>%
from("webehren@gmail.com") %>%
text_body("My First Email using R.") -> first_part
first_part %>%
subject("Test Mail from R") %>%
# attach_file("BazaarQueriesforURLData.txt") -> file_attachment
send_message()
file_attachment