Loading [MathJax]/extensions/tex2jax.js
MRFFL: MR Fortran Finance Library 2024-12-28
Computational Tools For Finance
All Namespaces Files Functions Variables
mrffl_us_inflation.f90
Go to the documentation of this file.
1! -*- Mode:F90; Coding:us-ascii-unix; fill-column:129 -*-
2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.H.S.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.H.E.!!
3!>
4!! @file mrffl_us_inflation.f90
5!! @author Mitch Richling http://www.mitchr.me/
6!! @date 2024-12-19
7!! @brief US inflation data and monte carlo.@EOL
8!! @keywords finance fortran monte carlo inflation cashflow time value of money tvm percentages taxes stock market
9!! @std F2023
10!! @see https://github.com/richmit/FortranFinance
11!! @copyright
12!! @parblock
13!! Copyright (c) 2024, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
14!!
15!! Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
16!! conditions are met:
17!!
18!! 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following
19!! disclaimer.
20!!
21!! 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following
22!! disclaimer in the documentation and/or other materials provided with the distribution.
23!!
24!! 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
25!! derived from this software without specific prior written permission.
26!!
27!! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
28!! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29!! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30!! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
31!! USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32!! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33!! OF THE POSSIBILITY OF SUCH DAMAGE.
34!! @endparblock
35!!
36
37!----------------------------------------------------------------------------------------------------------------------------------
38!> US inflation data and monte carlo.
39!!
41 use mrffl_config, only: rk=>mrfflrk, ik=>mrfflik
42 use mrffl_stats, only: resample_tail
44 implicit none
45 private
46 real(kind=rk), parameter, public :: inf_dat(1914:2023) = [ &
47 1.0, 1.0, 7.9, 17.4, 18.0, 14.6, & ! 1914-1919
48 15.6, -10.5, -6.1, 1.8, 0.0, 2.3, 1.1, -1.7, -1.7, 0.0, & ! 1920-1929
49 -2.3, -9.0, -9.9, -5.1, 3.1, 2.2, 1.5, 3.6, -2.1, -1.4, & ! 1930-1939
50 0.7, 5.0, 10.9, 6.1, 1.7, 2.3, 8.3, 14.4, 8.1, -1.2, & ! 1940-1949
51 1.3, 7.9, 1.9, 0.8, 0.7, -0.4, 1.5, 3.3, 2.8, 0.7, & ! 1950-1959
52 1.7, 1.0, 1.0, 1.3, 1.3, 1.6, 2.9, 3.1, 4.2, 5.5, & ! 1960-1969
53 5.7, 4.4, 3.2, 6.2, 11.0, 9.1, 5.8, 6.5, 7.6, 11.3, & ! 1970-1979
54 13.5, 10.3, 6.2, 3.2, 4.3, 3.6, 1.9, 3.6, 4.1, 4.8, & ! 1980-1989
55 5.4, 4.2, 3.0, 3.0, 2.6, 2.8, 3.0, 2.3, 1.6, 2.2, & ! 1990-1999
56 3.4, 2.8, 1.6, 2.3, 2.7, 3.4, 3.2, 2.8, 3.8, -0.4, & ! 2000-2009
57 1.6, 3.2, 2.1, 1.5, 1.6, 0.1, 1.3, 2.1, 2.4, 1.8, & ! 2010-2019
58 1.2, 4.7, 8.0, 4.1] ! 2020-2023
59
61
62contains
63
64 !--------------------------------------------------------------------------------------------------------------------------------
65 !> Aggregate inflation rate between two years.
66 !! Out of range years cause an ERROR STOP.
67 !!
68 real(kind=rk) pure function inf_aggregate(from_year, to_year)
69 implicit none
70 integer(kind=ik), intent(in) :: from_year, to_year
71 integer(kind=ik) :: year
72 if (from_year < lbound(inf_dat, 1)) error stop "ERROR(inf_aggregate): from_year too small"
73 if (from_year > ubound(inf_dat, 1)) error stop "ERROR(inf_aggregate): from_year too large"
74 if (to_year < lbound(inf_dat, 1)) error stop "ERROR(inf_aggregate): to_year too small"
75 if (to_year > ubound(inf_dat, 1)) error stop "ERROR(inf_aggregate): to_year too large"
76 inf_aggregate = 1.0
77 do year=(min(from_year, to_year)+1_ik),max(from_year, to_year)
79 end do
80 if (from_year > to_year) then
82 else
84 end if
85 end function inf_aggregate
86
87 !--------------------------------------------------------------------------------------------------------------------------------
88 !> Adjust value for inflation from_year to to_year using US inflation data.
89 !! Out of range years cause an ERROR STOP.
90 !!
91 real(kind=rk) pure function inf_adj(from_year, to_year, v)
92 implicit none
93 integer(kind=ik), intent(in) :: from_year, to_year
94 real(kind=rk), intent(in) :: v
95 inf_adj = add_percentage(v, inf_aggregate(from_year, to_year))
96 end function inf_adj
97
98 !--------------------------------------------------------------------------------------------------------------------------------
99 !> Return a random inflation value from the last history_years of US inflation data.
100 !!
101 real(kind=rk) function inf_resample(history_years)
102 implicit none
103 integer(kind=ik), intent(in) :: history_years
104 inf_resample = resample_tail(inf_dat, history_years)
105 end function inf_resample
106
107end module mrffl_us_inflation
Configuration for MRFFL (MR Fortran Finance Library).
integer, parameter, public mrfflrk
Real kind used in interfaces.
integer, parameter, public mrfflik
Integer kinds used in interfaces.
Simple functions for working with percentages.
elemental real(kind=rk) function, public add_percentage(v, p)
Add a percentage of a value to that value.
elemental real(kind=rk) function, public percentage_of(v, p)
Compute the percentage of a value.
elemental real(kind=rk) function, public percentage_change(v_from, v_to)
Compute the percentage change.
Some statstical utilities supporting other MRFFL modules.
real(kind=rk) function, public resample_tail(data, tail_length)
Return random value from among the last tail_length elements of data.
US inflation data and monte carlo.
real(kind=rk) pure function, public inf_adj(from_year, to_year, v)
Adjust value for inflation from_year to to_year using US inflation data.
real(kind=rk) function, public inf_resample(history_years)
Return a random inflation value from the last history_years of US inflation data.
real(kind=rk) pure function, public inf_aggregate(from_year, to_year)
Aggregate inflation rate between two years.
real(kind=rk), dimension(1914:2023), parameter, public inf_dat