-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
394 lines (394 loc) · 14.6 KB
/
.Rhistory
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
intall.packages("quantmod")
install.packages("quantmod")
library(quantmod)
install.packages("e1071")
library(e1071)
library(ggplot2)
install.packages("ggplot2")
library("ggplot2", lib.loc="~/R/win-library/3.1")
library("ggplot2", lib.loc="~/R/win-library/3.1")
library("e1071", lib.loc="~/R/win-library/3.1")
Data<-AUD/USD
Data<-AUD/USD
RSI3<-RSI(Op(Data),n=3)
Data<-Audusd.csv
Data<-AUDUSD.csv
getwd()
dataset_url <- "http://s3.amazonaws.com/practice_assignment/diet_data.zip"
download.file(dataset_url, "diet_data.zip")
unzip("diet_data.zip", exdir = "diet_data")
list.files("diet_data")
andy<-read.csv("diet_andy/Andy.csv")
andy <- read.csv("diet_data/andy.csv")
head(andy)
length(andy&Age)
length(andy&Day)
length(andy$Day)
length(andy$Age)
dim(andy)
weightmedian <- function(directory, day) {
files_list <- list.files(directory, full.names=TRUE) #creates a list of files
dat <- data.frame() #creates an empty data frame
for (i in 1:5) { #loops through the files, rbinding them together
dat <- rbind(dat, read.csv(files_list[i]))
}
dat_subset <- dat[which(dat[, "Day"] == day),] #subsets the rows that match the 'day' argument
median(dat_subset[, "Weight"], na.rm=TRUE) #identifies the median weight
#while stripping out the NAs
}
weightmedian(directory = "diet_data", day = 20)
weightmedian(directory = "diet_data", day = 15)
require(XLConnect)
require(fImport)
install . packages (c(" XLConnect ", " fImport ", " forecast ", "zoo", " ggplot2 ",
" scales "))
install . packages (c(" XLConnect ", " fImport ", " forecast ", "zoo", " ggplot2" scales "))
install.packages(c(" XLConnect ", " fImport ", " forecast ", "zoo", " ggplot2" scales "))
install.packages(c("XLConnect", "fImport", "forecast", "zoo", "ggplot2" "scales"))
install.packages("quantmod")
library(quantmod)
install.packages("e1071","ggplot2")
library("ggplot2", lib.loc="~/R/win-library/3.1")
library("e1071", lib.loc="~/R/win-library/3.1")
library(quantmod)
install.packages("e1071")
library(ggplot2)
library(e1071)
listfiles()
Data <- read.csv("audusd.csv")
RSI3<-RSI(Op(Data),n=3)
SMA50<-SMA(Op(Data),n=50)
Trend<-Op(Data)-SMA50
Price<-Cl(Data)-Op(Data)
Class<-ifelse(Price>0,"UP","DOWN")
DataSet<-data.frame(RSI3,Trend,Class)
DataSet<-DataSet[-c(1:49),]
Training<-DataSet[1:4528,] ; Test<-DataSet[4529:6038,] ; Val<-DataSet[6039:7548,]
SVM<-svm(Class~RSI3+Trend,data=Training, kernel="radial",cost=1,gamma=1/2)
TrainingPredictions<-predict(SVM,Training,type="class")
TrainingData<-data.frame(Training,TrainingPredictions)
ggplot(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open - SMA50",y="RSI3",color="Training Predictions")
install.packages('ggplot2', dependencies = TRUE)
ggplot(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open - SMA50",y="RSI3",color="Training Predictions")
ggplot
ggplot2(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open - SMA50",y="RSI3",color="Training Predictions")
qplot(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open - SMA50",y="RSI3",color="Training Predictions")
ggplot2(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open - SMA50",y="RSI3",color="Training Predictions")
set.seed(1410) # Make the sample reproducible
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
qplot(carat, price, data = diamonds)
qplot(log(carat), log(price), data = diamonds)
qplot(carat, x * y * z, data = diamonds)
# ggplot2 examples
library(ggplot2)
# create factors with value labels
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),
labels=c("3gears","4gears","5gears"))
mtcars$am <- factor(mtcars$am,levels=c(0,1),
labels=c("Automatic","Manual"))
mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),
labels=c("4cyl","6cyl","8cyl"))
# Kernel density plots for mpg
# grouped by number of gears (indicated by color)
qplot(mpg, data=mtcars, geom="density", fill=gear, alpha=I(.5),
main="Distribution of Gas Milage", xlab="Miles Per Gallon",
ylab="Density")
# Scatterplot of mpg vs. hp for each combination of gears and cylinders
# in each facet, transmittion type is represented by shape and color
qplot(hp, mpg, data=mtcars, shape=am, color=am,
facets=gear~cyl, size=I(3),
xlab="Horsepower", ylab="Miles per Gallon")
# Separate regressions of mpg on weight for each number of cylinders
qplot(wt, mpg, data=mtcars, geom=c("point", "smooth"),
method="lm", formula=y~x, color=cyl,
main="Regression of MPG on Weight",
xlab="Weight", ylab="Miles per Gallon")
# Boxplots of mpg by number of gears
# observations (points) are overlayed and jittered
qplot(gear, mpg, data=mtcars, geom=c("boxplot", "jitter"),
fill=gear, main="Mileage by Gear Number",
xlab="", ylab="Miles per Gallon")
head(economics)
## date pce pop psavert uempmed unemploy
## 1 1967-06-30 507.8 198712 9.8 4.5 2944
## 2 1967-07-31 510.9 198911 9.8 4.7 2945
## 3 1967-08-31 516.7 199113 9.0 4.6 2958
## 4 1967-09-30 513.3 199311 9.8 4.9 3143
## 5 1967-10-31 518.5 199498 9.7 4.7 3066
## 6 1967-11-30 526.2 199657 9.4 4.8 3018
a <- ggplot(data = economics, aes(x = date, y = unemploy))
a <- a + geom_line()
a
clear()
head(data)
exit
quit()
Data<-read.csv("data.csv")
header(data)
head(data)
list(data)
getpwd()
getwd()
View(Data)
head(Data)
install.packages("ggplot2",dependencies=TRUE)
library(ggplot2)
library("ggplot2", lib.loc="~/R/win-library/3.1")
install.packages("ggplot2")
a <-ggplot(data=Data,aes(x=Date,y=Close.Price))
install.packages("proto")
library(ggplot2)
library(proto)
library(ggplot2)
install.packages("labelling")
library(labelling)
library(ggplot2)
install.packages("ggplot2")
library(ggplot2)
available()
library()
library(ggplot2=help)
library(help=ggplot2)
library(ggplot2)
install.packages("Rcpp")
library(ggplot2)
data(diamonds)
head(diamonds)
with(diamonds,hist(price))
qplot(price,data=diamonds)
qplot(price,data=diamonds,binwidth=1000)
with(diamonds,plot(carat,price))
with(diamonds,plot(price,carat))
qplot(carat,price,data=diamonds)
qplot(carat,data=diamonds,geom="density")
qplot(price,data=diamonds,geom="density")
qplot(carat,price,data=diamonds,xlab="Wt in kt",ylab="Price in $",main="Diamonds are a jewellers best friend!")
qplot(carat,price,data=diamonds,facets=~clarity)
qplot(carat,price,data=diamonds,facets=clarity~)
qplot(carat,price,data=diamonds,facets=clarity~)
qplot(carat,price,data=diamonds,facets=clarity~.)
qplot(carat,price,data=diamonds,facets=~color)
qplot(carat,price,data=diamonds,facets=clarity~color)
qplot(carat,x*y*z,data=diamondss)
qplot(carat,x*y*z,data=diamonds)
qplot(carat,data=diamonds,colour=color)
qplot(carat,price,data=diamonds,colour=color)
qplot(carat,price,data=diamonds,colour=color,shape=cut)
qplot(carat,price,data=diamonds,alpha=I(1/10))
qplot(carat,price,data=diamonds,alpha=I(1/100))
qplot(carat,price,data=diamonds,alpha=I(1/200))
qplot(carat,price,data=diamonds,colour=color,shape=cut,alpha=I(1/50))
qplot(carat,price,data=diamonds,colour=color,shape=cut,alpha=I(1/50))
fit1=lm(price~carat*as.numeric(color),data=diamonds)
library(ggplot2)
fit1=lm(price~carat*as.numeric(color),data=diamonds)
summary(fit1)
st.seed(1410)
set.seed(1410)
dsmall<-diamonds[sample(nrow(diamonds),100),]
qplot(carat,price,data=diamonds,geom=c("point","smooth"))
qplot(carat,price,data=dsmall,geom=c("point","smooth"))
qplot(carat,price,data=diamonds,geom=c("point","smooth"))
?loess
qplot(carat,price,data=diamonds,geom=c("point","smooth"),span=0.1)
qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=0.1)
qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=0.2)
qplot(carat,price,data=dsmall,geom=c("point","smooth"),span=1)
?loess
head(diamonds)
qplot(color,price/carat,data=diamonds,geom="jitter")
qplot(color,price/carat,data=diamonds,geom="boxplot")
qplot(color,price/carat,data=diamonds,geom="jitter")
qplot(color,price/carat,data=diamonds,geom="boxplot")
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/5))
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/50))
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/25))
qplot(color,price/carat,data=diamonds,geom="jitter",alpha=I(1/5),colour=color)
qplot(carat,data=diamonds,geom="density",colour=color)
qplot(carat,data=diamonds,geom="histogram",fill=color)
qplot(carat,data=diamonds,geom="histogram",fill=color,binwidth=0.1)
qplot(carat,data=diamonds,geom="histogram",fill=color)
qplot(carat,data=diamonds,geom="density",colour=color)
HEAD(ECONOMICS)
head(economics)
install.packages("GTrendsR")
install_github("dvanclev/GTrendsR")
devtools::install_github("dvanclev/GTrendsR")
devtools::install_github("trinker/gtrend")
library(gtrend);library(dplyr);library(ggplot2);library(scales)
install.packages("dplyr")
library(dplyr)
terms <- c("reading assessment", "common core", "reading standards",
"phonics", "whole language", "lexile score", "balanced approach",
"literacy research association", "international reading association"
)
out <- gtrend_scraper("[email protected]<script type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>", "5ummerR@1n5", terms)
out %>%
trend2long() %>%
plot()
terms <- c("reading assessment", "common core", "reading standards",
"phonics", "whole language", "lexile score", "balanced approach",
"literacy research association", "international reading association"
)
out <- gtrend_scraper("[email protected]<script type="text/javascript">/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();/* ]]> */</script>", "5ummerR@1n5", terms)
out %>%
trend2long() %>%
plot()
exit
quit
quit()
library(quantmod)
library(e1071)
library(ggplot2)
Data<-read.csv("audusd.csv")
RSI3<-RSI(Op(Data),n=3)
SMA50<-SMA(Op(Data),n=50)
Trend<-Op(Data)-SMA50
Price<-Cl(Data)-Op(Data)
Class<-ifelse(Price>0,"UP","DOWN")
DataSet<-data.fram(RSI3,Trend,Class)
DataSet<-data.frame(RSI3,Trend,Class)
DataSet<-DataSet[-c(1:49),]
Training<-DataSet[1:4528,];Test<-DataSet[4529:6038,];Val<-DataSet[6039:7548,]
SVM<-svm(Class~RSI3+Trend,data=Training,kernel="radial",cost=1,gamma=1/2)
TrainingPredictions<-predict(SVM,Training,type="class")
ggplot(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open-SMA50",y="RSI3",color="Training Predictions")
TrainingData<-data.frame(Training,TrainingPredictions)
ggplot(TrainingData,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TrainingPredictions))+labs(title="SVM RSI3 and Trend Predictions",x="Open-SMA50",y="RSI3",color="Training Predictions")
ShortRange1<-which(Test$RSI3 < 25 & Test$Trend > -.010 & Test$Trend < -.005)
ShortRange2<-which(Test$RSI3 > 70 & Test$Trend < -.005)
ShortRange3<-which(Test$RSI3 > 75 & Test$Trend > .015)
LongRange1<-which(Test$RSI3 < 25 & Test$Trend < -.02)
LongRange2<-which(Test$RSI3 > 50 & Test$RSI3 < 75 & Test$Trend > .005 & Test$Trend < .01)
ShortTrades<-Test[c(ShortRange1,ShortRange2,ShortRange3),]
ShortCorrect<-((length(which(ShortTrades[,3]=="DOWN")))/nrow(ShortTrades))*100
LongTrades<-Test[c(LongRange1,LongRange2), ]
LongCorrect<-((length(which(LongTrades[,3]=="UP")))/nrow(LongTrades))*100
ShortCorrect
LongCorrect
NiftyData<-read.csv("CNX NIFTY.csv")
RSI3<-RSI(Op(NiftyData),n=3)
SMA50<-SMA(Op(Data),n=50)
Trend<-Op(Data)-SMA50
SMA50<-SMA(Op(NiftyData),n=50)
Trend<-Op(NiftyData)-SMA50
Price<-Cl(NiftyData)-Op(NiftyData)
Class<-ifelse(Price>0,"UP","DOWN")
DataSetN<-data.frame(RSI3,Trend,Class)
DataSetN<-DataSetN[-c(1:49),]
TrainingN<-DataSetN[1:805,];Tes<-DataSetN[806:1073,];Val<-DataSetN[1074:1343,]
SVM<-svm(Class~RSI3+Trend,data=TrainingN,kernel="radial",cost=1,gamma=1/2)
TP<-predict(SVM,TrainingN,type="class")
TD<-data.frame(TrainingN,TP)
ggplot(TD,aes(x=Trend,y=RSI3))+stat_density2d(geom="contour",aes(color=TP))+labs(title="SVM RSI3 & Trend Predictions",x="Op-SMA50",y="RSI3",color="Training Predictions")
LongRange1<-which(Tes$RSI3>62.5 & Tes$Trend<-100 & Tes$Trend>-400)
LongRange1<-which(Tes$RSI3>62.5 & Tes$Trend< -100 & Tes$Trend> -400)
ShortRange1<-which(Tes$RSI3>62.5 & Tes$Trend>750 & Tes$Trend<1000)
ShortRange2<- which(Tes$RSI3<50 & Tes$Trend<250 & Tes$Trend> -150)
ShortTradesN<-Tes[c(ShortRange1,ShortRange2),]
LongTradesN<-Tes[c(LongRange1),]
SC<- ((length(which(ShortTradesN[,3]=="DOWN")))/nrow(ShortTradesN))*100
SC
LC<- ((length(which(longTradesN[,3]=="UP")))/nrows(LongTradesN))*100
LC<- ((length(which(LongTradesN[,3]=="UP")))/nrows(LongTradesN))*100
LC<- ((length(which(LongTradesN[,2]=="UP")))/nrows(LongTradesN))*100
LC<- ((length(which(LongTradesN[,3]=="UP")))/nrow(LongTradesN))*100
LC
head(LongTradesN)
head(LongRange1)
quit()
install.packages("swirl")
library("swirl")
ls()
rm(list=ls())
swirl()
bye()
swirl()
rm(list=ls())
install.packages("swirl")
library("swirl")
install_from_swirl("R Programming")
exit
uit
quit
exit()
quit()
x<-10
x<-10
x<-1:10
if(x>5){x<-0}
}
}
}
z<-10
f(3)
source('~/.active-rstudio-document')
z<-10
f(3)
x<-5
y<-if(x<3){NA}else{10}
rm(list=ls())
x<-5
y <-if(x<3){NA}
quit()
source("submitscrip1.r")
source("http://d396qusza40orc.cloudfront.net/rprog%2Fscripts%2Fsubmitscript1.R")
source('D:/Coursera R Programming/complete.R')
submit()
submit()
submit()
submit()
quit()
rpois(5,2)
set.sedd(1)
set.seed(1)
rpois(5,2)
rpois(5,2)
rpois(5,2)
set.seed(1)
rpois(5,2)
?set.seed
set.seed(5)
?set.seed
rpois(5,2)
?qpois
quit()
??rmvnorm
?plot
??as.yearmon
?diff
??table.Stats
?table.Stats
?apply
?mean
??pairs
?t.test
?plot
?sigma
?expression
expression(sigma[p])
install.packages(quantmod)
install.packages(quantmod.r)
install.packages("quantmod")
install.packages("Quandl")
library(Quandl)
library(quantmod)
fb_data=Quandl("GOOG/NASDAQ_FB",type="xts")
head(fb_data)
candleChart(fb_data)
infy_data=Quandl("GOOG/NASDAQ_INFY")
candleChart(infy_data)
infy_data=Quandl("GOOG/NASDAQ_INFY",type="xts")
candleChart(infy_data)
infyNSE_data=Quandl("GOOG/NSE_INFY",type="xts")
candleChart(infyNSE_data)
?candleChart
?Quandl
install.packages("shiny")
library(shiny)
runExample("01_hello")