New Release of {healthyR.ts}

code
rtip
healthyrts
Author

Steven P. Sanderson II, MPH

Published

January 9, 2023

Introduction

Hello R users!

I am excited to announce a new update to the {healthyR.ts} package: the ts_brownian_motion() function.

This function allows you to easily simulate brownian motion, also known as a Wiener process, using just a few parameters. You can specify the length of the simulation using the ‘.time’ parameter, the number of simulations to run using the ‘.num_sims’ parameter, the time step size (standard deviation) using the ‘.delta_time’ parameter, and the initial value (which is set to 0 by default) using the ‘.initial_value’ parameter.

But what is brownian motion, and why might you want to simulate it? Brownian motion is a random process that describes the movement of particles suspended in a fluid. It is named after the botanist Robert Brown, who observed the random movement of pollen grains suspended in water under a microscope in the 19th century.

In finance, brownian motion is often used to model the movement of stock prices over time. By simulating brownian motion, you can get a sense of how prices might fluctuate in the future, and use this information to inform your investment decisions.

I hope that the ts_brownian_motion() function will be a useful tool for anyone interested in simulating brownian motion, whether for financial modeling or any other application. Give it a try and see what you can do with it!

Right now the function is a bit slow at .num_sims > 500 so I am working on optimizing it. I will also later on be introducing the Geometric Brownian Motion to {healthyR.ts}

As always, we welcome feedback and suggestions for new features and improvements. Thank you for using the {healthyR.ts} package, and happy simulating!

Function

Here is the full function call:

ts_brownian_motion(
  .time = 100,
  .num_sims = 10,
  .delta_time = 1,
  .initial_value = 0
)

Example

A simple example of the output.

library(healthyR.ts)

ts_brownian_motion()
# A tibble: 1,010 × 3
   sim_number     t     y
   <fct>      <dbl> <dbl>
 1 1              0  0   
 2 1              1  1.46
 3 1              2  2.68
 4 1              3  2.78
 5 1              4  3.07
 6 1              5  3.43
 7 1              6  3.05
 8 1              7  4.43
 9 1              8  6.04
10 1              9  6.89
# … with 1,000 more rows

Voila!