This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.

Time Series Classification Synthetic vs Real Financial Time Series – Part VII

See Part IPart II ,Part III, Part IV, Part V and Part VI in this series for instructions from Matthew Smith on which R packages and data sets you need.

Autocorrelation plots:

I plot the Autocorrelation Function for a “random” sample of observations time series. I selected 4 observations and filtered the data by them.

######################################################################
################# ACF plots ##########################################

# I only use 4 observations for these plots, 2 from the “synthetic” class and 2 from the “real” class.

df %>%
filter(row_id == 6422 | row_id == 8967 | row_id == 6080 | row_id == 5734) %>%
mutate(date = as.Date(variable)) %>%
ggplot(aes(x = date)) +
geom_line(aes(y = value), color = “red”, alpha = 0.4) +
geom_hline(yintercept = 0) +
facet_wrap(~ row_id + class) +
theme_tq()

Time Series Classification

acf_data <- df %>%
dplyr::filter(row_id == 6422 | row_id == 8967 | row_id == 6080 | row_id == 5734) %>%
mutate(date = as.Date(variable))

df_acf <- acf_data %>%
group_by(row_id) %>%
summarise(list_acf = list(acf(value, plot=FALSE))) %>%
mutate(acf_vals = purrr::map(list_acf, ~as.numeric(.x$acf))) %>%
select(-list_acf) %>%
unnest() %>%
group_by(row_id) %>%
mutate(lag = row_number() – 1)

df_ci <- acf_data %>%
group_by(row_id) %>%
summarise(ci = qnorm((1 + 0.95)/2)/sqrt(n()))

ggplot(df_acf, aes(x = lag, y = acf_vals)) +
geom_bar(stat=”identity”, width=.05) +
geom_hline(yintercept = 0) +
geom_hline(data = df_ci, aes(yintercept = -ci), color=”blue”, linetype=”dotted”) +
geom_hline(data = df_ci, aes(yintercept = ci), color=”blue”, linetype=”dotted”) +
labs(x=”Lag”, y=”ACF”) +
facet_wrap(~ row_id) +
theme_tq()

Stay tuned for the next installment with a focus on how to generate the financial time series features using the tsfeatures package.

Visit Matthew Smith – R Blog to download the complete R code and see additional details featured in this tutorial: https://lf0.com/post/synth-real-time-series/financial-time-series/

Disclosure: Interactive Brokers

Information posted on IBKR Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from Matthew Smith and is being posted with permission from Matthew Smith. The views expressed in this material are solely those of the author and/or Matthew Smith and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

trading top