forked from wilsonfreitas/rb3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.R
More file actions
50 lines (43 loc) · 1.26 KB
/
README.R
File metadata and controls
50 lines (43 loc) · 1.26 KB
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
## ----eval=TRUE-----------------------------------------------------------------------------------------------------------------------------
options(rb3.cachedir = tempdir())
devtools::load_all(".")
library(tidyverse)
library(bizdays)
# Download yield curve data for specific dates
fetch_marketdata("b3-reference-rates",
refdate = preceding("2024-01-31", "Brazil/B3"),
curve_name = "PRE"
)
# Download yearly COTAHIST files
fetch_marketdata("b3-cotahist-yearly", year = 2023)
# Download futures data
fetch_marketdata("b3-futures-settlement-prices", refdate = preceding("2024-01-31", "Brazil/B3"))
ch <- cotahist_get("yearly")
# Filter for stocks
eq <- ch |>
filter(year(refdate) == 2023) |>
cotahist_filter_equity() |>
collect()
# Get top 10 most traded stocks
symbols <- eq |>
group_by(symbol) |>
summarise(volume = sum(volume)) |>
arrange(desc(volume)) |>
head(10) |>
collect() |>
pull(symbol)
# Get Brazilian nominal yield curve (PRE)
yc_data <- yc_brl_get() |>
filter(refdate == "2024-01-31") |>
collect()
# Get futures settlement prices
futures_data <- futures_get() |>
filter(commodity == "DI1") |>
collect()
# save datasets: ch, eq, symbols, yc_data, futures_data to file README.RData
save(
eq,
yc_data,
futures_data,
file = "README.RData"
)