-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path沪牌数据.R
137 lines (122 loc) · 3.73 KB
/
沪牌数据.R
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
library(ggplot2)
library(reshape)
library(dplyr)
hisdata<- read.csv(file = "C:/Users/chenshengkang/Desktop/hupai.csv",header = FALSE)
colnames(hisdata)<- c("Time","15Y11M","15Y12M","16Y01M","16Y02M","16Y03M",
"16Y04M","16Y05M","16Y06M","16Y07M","16Y08M","16Y09M",
"16Y10M","16Y11M","16Y12M")
hisdata
standprice<-as.vector(hisdata[61,-1] )
moni<- function(intime,addprice,outtime){
#初始化
outprice<- as.vector(NULL)
standprice<- as.vector(NULL)
lm1s<- as.vector(NULL)
l0s<- as.vector(NULL)
l1s<- as.vector(NULL)
l2s<- as.vector(NULL)
#写入数据
for( i in 2:ncol(hisdata)){
temp<- hisdata[intime+1,i]+addprice
outprice<- c(outprice,temp)
temp<- hisdata[61,i]
standprice<- c(standprice,temp)
temp<- hisdata[outtime,i]
lm1s<- c(lm1s,temp)
temp<- hisdata[outtime+1,i]
l0s<- c(l0s,temp)
temp<- hisdata[outtime+2,i]
l1s<- c(l1s,temp)
temp<- hisdata[outtime+3,i]
l2s<- c(l2s,temp)
}
#Result
result<- as.data.frame(NULL)
result<- rbind(outprice-lm1s,outprice-l0s,outprice-l1s,outprice-l2s,outprice-standprice)
colnames(result)<- colnames(hisdata[-1])
rownames(result)<-c(outtime-1,outtime,outtime+1,outtime+2,"Diff")
result
a<- ifelse(result[-5,]<=300,1,0)
for (i in 1:ncol(result)){
for (m in 1:4){
a[m,i]<- ifelse(result[5,i]<300 & result[5,i]>=0,a[m,i],0 )
}
}
b<-melt(a,id=colnames(result))
colnames(b)<- c("time","mon","value")
b<- cbind(intime,addprice,b)
return(b)
}
moni(45,700,56)
intimearrange<- c(45,48,50)
addpricearrange1<- c(700,800,900,1000)
addpricearrange2<- c(500,600,700,800)
addpricearrange3<- c(400,500,600,700)
re<- as.data.frame(NULL)
for (mm in 1:length(addpricearrange1)){
temp<- moni(intimearrange[1],addpricearrange1[mm],56)
re<- rbind(re,temp)
}
re
result<- as.data.frame(NULL)
result<- rbind(result,re)
re<- as.data.frame(NULL)
for (mm in 1:length(addpricearrange2)){
temp<- moni(intimearrange[2],addpricearrange2[mm],56)
re<- rbind(re,temp)
}
result<- rbind(result,re)
re<- as.data.frame(NULL)
for (mm in 1:length(addpricearrange1)){
temp<- moni(intimearrange[3],addpricearrange3[mm],56)
re<- rbind(re,temp)
}
result<- rbind(result,re)
result
o<-cast(result,time~mon~addprice~intime,sum)
#表格
#提交时间对比
cast(result,time~mon,sum)
#intime对比
cast(result,intime~mon,sum)
#加价幅度对比
cast(result,intime+addprice~mon,sum)
#综合
cast(result,time~mon~addprice~intime,sum)
#图表
p<- ggplot(result,aes(time,mon))+geom_tile(aes(fill=value))+facet_wrap(~intime+addprice)+
scale_fill_gradient2(high="green", low="red") +
labs(x="提交时间", y="年月") +
theme_bw() +
theme(
axis.title.x=element_text(size=16),
axis.title.y=element_text(size=16),
axis.text.x=element_text(size=12, colour="grey50"),
axis.text.y=element_text(size=12, colour="grey50"),
legend.title=element_text(size=14),
legend.text=element_text(size=12),
legend.key.size = unit(0.8, "cm"))#需要载入grid包来调整legend的大小
p
#DT HTML交互
library(DT)
temp<- result
temp$intime<- as.integer(temp$intime)
temp$addprice<- as.integer(temp$addprice)
temp
datatable(temp,colnames=c("加价时间","加价幅度","提交时间","月份","是否中标"),filter = 'top', options = list(
pageLength = 50, autoWidth = TRUE))
temp
#实时查询
temp<- moni(45,1100,56)
temp$value<- as.numeric(temp$value)
cast(temp,mon+time~intime,sum)
hisdata2<- read.csv(file = "C:/Users/chenshengkang/Desktop/hupai2.csv",header = FALSE,sep = ',')
colnames(hisdata2)<- c("date","price","add","s")
hisdata3<- hisdata2[3:4]
plot(hisdata3$s,hisdata3$add)
his_lm<- lm(add~ s+I(s^2),data=hisdata3)
summary(his_lm)
abline(his_lm)
library(car)
scatterplot(s~add,data=hisdata3)
lines(hisdata3$s,fitted(his_lm))