Analýza ropnej geopolitiky 2010–2026

Author

Norbert Hanáček

Published

October 22, 2026

knitr::opts_chunk$set(
    echo = TRUE,
    message = FALSE,
    warning = FALSE
)

Úloha 1: Načítanie údajov (Read CSV)

Súbor oil_geopolitics_dataset_2010_2026.csv je v podpriečinku udaje. Oddeľovač je čiarka, desatinný znak bodka, prvý riadok obsahuje názvy stĺpcov.

library(dplyr)
library(ggplot2)
library(knitr)
library(kableExtra)

ropa <- read.csv("oil_geopolitics_dataset_2010_2026.csv",
                 header = TRUE, sep = ",", dec = ".")


ropa$date <- as.Date(ropa$date)      # text -> dátum

head(ropa)                           # prvých šesť riadkov
        date brent_price wti_price dxy_index   vix gpr_index brent_return
1 2010-02-17       76.27     77.33     80.38 21.72  80.72536  0.007795935
2 2010-02-18       77.78     79.06     80.40 20.63  80.72536  0.019798115
3 2010-02-19       78.19     79.81     80.64 20.02  80.72536  0.005271325
4 2010-02-22       78.61     80.16     80.51 19.94  80.72536  0.005371507
5 2010-02-23       77.25     78.86     80.85 21.37  80.72536 -0.017300606
6 2010-02-24       78.09     80.00     80.85 20.27  80.72536  0.010873739
    wti_return brent_lag_1 brent_lag_3 brent_lag_7 wti_lag_1 wti_lag_3
1  0.004155300       75.68       73.05       69.59     77.01     75.28
2  0.022371598       76.27       72.90       70.11     77.33     74.13
3  0.009486466       77.78       75.68       72.13     79.06     77.01
4  0.004385492       78.19       76.27       72.54     79.81     77.33
5 -0.016217602       78.61       77.78       73.05     80.16     79.06
6  0.014455990       77.25       78.19       72.90     78.86     79.81
  wti_lag_7 brent_volatility_7d brent_volatility_30d wti_volatility_7d
1     71.19          0.01446055           0.01967906        0.01697708
2     71.89          0.01438747           0.02001918        0.01736603
3     73.75          0.01334209           0.01979589        0.01655310
4     74.52          0.01336596           0.01982289        0.01677207
5     75.28          0.01733358           0.02004482        0.01960840
6     74.13          0.01674453           0.02015997        0.01708107
  wti_volatility_30d brent_wti_spread event_type event_description
1         0.01928020        -1.060005       none              none
2         0.01975580        -1.279999       none              none
3         0.01955948        -1.619995       none              none
4         0.01956102        -1.550003       none              none
5         0.01975645        -1.610001       none              none
6         0.01996491        -1.910004       none              none
  event_severity event_flag
1              0          0
2              0          0
3              0          0
4              0          0
5              0          0
6              0          0
colnames(ropa)                       # názvy premenných
 [1] "date"                 "brent_price"          "wti_price"           
 [4] "dxy_index"            "vix"                  "gpr_index"           
 [7] "brent_return"         "wti_return"           "brent_lag_1"         
[10] "brent_lag_3"          "brent_lag_7"          "wti_lag_1"           
[13] "wti_lag_3"            "wti_lag_7"            "brent_volatility_7d" 
[16] "brent_volatility_30d" "wti_volatility_7d"    "wti_volatility_30d"  
[19] "brent_wti_spread"     "event_type"           "event_description"   
[22] "event_severity"       "event_flag"          
dim(ropa)                            # počet riadkov a stĺpcov
[1] 4047   23
range(ropa$date, na.rm = TRUE)       # časové obdobie
[1] "2010-02-17" "2026-03-12"

Úloha 2: Tabuľka

Ukážka údajov

ropa %>%
  select(date, brent_price, wti_price, dxy_index, vix, gpr_index) %>%
  head(10) %>%
  kable(digits = 2,
        caption = "Prvých 10 záznamov databázy",
        col.names = c("Dátum", "Brent", "WTI", "DXY", "VIX", "GPR"),
        align = "c") %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
                full_width = FALSE, position = "center")
Prvých 10 záznamov databázy
Dátum Brent WTI DXY VIX GPR
2010-02-17 76.27 77.33 80.38 21.72 80.73
2010-02-18 77.78 79.06 80.40 20.63 80.73
2010-02-19 78.19 79.81 80.64 20.02 80.73
2010-02-22 78.61 80.16 80.51 19.94 80.73
2010-02-23 77.25 78.86 80.85 21.37 80.73
2010-02-24 78.09 80.00 80.85 20.27 80.73
2010-02-25 76.29 78.17 80.79 20.10 80.73
2010-02-26 77.59 79.66 80.36 19.50 80.73
2010-03-01 76.89 78.70 80.66 19.26 74.12
2010-03-02 78.18 79.68 80.52 19.06 74.12

Základné štatistiky cien podľa rokov

