check

原创
2018/07/16 17:23
阅读数 16
check<-function(x)
	{
	library(rvest)
	day1<-Sys.Date()
	day2<-Sys.Date()-7
	url<-paste("http://app.finance.ifeng.com/hq/trade/stock_zijin.php?code=sh",x,"&begin_day=",day2,"&end_day=",day1,sep="")
	web<-read_html(url)
	res<-web%>%html_table(fill=T)%>%as.data.frame
	res<-res[-length(res[,1]),]
	LastAll<-res[2,2]
	NowAll<-res[1,2]
	BeforeAll<-res[3,2]
	t<-data.frame(Code==x,BeforeAll,LastAll,NowAll)
	t[,1:4]<-lapply(t[,1:4],as.vector)
	g<-function(y){substring(y,1,nchar(y)-2)}
	t[,2:4]<-lapply(t[,2:4],g)
	t[,2:4]<-lapply(t[,2:4],as.numeric)
	m<-strsplit(as.character(Sys.time())," ")[[1]][2]
	y<-as.numeric(substring(m,1,2))
	u<-as.numeric(substring(m,4,5))
	nt<-ifelse(y<12,(y-9)*60+u-30,ifelse(y>14,240,ifelse(y>12,(y-11)*60+u,120)))
	TP<-round(nt/240,2)
	t$ExpectIn<-round(t$NowAll/TP,0)
	t$MP<-round(t$ExpectIn/t$LastAll,2)
	t$Sign<-ifelse(MP<-1,"sell","hold")
	print(t)
	}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部