Código
setwd("/cloud/project")
library(readxl)
library(tidyverse)
library(deflateBR)
library(knitr)
library(forecast)
preco <- readxl::read_excel("SojaM.xlsx")
kable(head(preco), format = "markdown")| Data | spotR | SpotD | cabio | FuturoD | FuturoR |
|---|---|---|---|---|---|
| 2011-02-01 | 51.39 | 30.80 | 1.668506 | 29.84 | 49.78823 |
| 2011-03-01 | 49.54 | 29.86 | 1.659076 | 30.90 | 51.26544 |
| 2011-04-01 | 47.19 | 29.76 | 1.585686 | 30.40 | 48.20484 |
| 2011-05-01 | 47.83 | 29.66 | 1.612610 | 30.55 | 49.26522 |
| 2011-06-01 | 47.88 | 30.16 | 1.587533 | 29.75 | 47.22911 |
| 2011-07-01 | 48.50 | 31.03 | 1.563003 | 31.09 | 48.59378 |
Código
soja <- ts(preco$spotR, frequency = 12, start = c(2011,02,01), end = c(2024,05,01))
sojaF <- ts(preco$FuturoR, frequency = 12, start = c(2011,02,01), end = c(2024,05,01))
times = seq(as.Date("2011/2/1"), by = "month", length.out = length(soja))
spot <- ts(preco$spotR, frequency = 12, start = c(2011,02,01), end = c(2024,05,01)) |>
deflate(nominal_dates = times, real_date = "04/2024", index = "igpm")
futuro <- ts(preco$FuturoR, frequency = 12, start = c(2011,02,01), end = c(2024,05,01)) |>
deflate(nominal_dates = times, real_date = "04/2024", index = "igpm")
plot(spot, main = "Preço Spot da Soja", col = "blue")Código
plot(futuro, main = "Preço Futuro da Soja", col = "red")Código
ts.plot(spot, futuro, col = c("blue", "red"), lty = 1:2, gpars = list(xlab = "Ano", ylab = "Índice", main = "Spot x Futuro"))Código
hist(spot, col = "blue",breaks = 15)Código
hist(futuro, col = "red",breaks = 15)