Skip to content

Commit

Permalink
Added examples to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaKishore committed Mar 6, 2019
1 parent d724ada commit 973413d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/arma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ and the inverse Fourier transform.
- `arma::ARMA`: Instance of `ARMA` type
- `;num_autocov::Integer(16)` : The number of autocovariances to calculate
##### Returns
- `acov::Vector{Float64}`: `acov[j]` is the autocovariance between two elements with a lag j.
##### Examples
```julia
using Plots
# AR(2) process
ar = ARMA([0.8 , 0.5], Vector{Float64}(),1)
ar_acov = autocovariance(ar)
plot(1:length(ar_acov),ar_acov,color=:blue, lw=2, marker=:circle, markersize=3, label = "autocovariance")
# ARMA(2,2) process
lp = ARMA([0.8, 0.5], [0.7, 0.3], 0.5)
lp_acov = autocovariance(lp, num_autocov = 50)
plot(1:length(lp_acov),lp_acov,color=:blue, lw=2, marker=:circle, markersize=3, label = "autocovariance")
```
"""
function autocovariance(arma::ARMA; num_autocov::Integer=16)
# Compute the autocovariance function associated with ARMA process arma
Expand All @@ -163,6 +184,21 @@ Get the impulse response corresponding to our model.
- `psi::Vector{Float64}`: `psi[j]` is the response at lag j of the impulse
response. We take `psi[1]` as unity.
##### Examples
```julia
using Plots
lp1 = ARMA([0.5],[0.5],1)
response1 = impulse_response(lp1)
plot(1:length(response1),response1,color=:blue, lw=2, marker=:circle, markersize=3)
lp2 = ARMA([0.8, 0.5], [0.7, 0.3], 0.5)
response2 = impulse_response(lp2)
plot(1:length(response2),response2,color=:blue, lw=2, marker=:circle, markersize=3)
```
"""
function impulse_response(arma::ARMA; impulse_length=30)
# Compute the impulse response function associated with ARMA process arma
Expand Down
13 changes: 13 additions & 0 deletions src/markov/mc_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ state transitions.
- `p::AbstractMatrix` : The transition matrix. Must be square, all elements must be nonnegative, and all rows must sum to unity.
- `state_values::AbstractVector` : Vector containing the values associated with the states.
##### Examples
```julia
# Without labelling states
p1 = [1 0 0; 0 1 0; 0 0 1]
mc1 = MarkovChain(p1)
#Including labels for states
p2 = [0.3 0.7; 0.25 0.75]
states = ["unemployed", "employed"]
mc2 = MarkovChain(p2, states)
```
"""
mutable struct MarkovChain{T, TM<:AbstractMatrix{T}, TV<:AbstractVector}
p::TM # valid stochastic matrix
Expand Down
10 changes: 10 additions & 0 deletions src/modeltools/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Additionally, this code assumes that if c < 1e-10 then
u(c) = log(1e-10) + 1e10*(c - 1e-10)
##### Examples
```julia
u1 = LogUtility()
u1(10.)
u1.([1.e-15, 1.e15])
u2 = LogUtility(10)
u2.([10., 1.e-15])
```
"""
struct LogUtility <: AbstractUtility
ξ::Float64
Expand Down
12 changes: 12 additions & 0 deletions src/zeros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ sequentially with any bracketing pairs that are found.
- `x1b::Vector{T}`: `Vector` of lower borders of bracketing intervals
- `x2b::Vector{T}`: `Vector` of upper borders of bracketing intervals
##### Examples
```julia
x1a, x2a = divide_bracket(sin, -100., 100.)
function poly(x)
return x^2 - 2x + 1
end
x1b, x2b = divide_bracket(poly, -1., 1., 100)
```
##### References
This is `zbrack` from Numerical Recepies Recepies in C++
Expand Down

0 comments on commit 973413d

Please sign in to comment.