-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvalue_type.R
53 lines (48 loc) · 1.26 KB
/
value_type.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
# Utility functons and definitions of stock value type
# inspired by the following (somehow, their methods do not work for my usage)
# http://stackoverflow.com/questions/24309910/how-to-get-name-of-variable-in-r-substitute
vname <- function(var) # return string name of var, e.g., vname("foo") = "foo"
{
return (deparse(substitute(var)))
}
# Shall we try variable declaration with possible higher readability?
# (this may be an issue when num. of var is larger...)
# ref.: http://stackoverflow.com/questions/7519790/assign-multiple-new-variables-in-a-single-line-in-r
yield = 1
date = 2
close = 3
volume = 4
adjclose = 5
YIELD = vname(yield)
DATE = vname(date)
CLOSE = vname(close)
VOLUME = vname(volume)
ADJCLOSE = vname(adjclose)
get_name <- function(value_type)
{
switch (value_type,
yield = "殖利率",
date = "日期",
close = "收盤價",
volume = "成交量",
adjclose = "還原權值價格")
}
get_value_name <- function(name)
{
if (name == "殖利率") {
return (vname(yield))
}
if (name == "日期") {
return (vname(date))
}
if (name == "收盤價") {
return (vname(close))
}
if (name == "成交量") {
return (vname(volume))
}
if (name == "還原權值價格") {
return (vname(adjclose))
}
stopifnot(FALSE)
}