knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(tidyverse)
library(lubridate)
library(ggplot2)
library(readxl)

About this report

data <- read_excel("ptf-smf.xlsx") %>% select("DateTime"=Tarih,PTF,SMF)

data %>% head(10)
## # A tibble: 10 x 3
##    DateTime              PTF   SMF
##    <dttm>              <dbl> <dbl>
##  1 2020-09-01 00:00:00  302.  332.
##  2 2020-09-01 01:00:00  300.  325.
##  3 2020-09-01 02:00:00  293.  318.
##  4 2020-09-01 03:00:00  290   320 
##  5 2020-09-01 04:00:00  290   330 
##  6 2020-09-01 05:00:00  290   339 
##  7 2020-09-01 06:00:00  292.  342.
##  8 2020-09-01 07:00:00  295.  345 
##  9 2020-09-01 08:00:00  307.  339.
## 10 2020-09-01 09:00:00  315.  346.
data %>% glimpse()
## Rows: 720
## Columns: 3
## $ DateTime <dttm> 2020-09-01 00:00:00, 2020-09-01 01:00:00, 2020-09-01 02:00:…
## $ PTF      <dbl> 302.39, 300.25, 292.64, 290.00, 290.00, 290.00, 292.01, 295.…
## $ SMF      <dbl> 332.39, 325.25, 317.64, 320.00, 330.00, 339.00, 342.01, 345.…

We have 720 observation for 3 variables.

Short definition for these variables:

DateTime: Date and time

PTF: Market Clearing Price (MCP) for the orders.

SMF: System Marginal Price (SMP) is single price per hour is reported as a result of balancing

summary(data)
##     DateTime                        PTF             SMF        
##  Min.   :2020-09-01 00:00:00   Min.   :198.4   Min.   : 129.0  
##  1st Qu.:2020-09-08 11:45:00   1st Qu.:292.7   1st Qu.: 275.0  
##  Median :2020-09-15 23:30:00   Median :305.1   Median : 320.0  
##  Mean   :2020-09-15 23:30:00   Mean   :308.2   Mean   : 323.4  
##  3rd Qu.:2020-09-23 11:15:00   3rd Qu.:314.9   3rd Qu.: 351.3  
##  Max.   :2020-09-30 23:00:00   Max.   :982.0   Max.   :2000.0

Now I will add new columns for analyzing these prices on a daily or hourly basis.

data <- data %>% 
  mutate(
    day = lubridate::day(DateTime),
    wday = lubridate::wday(DateTime,label=TRUE),
    hour = lubridate::hour(DateTime)
  )
data %>% group_by(hour) %>% summarise(meanPTF=mean(PTF),meanSMF=mean(SMF)) %>% pivot_longer(.,-hour) %>% ggplot(.,aes(x=hour,y=value,color=name)) + geom_line() + scale_y_continuous(limits = c(0,500)) + theme_minimal()

data %>% group_by(hour) %>% summarise(meanPTF=mean(PTF),meanSMF=mean(SMF)) %>% mutate(ratio=(meanSMF/meanPTF)-1) %>% ggplot(.,aes(x=hour, y=ratio)) + geom_line() + scale_y_continuous(limits = c(-0.2,0.2), breaks = seq(-0.2, 0.2, by=0.04), labels = scales::percent) + theme_minimal()

data %>% filter(hour > 9, hour <= 24) %>% 
  select(PTF,SMF,hour,wday) %>% 
  group_by(wday,hour) %>% 
  summarise(meanPTF=mean(PTF),meanSMF=mean(SMF)) %>% 
  ggplot(.,aes(x=meanPTF,y=meanSMF,color=as.character(hour))) + 
    geom_point() + scale_x_continuous(limits = c(200,1000)) + 
    scale_y_continuous(limits = c(200,1000)) + 
    geom_abline(intercept =0, slope = 1, color="red", size=0.5, alpha=0.5)