fork download
  1.  
  2.  
  3.  
  4. library(rsconnect)
  5. library(shiny)
  6. library(quantmod)
  7. library(rvest)
  8. library(XML)
  9. library(e1071)
  10. library(timeSeries)
  11. library(forecast)
  12. library(neuralnet)
  13. library(nnet)
  14. library(lattice)
  15. library(ggplot2)
  16. library(caret)
  17. library(MLmetrics)
  18. library(rsconnect)
  19. library(devtools)
  20.  
  21. deployApp("C:\\Users\\User\\Desktop\\shinyApp")
  22.  
  23.  
  24. Stock<-read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vRYxupbr1vUlPOpq2JPGzlCuJKcMXHvC4MaWR-qzngSpBiymOBFbbXuegSJjgUl6-Rb-3bPvCvJOCFW/pub?gid=1809581675&single=true&output=csv",header=T)
  25. N<-nrow(Stock)
  26. st<-Stock[,2]
  27.  
  28. set.seed(123)
  29. ind1<-sample(N,round(N*0.7))
  30. Train<-Stock[ind1,-1]
  31. Test<-Stock[-ind1,-1]
  32. Test1<-Test[,11:18]
  33.  
  34.  
  35. mod1<-lm(stock~usd+coffee+rice+oil+wheatADJ+Djopen+cuADJ+cornADJ,data=Train)
  36.  
  37.  
  38.  
  39.  
  40. TWII=getSymbols( "^TWII" ,from = "2017-9-1", src="yahoo",auto.assign = FALSE)
  41. ul="http://q...content-available-to-author-only...o.com/exchanges/contracts.html?r=CBOT_ZW"
  42. wheatc = data.frame( readHTMLTable(ul))
  43.  
  44. wheat1<-data.frame(as.character( wheatc$NULL.V3))
  45.  
  46. oil1=getSymbols("CL=F",from = "2017-09-01", src="yahoo",auto.assign = FALSE)
  47. ul2="http://q...content-available-to-author-only...o.com/exchanges/contracts.html?r=CBOT_ZR"
  48. ricec<-data.frame(readHTMLTable(ul2))
  49. rice1<-data.frame(as.character(ricec$NULL.V3))
  50.  
  51. ul1="http://w...content-available-to-author-only...m.br/indicadores-de-mercado/precos-cepeaesalq/"
  52. coffeec = data.frame( readHTMLTable(ul1))
  53. coffee1<- coffeec$table_1.Conillon.US.
  54.  
  55. corn1=getSymbols("C=F",from = "2017-09-01", src="yahoo",auto.assign = FALSE)
  56. cu1<-getSymbols("^YHOH711",auto.assign = F)
  57. dj1=getSymbols( "^DJI" ,from = "2017-09-01", src="yahoo",auto.assign = FALSE)
  58. usd1=getSymbols( "USDTWD=X" ,from = "2017-09-01", src="yahoo",auto.assign = FALSE)
  59.  
  60. tw.ts<-TWII$TWII.Adjust[-(1:3552),]
  61. tw<-as.numeric(tail(TWII$TWII.Adjust,n=30))
  62.  
  63. oil2<-as.numeric(tail(oil1[,6],n=1))
  64. oil3<-(oil2-mean(Stock$oil))/sd(Stock$oil)
  65. coffee2<-tail(as.numeric (coffee1),n=1)
  66. coffee3<-(coffee2-mean(Stock$coffee))/sd(Stock$coffee)
  67. rice2<-head( as.numeric(as.character(rice1[-(1:3),])),n=1)
  68. rice3<-(rice2-mean(Stock$rice))/sd(Stock$rice)
  69. corn2<-as.numeric(tail(corn1[,6],n=1)/10)
  70. corn3<-(corn2-mean(Stock$cornADJ))/sd(Stock$cornADJ)
  71. cu2<-as.numeric(tail(cu1[,6],n=1)/10)
  72. cu3<-(cu2-mean(Stock$cuADJ))/sd(Stock$cuADJ)
  73. dj2<-as.numeric(tail(dj1[,1],n=1)/100)
  74. dj3<-(dj2-mean(Stock$Djopen))/sd(Stock$Djopen)
  75.  
  76. usd2<-as.numeric (tail(usd1[,6],n=1))
  77. usd3<-(usd2-mean(Stock$usd))/sd(Stock$usd)
  78. wheat2<-head(as.numeric( as.character( wheat1[-(1:2),])),n=1)/10
  79. wheat3<-(wheat2-mean(Stock$wheatADJ))/sd(Stock$wheatADJ)
  80.  
  81.  
  82. d1<-data.frame(oil=oil2,coffee=coffee2,usd=usd2,rice=rice2,wheatADJ=wheat2,cuADJ=cu2,Djopen=dj2,cornADJ=corn2)
  83. d2<-data.frame(usd.z=usd3,coffee.z=coffee3,rice.z=rice3,oil.z=oil3,dj.z=dj3,wheat.z=wheat3,corn.z=corn3,cu.z=cu3)
  84. new<-predict(mod1,newdata = d1)
  85.  
  86. new1<-stack(data.frame(tw,new))
  87.  
  88. new2<-new1[1:31,1]
  89.  
  90. sttdiff<-diff(st,differences=1)
  91.  
  92.  
  93.  
  94. stt3<- arima(sttdiff, order=c(14,1,0),method = "ML")
  95.  
  96.  
  97. stt_cor<-forecast(tw, h=5, level = c(95),model=stt3)
  98.  
  99.  
  100.  
  101. x<-rep(2,time=30)
  102. y<-4
  103. z<-data.frame(x,y)
  104. z1<-stack(z)
  105. z2<-z1[1:31,1]
  106. model <-neuralnet(formula =stock.z~usd.z+coffee.z+rice.z+oil.z+wheat.z+dj.z+cu.z+corn.z,data = Train, hidden = c(14) ,learningrate = 0.1, threshold =
  107. 0.1,stepmax =90000)
  108. pred <- compute(model,d2)
  109. new.n<-(pred$net.result)
  110. new.n1<-new.n*sd(Stock$stock)+mean(Stock$stock)
  111. new1.n<-stack(data.frame(tw,new.n1))
  112. new2.n<-new1.n[1:31,1]
  113. plot(new2,type="b",ylab="twstock" ,xlab="last mounth",cex=z2,col=z2,lwd=3,main="regression prediction")
  114. s1<-svm(stock.z~usd.z+coffee.z+rice.z+oil.z+wheat.z+dj.z+cu.z+corn.z,data=Train,gamma=2^-1,cost=2^6)
  115. svm1<-predict(s1,newdata = d2)
  116.  
  117. da<-data.frame( model$generalized.weights)
  118. da2<-abs(da)
  119. da3<-data.frame(usd=sum(da2$X1),coffee=sum(da2$X2),rice=sum(da2$X3),oil=sum(da2$X4),wheat=sum(da2$X5),dj=sum(da2$X6),cu=sum(da2$X7),corn=sum(da2$X8))
  120.  
  121. svm2<-svm1*sd(Stock$stock)+mean(Stock$stock)
  122. svm3<-stack(data.frame(tw,svm2))
  123. svm4<-svm3[1:31,1]
  124. shinyServer(function(input, output) {
  125.  
  126. output$twstock.mod <- renderPlot(plot(new2,type="b",ylab="twstock" ,xlab="last mounth",cex=z2,col=z2,lwd=3,main="regression prediction"))
  127.  
  128. output$twtime<-renderPlot(plot(stt_cor))
  129. output$twnet<-renderPlot(plot( new2.n,type="b",ylab="twstock" ,xlab="last mounth",cex=z2,col=z2,lwd=3,main="neuralnet prediction"))
  130. output$twsvm<-renderPlot(plot( svm4,type="b",ylab="twstock" ,xlab="last mounth",cex=z2,col=z2,lwd=3,main="svm prediction"))
  131.  
  132.  
  133.  
  134.  
  135. })
  136. # your code goes here
Success #stdin #stdout #stderr 0.19s 175424KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error in library(rsconnect) : there is no package called ‘rsconnect’
Execution halted