ropa.stats <- ropa %>%
  mutate(rok = as.integer(format(date, "%Y"))) %>%
  group_by(rok) %>%
  summarise(
    n       = n(),
    mean    = mean(brent_price, na.rm = TRUE),
    sd      = sd(brent_price, na.rm = TRUE),
    min     = min(brent_price, na.rm = TRUE),
    q25     = quantile(brent_price, 0.25, na.rm = TRUE),
    median  = median(brent_price, na.rm = TRUE),
    q75     = quantile(brent_price, 0.75, na.rm = TRUE),
    max     = max(brent_price, na.rm = TRUE),
    .groups = "drop"
  )

ropa.stats %>%
  kable(digits = 2,
        caption = "Základné štatistiky ceny ropy Brent podľa rokov (USD/barel)") %>%
  kable_styling(full_width = FALSE,
                bootstrap_options = c("striped", "hover", "condensed")) %>%
  column_spec(1, bold = TRUE) %>%
  row_spec(0, bold = TRUE, background = "#f2f2f2") %>%
  add_header_above(c(" " = 2, "Brent – popisné štatistiky" = 7))
Základné štatistiky ceny ropy Brent podľa rokov (USD/barel)
Brent – popisné štatistiky
rok n mean sd min q25 median q75 max
2010 222 81.04 5.74 69.55 76.69 79.90 84.83 94.75
2011 252 110.95 6.97 93.33 107.35 111.39 115.46 126.65
2012 250 111.76 7.83 89.23 108.17 111.56 116.74 126.22
2013 252 108.72 4.25 99.13 105.78 109.22 111.22 118.90
2014 252 99.35 14.62 57.33 93.98 106.73 108.69 115.06
2015 252 53.50 8.05 36.11 48.06 53.31 60.25 67.77
2016 253 45.13 6.70 27.88 41.20 46.83 49.69 56.22
2017 251 54.73 4.99 44.82 51.40 54.49 56.88 67.02
2018 251 71.77 6.90 50.47 67.46 73.05 77.00 86.29
2019 252 64.16 4.16 54.91 61.18 63.39 66.91 74.57
2020 253 43.09 10.25 19.33 38.97 43.08 48.71 68.91
2021 252 70.95 7.83 51.09 66.35 71.40 75.45 86.40
2022 251 98.97 11.76 76.10 90.54 96.78 107.56 127.98
2023 251 82.19 5.58 71.84 77.44 82.47 85.81 96.55
2024 252 79.82 5.39 69.19 74.48 79.91 83.66 91.17
2025 253 68.09 5.06 58.92 64.44 66.99 70.78 82.03
2026 48 70.98 9.36 59.96 65.41 68.23 71.53 98.96

Udalosti podľa typu

ropa %>%
  filter(event_type != "none") %>%
  group_by(event_type) %>%
  summarise(
    Pocet          = n(),
    Priem.zavaznost = mean(event_severity, na.rm = TRUE),
    Priem.Brent     = mean(brent_price, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  arrange(desc(Pocet)) %>%
  kable(digits = 2,
        caption = "Geopolitické udalosti podľa typu",
        col.names = c("Typ udalosti", "Počet", "Priem. závažnosť", "Priem. cena Brent")) %>%
  kable_styling(full_width = FALSE,
                bootstrap_options = c("striped", "hover", "condensed"))
Geopolitické udalosti podľa typu
Typ udalosti Počet Priem. závažnosť Priem. cena Brent
sanctions 6 7.83 96.21
conflict 4 8.25 74.23
opec 3 8.00 55.34
war 3 8.67 86.64
blockade 2 9.00 90.19
annexation 1 8.00 106.79
blockage 1 8.00 60.79
diplomatic_crisis 1 6.00 49.47
disaster 1 7.00 84.80
energy_crisis 1 7.00 81.26
market_crash 1 10.00 25.57
market_shift 1 7.00 64.40

Úloha 3: Obrázok (graf)

Vývoj cien Brent a WTI v čase

ggplot(ropa, aes(x = date)) +
  geom_line(aes(y = brent_price, colour = "Brent"), linewidth = 0.5) +
  geom_line(aes(y = wti_price,   colour = "WTI"),   linewidth = 0.5) +
  scale_colour_manual(values = c("Brent" = "darkblue", "WTI" = "darkorange")) +
  labs(title = "Vývoj cien ropy Brent a WTI",
       x = "Rok", y = "Cena (USD/barel)", colour = "Typ ropy") +
  theme_minimal()

Boxplot ceny Brent podľa rokov

ggplot(ropa, aes(x = factor(format(date, "%Y")), y = brent_price)) +
  geom_boxplot(fill = "lightblue", color = "darkblue") +
  labs(title = "Cena ropy Brent podľa rokov",
       x = "Rok", y = "Cena (USD/barel)") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Scatter plot: geopolitické riziko a cena

ggplot(ropa, aes(x = gpr_index, y = brent_price)) +
  geom_point(alpha = 0.3, colour = "darkblue") +
  geom_smooth(method = "lm", colour = "red", se = TRUE) +
  labs(title = "Geopolitické riziko (GPR) a cena ropy Brent",
       x = "GPR index", y = "Brent (USD/barel)") +
  theme_minimal()