Function to create trading days/weeks from a tsibble/grouped tsibble

TradingDayCreator(data, DateVar, key)

Arguments

data

A tidyquant daily OHLC tibble.

DateVar

A time index for the tsibble.

key

The key for the tsibble supplied.

Value

A tsibble indexed by trading_day. The function will also work with generic messy time units such as weeks.

Examples

data(FANG) TradingDayCreator(FANG, DateVar=date, key=symbol)
#> Joining, by = "symbol"
#> Joining, by = "date"
#> # A tsibble: 4,032 x 9 [1] #> # Key: symbol [4] #> symbol date open high low close volume adjusted trading_day #> <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> #> 1 AMZN 2013-01-02 256. 258. 253. 257. 3271000 257. 1 #> 2 AMZN 2013-01-03 257. 261. 256. 258. 2750900 258. 2 #> 3 AMZN 2013-01-04 258. 260. 257. 259. 1874200 259. 3 #> 4 AMZN 2013-01-07 263. 270. 263. 268. 4910000 268. 4 #> 5 AMZN 2013-01-08 267. 269. 264. 266. 3010700 266. 5 #> 6 AMZN 2013-01-09 268. 270. 265. 266. 2265600 266. 6 #> 7 AMZN 2013-01-10 269. 269. 262. 265. 2863400 265. 7 #> 8 AMZN 2013-01-11 265. 268. 264. 268. 2413300 268. 8 #> 9 AMZN 2013-01-14 268 274. 268. 273. 4275000 273. 9 #> 10 AMZN 2013-01-15 271. 273. 269. 272. 2326900 272. 10 #> # … with 4,022 more rows