Skip to content

Commit 973413d

Browse files
committed
Added examples to docs
1 parent d724ada commit 973413d

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/arma.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ and the inverse Fourier transform.
139139
- `arma::ARMA`: Instance of `ARMA` type
140140
- `;num_autocov::Integer(16)` : The number of autocovariances to calculate
141141
142+
##### Returns
143+
144+
- `acov::Vector{Float64}`: `acov[j]` is the autocovariance between two elements with a lag j.
145+
146+
##### Examples
147+
148+
```julia
149+
using Plots
150+
151+
# AR(2) process
152+
ar = ARMA([0.8 , 0.5], Vector{Float64}(),1)
153+
ar_acov = autocovariance(ar)
154+
plot(1:length(ar_acov),ar_acov,color=:blue, lw=2, marker=:circle, markersize=3, label = "autocovariance")
155+
156+
# ARMA(2,2) process
157+
lp = ARMA([0.8, 0.5], [0.7, 0.3], 0.5)
158+
lp_acov = autocovariance(lp, num_autocov = 50)
159+
plot(1:length(lp_acov),lp_acov,color=:blue, lw=2, marker=:circle, markersize=3, label = "autocovariance")
160+
161+
```
162+
142163
"""
143164
function autocovariance(arma::ARMA; num_autocov::Integer=16)
144165
# Compute the autocovariance function associated with ARMA process arma
@@ -163,6 +184,21 @@ Get the impulse response corresponding to our model.
163184
- `psi::Vector{Float64}`: `psi[j]` is the response at lag j of the impulse
164185
response. We take `psi[1]` as unity.
165186
187+
##### Examples
188+
189+
```julia
190+
using Plots
191+
192+
lp1 = ARMA([0.5],[0.5],1)
193+
response1 = impulse_response(lp1)
194+
plot(1:length(response1),response1,color=:blue, lw=2, marker=:circle, markersize=3)
195+
196+
lp2 = ARMA([0.8, 0.5], [0.7, 0.3], 0.5)
197+
response2 = impulse_response(lp2)
198+
plot(1:length(response2),response2,color=:blue, lw=2, marker=:circle, markersize=3)
199+
200+
```
201+
166202
"""
167203
function impulse_response(arma::ARMA; impulse_length=30)
168204
# Compute the impulse response function associated with ARMA process arma

src/markov/mc_tools.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ state transitions.
2727
2828
- `p::AbstractMatrix` : The transition matrix. Must be square, all elements must be nonnegative, and all rows must sum to unity.
2929
- `state_values::AbstractVector` : Vector containing the values associated with the states.
30+
31+
##### Examples
32+
33+
```julia
34+
# Without labelling states
35+
p1 = [1 0 0; 0 1 0; 0 0 1]
36+
mc1 = MarkovChain(p1)
37+
38+
#Including labels for states
39+
p2 = [0.3 0.7; 0.25 0.75]
40+
states = ["unemployed", "employed"]
41+
mc2 = MarkovChain(p2, states)
42+
```
3043
"""
3144
mutable struct MarkovChain{T, TM<:AbstractMatrix{T}, TV<:AbstractVector}
3245
p::TM # valid stochastic matrix

src/modeltools/utility.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ Additionally, this code assumes that if c < 1e-10 then
1515
1616
u(c) = log(1e-10) + 1e10*(c - 1e-10)
1717
18+
##### Examples
19+
20+
```julia
21+
u1 = LogUtility()
22+
u1(10.)
23+
u1.([1.e-15, 1.e15])
24+
u2 = LogUtility(10)
25+
u2.([10., 1.e-15])
26+
```
27+
1828
"""
1929
struct LogUtility <: AbstractUtility
2030
ξ::Float64

src/zeros.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ sequentially with any bracketing pairs that are found.
114114
- `x1b::Vector{T}`: `Vector` of lower borders of bracketing intervals
115115
- `x2b::Vector{T}`: `Vector` of upper borders of bracketing intervals
116116
117+
##### Examples
118+
119+
```julia
120+
x1a, x2a = divide_bracket(sin, -100., 100.)
121+
122+
function poly(x)
123+
return x^2 - 2x + 1
124+
end
125+
x1b, x2b = divide_bracket(poly, -1., 1., 100)
126+
127+
```
128+
117129
##### References
118130
119131
This is `zbrack` from Numerical Recepies Recepies in C++

0 commit comments

Comments
 (0)