![]() |
RFOF - RF Library for Orbit Following Codes
|
Module handling samples of Wiener processes (Brownain sample paths) The sample path is stored in a type Wiener_process_sample_path. The time grid use is stored in reversed order, i.e. the starting-time is stored in the last occupied element of the time vector, while the end-time is stored in the first element. This ordering optimizes the use within Monte Carlo codes with adaptive time stepping, in which you often wish to refine the next upcoming time step. With the reversed ordering the "next upcoming time step" is at the end of the vector, thus adding a time point will only require changes to the last few elements of the time-vectors. More...
Data Types | |
type | Wiener_process_sample_path |
Samples from the Wiener process. More... | |
Public Member Functions | |
subroutine | constructor_Wiener_process_sample_path (samplePath, Nelements, time1, time2, rand_normal_distribution) |
Constructor for the type Wiener_process_sample_path. | |
subroutine | destructor_Wiener_process_sample_path (samplePath) |
Destructor for the type Wiener_process_sample_path. | |
subroutine | add_point_on_sample_path (samplePath, new_time, rand_normal_distribution) |
Add point on the sample path by sampling a Brownian bridge. | |
subroutine | add_point_on_sample_path_index_k (k, samplePath, new_time, rand_normal_distribution) |
Add point at index k in the sample path, by sampling a Brownian bridge. | |
subroutine | remove_N_points_from_sample_path (samplePath, Nr_points_to_remove) |
Remove the N first points in the sample path. | |
real(8) function | Brownian_bridge (t0, t1, W0, W1, tn, rand_normal_distribution) |
Generate a point in the sample path of a Wiener process, under the condition of knowing the value of the Wiener process at both the "past" time t0 and the future time t1 . | |
subroutine | extendVectorAllocation (v, Nextra) |
Extend the memory allocation for the vector v by Nextra elements. | |
subroutine | test_sample_path |
Program for testing RFOF_Brownian_sample_paths module. |
Module handling samples of Wiener processes (Brownain sample paths) The sample path is stored in a type Wiener_process_sample_path. The time grid use is stored in reversed order, i.e. the starting-time is stored in the last occupied element of the time vector, while the end-time is stored in the first element. This ordering optimizes the use within Monte Carlo codes with adaptive time stepping, in which you often wish to refine the next upcoming time step. With the reversed ordering the "next upcoming time step" is at the end of the vector, thus adding a time point will only require changes to the last few elements of the time-vectors.
Use in Monte Carlo code for time-stepping:
constructor_Wiener_process_sample_path
, which will give you a sample path with a start and end point.add_point_on_sample_path
. Note that the new time has to occure after the start point of the sample path.remove_N_points_from_sample_path
.dt = samplePath%time( samplePath%Nr_stored_points-1) - samplePath%time( samplePath%Nr_stored_points) dW = samplePath%Wiener(samplePath%Nr_stored_points-1) - samplePath%Wiener(samplePath%Nr_stored_points)
Definition at line 32 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::constructor_Wiener_process_sample_path | ( | type(Wiener_process_sample_path), intent(inout) | samplePath, |
integer, intent(in) | Nelements, | ||
real(8), intent(in) | time1, | ||
real(8), intent(in) | time2, | ||
real(8), intent(in) | rand_normal_distribution | ||
) |
Constructor for the type Wiener_process_sample_path.
INPUT
Nelements | Number of elements to allocate for the vectors. |
time1 | Time at start of sample path. |
time2 | Time at end of sample path. |
rand_normal_distribution | Random number determining the end state of the sample path. |
INPUT/OUTPUT
samplePath | Sample path of a Wiener process (brownian motion). |
Definition at line 64 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::destructor_Wiener_process_sample_path | ( | type(Wiener_process_sample_path), intent(inout) | samplePath | ) |
Destructor for the type Wiener_process_sample_path.
INPUT/OUTPUT
samplePath | Sample path of a Wiener process (brownian motion). |
Definition at line 106 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::add_point_on_sample_path | ( | type(Wiener_process_sample_path), intent(inout) | samplePath, |
real(8), intent(in) | new_time, | ||
real(8), intent(in) | rand_normal_distribution | ||
) |
Add point on the sample path by sampling a Brownian bridge.
INPUT
new_time | Time for new point in sample path. |
rand_normal_distribution | Random number determining the new point in the sample path. |
INPUT/OUTPUT
samplePath | Sample path of a Wiener process (brownian motion). |
Definition at line 127 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::add_point_on_sample_path_index_k | ( | integer, intent(in) | k, |
type(Wiener_process_sample_path), intent(inout) | samplePath, | ||
real(8), intent(in) | new_time, | ||
real(8), intent(in) | rand_normal_distribution | ||
) |
Add point at index k
in the sample path, by sampling a Brownian bridge.
INPUT
k | Index k at which the new sample should be added. |
new_time | Time for new point in sample path. |
rand_normal_distribution | Random number determining the new point in the sample path. |
INPUT/OUTPUT
samplePath | Sample path of a Wiener process (brownian motion). |
Definition at line 186 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::remove_N_points_from_sample_path | ( | type(Wiener_process_sample_path), intent(inout) | samplePath, |
integer, intent(in) | Nr_points_to_remove | ||
) |
Remove the N
first points in the sample path.
INPUT
Nr_points_to_remove | Number of point to be remove in the begnning the sample path |
INPUT/OUTPUT
samplePath | Sample path of a Wiener process (brownian motion). |
Definition at line 240 of file RFOF_wiener_sample_paths.F90.
real(8) function RFOF_wiener_sample_paths::Brownian_bridge | ( | real(8), intent(in) | t0, |
real(8), intent(in) | t1, | ||
real(8), intent(in) | W0, | ||
real(8), intent(in) | W1, | ||
real(8), intent(in) | tn, | ||
real(8), intent(in) | rand_normal_distribution | ||
) |
Generate a point in the sample path of a Wiener process, under the condition of knowing the value of the Wiener process at both the "past" time t0
and the future time t1
.
t0 | Time at of point in sample path |
t1 | Time at previous point in sample path |
W0 | Value of Wiener process at time t0 |
W1 | Value of Wiener process at time t1 |
rand_normal_distribution | Random number determining the new point in the sample path. |
tn | Time at new point to be added to sample path |
Definition at line 266 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::extendVectorAllocation | ( | real(8), dimension(:), intent(inout), pointer | v, |
integer, intent(in) | Nextra | ||
) |
Extend the memory allocation for the vector v
by Nextra
elements.
INPUT
Nextra | Number of point to add to the vector v . |
INPUT/OUTPUT
v | Vector of real number; the length of this vector should be extended by Nextra elements. |
Definition at line 299 of file RFOF_wiener_sample_paths.F90.
subroutine RFOF_wiener_sample_paths::test_sample_path | ( | ) |
Program for testing RFOF_Brownian_sample_paths module.
Output to expect:
path after constructor 2 3 3 2.0000000000000000 1.0000000000000000 1.0000000000000000 0.0000000000000000 new samplePath%Nr_stored_points: 3 1 point added 3 3 3 2.0000000000000000 1.3999999999999999 1.0000000000000000 1.0000000000000000 0.13599999999999990 0.0000000000000000 new samplePath%Nr_stored_points: 4 2 point added 4 6 6 2.0000000000000000 1.8000000000000000 1.3999999999999999 1.0000000000000000 1.0000000000000000 0.81066666666666676 0.13599999999999990 0.0000000000000000 new samplePath%Nr_stored_points: 5 3 point added 5 6 6 2.0000000000000000 1.8000000000000000 1.8000000000000000 1.3999999999999999 1.0000000000000000 1.0000000000000000 0.81066666666666676 0.81066666666666676 0.13599999999999990 0.0000000000000000 new samplePath%Nr_stored_points: 5 3 point added 5 6 6 2.0000000000000000 1.8000000000000000 1.8000000000000000 1.8000000000000000 1.3999999999999999 1.0000000000000000 0.81066666666666676 0.81066666666666676 0.81066666666666676 0.13599999999999990 Error in add_point_on_sample_path: Attempting to add point before the start of the Wiener process ABORT
Definition at line 355 of file RFOF_wiener_sample_paths.F90.