We will approximate the distribution of moments when the random walk changes state through simulations.
First, we simulate many paths of Kendall random walk with normal step distribution.
library(kendallRandomWalks)
library(dplyr)
library(ggplot2)
set.seed(17)
walks <- simulate_kendall_rw(1000, 1000, rnorm, 0.5, T)
walks2 <- simulate_kendall_rw(1000, 1000, rcauchy, 0.5, T)
Example trajectory
Number of unique states
ggplot(summarise_kendall_rw(walks, n_distinct), aes(x = aggregated), color = "black") +
theme_bw() +
geom_density() +
geom_density(data = summarise_kendall_rw(walks2, n_distinct), color = "blue") +
ylab("Estimated density") +
xlab("Number of unique values") +
scale_color_discrete(guide = "legend")
Jumps
Time with no change of state
diffs3 <- mutate_kendall_rw(diffs, function(x) as.numeric(x != 0), F)
lengths <- diffs3$simulation %>%
group_by(sim_id) %>%
mutate(id = 1:n()) %>%
filter(sim != 0) %>%
mutate(previous = ifelse(is.na(lag(id)), 0, lag(id))) %>%
mutate(length = id - previous)
diffs4 <- mutate_kendall_rw(diffs2, function(x) as.numeric(x != 0), F)
lengths2 <- diffs4$simulation %>%
group_by(sim_id) %>%
mutate(id = 1:n()) %>%
filter(sim != 0) %>%
mutate(previous = ifelse(is.na(lag(id)), 0, lag(id))) %>%
mutate(length = id - previous)
ggplot(subset(lengths, sim_id < 5),
aes(x = length, fill = as.factor(sim_id), group = as.factor(sim_id))) +
geom_density() +
theme_bw() +
ggtitle("Distribution of time with no state-change (by simulation)")
ggplot(lengths, aes(x = length)) +
geom_density() +
theme_bw() +
xlab("Jump size") +
ggtitle("Distribution of time with no state-change (aggregated)")