File: test-has.R

package info (click to toggle)
r-cran-quantmod 0.4.28-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 984 kB
  • sloc: makefile: 2
file content (94 lines) | stat: -rw-r--r-- 3,444 bytes parent folder | download | duplicates (2)
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
library(quantmod)
library(tinytest)

data(sample_matrix, package = "xts")
stock <- as.xts(sample_matrix)
stock$Volume <- stock$Close
stock$Adjusted <- stock$Close
simple.colnames <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")

# basic functionality
colnames(stock) <- paste("MSFT", simple.colnames, sep = ".")
expect_true(has.Op(stock))
expect_true(has.Hi(stock))
expect_true(has.Lo(stock))
expect_true(has.Cl(stock))
expect_true(has.Vo(stock))
expect_true(has.Ad(stock))
expect_true(is.HLC(stock))
expect_true(all(has.HLC(stock)))
expect_true(is.OHLC(stock))
expect_true(all(has.OHLC(stock)))
expect_true(is.OHLCV(stock))
expect_true(all(has.OHLCV(stock)))

# Test which for has/OHLC functions.
expect_equal(has.Op(stock, which = TRUE), 1)
expect_equal(has.Hi(stock, which = TRUE), 2)
expect_equal(has.Lo(stock, which = TRUE), 3)
expect_equal(has.Cl(stock, which = TRUE), 4)
expect_equal(has.Vo(stock, which = TRUE), 5)
expect_equal(has.Ad(stock, which = TRUE), 6)
expect_equal(has.HLC(stock, which = TRUE), c(2,3,4))
expect_equal(has.OHLC(stock, which = TRUE), c(1,2,3,4))
expect_equal(has.OHLCV(stock, which = TRUE), c(1,2,3,4,5))

#has.OHLC will test underlying has.Op, has.Cl, etc. It will NOT test has.Ad
colnames(stock) <- simple.colnames
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("OPEN", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("HIGH", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("LOW", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("CLOSE", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("VOLUME", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("ADJUSTED", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("ILOW", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("LOW.W", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("LOW_A", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("^LOW", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("My.LOW", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

colnames(stock) <- paste("VLOWY", simple.colnames, sep = ".")
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))

# low in colname returned by function TTR::stoch()
colnames(stock) <- paste("LOW", simple.colnames, sep = ".")
stock$slowD <- stock[,4]
expect_true(all(has.OHLCV(stock)))
expect_equal(has.OHLCV(stock, which = T), c(1,2,3,4,5))
stock$slowD <- NULL