From acd1fdfafef4e2410f1f67c91848d154a42719be Mon Sep 17 00:00:00 2001 From: Jacob Amos Date: Thu, 8 Apr 2021 18:57:23 -0400 Subject: [PATCH] major documentation update. moving regression example script and readme. --- README.md | 3 +++ docs/Project.toml | 3 +++ docs/make.jl | 3 ++- docs/src/chaos.md | 4 ++-- docs/src/ma.md | 2 +- docs/src/reg.md | 33 +++++++++++++++++++++++++++++++++ examples/example4.jl | 25 +++++++++++++++++++++++++ 7 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 examples/example4.jl diff --git a/README.md b/README.md index 2c64f31..2bbe5c1 100644 --- a/README.md +++ b/README.md @@ -107,3 +107,6 @@ Indicators is a [Julia](https://julialang.org) package offering efficient implem #### Corn futures daily data ![alt text](https://raw.githubusercontent.com/dysonance/Indicators.jl/master/examples/example3.png "Example 3") +#### Gold Futures Moving Regression +[alt text](https://raw.githubusercontent.com/dysonance/Indicators.jl/master/examples/example4.png "Example 4") + diff --git a/docs/Project.toml b/docs/Project.toml index dfa65cd..205dd2b 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,2 +1,5 @@ [deps] +AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +GLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008" diff --git a/docs/make.jl b/docs/make.jl index ed8bcd4..6f6e964 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,4 +1,4 @@ -using Documenter, Indicators, Plots +using Documenter, Indicators, Plots, GLMakie makedocs( modules = [Indicators], @@ -10,6 +10,7 @@ makedocs( "Volatility Indicators" => "vol.md"], "Exotic" => ["Regressions"=>"reg.md", "Trendlines" => "trendy.md", + "Chaos" => "chaos.md", "Patterns" => "patterns.md"]], format = Documenter.HTML(), doctest=false, diff --git a/docs/src/chaos.md b/docs/src/chaos.md index bd63990..c34748b 100644 --- a/docs/src/chaos.md +++ b/docs/src/chaos.md @@ -23,6 +23,6 @@ savefig("chaos_example.svg") # hide ## Reference ```@autodocs -modules = [Indicators] -pages = ["chaos.jl"] +Modules = [Indicators] +Pages = ["chaos.jl"] ``` diff --git a/docs/src/ma.md b/docs/src/ma.md index d96bbc6..8e03501 100644 --- a/docs/src/ma.md +++ b/docs/src/ma.md @@ -22,5 +22,5 @@ savefig("ma_example.svg") # hide ```@autodocs Modules = [Indicators] -Pages = ["ma.jl"] +Pages = ["ma.jl", "run.jl"] ``` diff --git a/docs/src/reg.md b/docs/src/reg.md index b59ff5d..6b13306 100644 --- a/docs/src/reg.md +++ b/docs/src/reg.md @@ -1,5 +1,38 @@ # Regression Indicators +## Example + +```@example +using Temporal, Indicators, GLMakie + +N = 252 +X = quandl("CHRIS/CME_GC1", rows=N) +x = rename(cl(X), :Settle => :Gold) + +lookback = 20 +n_sigma = 2.0 +reg = mlr_bands(x, n=lookback, se=n_sigma) +coef = mlr_beta(x, n=lookback) +rsq = mlr_rsq(x, n=lookback) + +fig = Figure() +fig[1,1] = Axis(fig, title="Corn Futures") +lines!(fig[1,1], x.values[:,1], label="Price (Observed)", linewidth=3, color=:black) +lines!(fig[1,1], reg[:MLR].values[:], label="Predicted", linewidth=1, color=:blue) +lines!(fig[1,1], reg[:MLRLB].values[:], label="-2 Std Err", linewidth=1, color=:red) +lines!(fig[1,1], reg[:MLRUB].values[:], label="+2 Std Err", linewidth=1, color=:green) +band!(1:N, reg.values[:,1], reg.values[:,3], color="#80800040") +axislegend(bgcolor="#00000040", framecolor="#00000040", position=:cb, orientation=:horizontal) +lines(fig[2,1], 1:N, coef[:Slope].values[:], label="Beta", linewidth=2, color=:purple) +lines!(fig[2,1], 1:N, rsq.values[:], label="R-Squared", linewidth=2, color="#FF8000") +band!(1:N, zeros(N), rsq.values[:], color="#FF800040") +hlines!(current_axis(), [0.0, 1.0], linestyle=:dash, linewidth=1) +axislegend(bgcolor="#00000040", framecolor="#00000040", position=:cb, orientation=:horizontal) +save("reg_example.png", fig) # hide +nothing # hide +``` +![](reg_example.png) + ## Reference ```@autodocs diff --git a/examples/example4.jl b/examples/example4.jl new file mode 100644 index 0000000..61d3e2a --- /dev/null +++ b/examples/example4.jl @@ -0,0 +1,25 @@ +using Temporal, Indicators, GLMakie + +N = 252 +X = quandl("CHRIS/CME_GC1", rows=N) +x = rename(cl(X), :Settle => :Gold) + +lookback = 20 +n_sigma = 2.0 +reg = mlr_bands(x, n=lookback, se=n_sigma) +coef = mlr_beta(x, n=lookback) +rsq = mlr_rsq(x, n=lookback) + +fig = Figure() +fig[1,1] = Axis(fig, title="Corn Futures") +lines!(fig[1,1], x.values[:,1], label="Price (Observed)", linewidth=3, color=:black) +lines!(fig[1,1], reg[:MLR].values[:], label="Predicted", linewidth=1, color=:blue) +lines!(fig[1,1], reg[:MLRLB].values[:], label="-2 Std Err", linewidth=1, color=:red) +lines!(fig[1,1], reg[:MLRUB].values[:], label="+2 Std Err", linewidth=1, color=:green) +band!(1:N, reg.values[:,1], reg.values[:,3], color="#80800040") +axislegend(bgcolor="#00000040", framecolor="#00000040", position=:cb, orientation=:horizontal) +lines(fig[2,1], 1:N, coef[:Slope].values[:], label="Beta", linewidth=2, color=:purple) +lines!(fig[2,1], 1:N, rsq.values[:], label="R-Squared", linewidth=2, color="#FF8000") +band!(1:N, zeros(N), rsq.values[:], color="#FF800040") +hlines!(current_axis(), [0.0, 1.0], linestyle=:dash, linewidth=1) +axislegend(bgcolor="#00000040", framecolor="#00000040", position=:cb, orientation=:horizontal)