Could you please help to simulate in R bivariate Normal distribution (B(x), B(y)) with mean zero and covariance given by cov(B(x),B(y))=min (x,y)
My main challenge is in specifying the covariance min(x,y) in R. I come up with the below code but obviously the code is not correct
library(mvtnorm)
# Set parameters
n <- 100 # Number of time periods
x <- seq(0, 1, length.out = n) # Values of x at each time period
y <- seq(0, 1, length.out = n) # Values of y at each time period
cov_matrix <- matrix(0, n, n) # Initialize the covariance matrix
# Compute covariance matrix
for (i in 1:n) {
for (j in 1:n) {
cov_matrix[i, j] <- min(x[i], y[j])
}
}
# Generate samples from multivariate normal distribution
samples <- mvtnorm::rmvnorm(500, mean = rep(0, n), sigma = cov_matrix)
# # Split samples into B(x) and B(y)
b_x <- samples[, 1:(n/2)] # B(x) values
b_y <- samples[, (n/2+1):n] # B(y) values
# Plot Bivariate Brownian Motion
plot(x = b_x, y = b_y, type = "l", xlim = c(-0.5, 0.5), ylim = c(-0.5, 0.5),
xlab = "B(x)", ylab = "B(y)", main = "Bivariate Brownian Motion")