Skip to content

Commit

Permalink
Increased test coverage
Browse files Browse the repository at this point in the history
The tests now includes all indicators and event data
  • Loading branch information
serkor1 committed Dec 9, 2023
1 parent 98ea8ab commit 096c075
Showing 1 changed file with 80 additions and 2 deletions.
82 changes: 80 additions & 2 deletions tests/testthat/test-charting.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ testthat::test_that("Charting with klines, SMA and MACD works as intended", {
) %>% cryptoQuotes::addMA(
FUN = TTR::SMA,
n = 10
) %>% cryptoQuotes::addMACD()
) %>%
cryptoQuotes::addMACD() %>%
cryptoQuotes::addRSI() %>%
cryptoQuotes::addVolume() %>%
cryptoQuotes::addBBands()
}
)

Expand All @@ -30,11 +34,85 @@ testthat::test_that("Charting with ohlc, SMA and MACD works as intended", {
) %>% cryptoQuotes::addMA(
FUN = TTR::SMA,
n = 10
) %>% cryptoQuotes::addMACD()
) %>% cryptoQuotes::addMACD() %>%
cryptoQuotes::addRSI() %>%
cryptoQuotes::addVolume() %>%
cryptoQuotes::addBBands()
}
)

}
)
}
)

testthat::test_that("Charting with klines and adding Eventlines", {
testthat::expect_no_error(
{

# Create Eventdata
set.seed(1903)
event_data <- cryptoQuotes::ATOMUSDT[
sample(1:nrow(cryptoQuotes::ATOMUSDT), size = 2)
]

# 1.1) Extract the index
# from the event data
index <- zoo::index(
event_data
)

# 1.2) Convert the coredata
# into a data.frame
event_data <- as.data.frame(
zoo::coredata(event_data)
)

# 1.3) Add the index into the data.frame
# case insensitive
event_data$index <- index

# 1.4) add events to the data.
# here we use Buys and Sells.
event_data$event <- rep(
x = c('Buy', 'Sell'),
lenght.out = nrow(event_data)
)

# 1.5) add colors based
# on the event; here buy is colored
# darkgrey, and if the position is closed
# with profit the color is green
event_data$color <- ifelse(
event_data$event == 'Buy',
yes = 'darkgrey',
no = ifelse(
subset(event_data, event == 'Buy')$Close < subset(event_data, event == 'Sell')$Close,
yes = 'green',
no = 'red'
)
)

# 1.6) modify the event to add
# closing price at each event
event_data$event <- paste0(
event_data$event, ' @', event_data$Close
)

# 2) Chart the the klines
# and add the buy and sell events
cryptoQuotes::chart(
chart = cryptoQuotes::kline(
ATOMUSDT
) %>% cryptoQuotes::addEvents(
event = event_data
)
)



}
)
}
)

0 comments on commit 096c075

Please sign in to comment.