From bb4d101ae150a8167383a07c3dc822065536556e Mon Sep 17 00:00:00 2001 From: arthur-brigatto <103693830+arthur-brigatto@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:34:24 -0300 Subject: [PATCH] Add files via upload --- LICENSE | 21 +++++++++++++++++++++ Project.toml | 13 +++++++++++++ README.md | 14 ++++++++++++++ docs/Project.toml | 3 +++ docs/make.jl | 25 +++++++++++++++++++++++++ docs/src/index.md | 14 ++++++++++++++ src/SeasonalNaive.jl | 7 +++++++ src/forecast.jl | 11 +++++++++++ test/runtests.jl | 20 ++++++++++++++++++++ 9 files changed, 128 insertions(+) create mode 100644 LICENSE create mode 100644 Project.toml create mode 100644 README.md create mode 100644 docs/Project.toml create mode 100644 docs/make.jl create mode 100644 docs/src/index.md create mode 100644 src/SeasonalNaive.jl create mode 100644 src/forecast.jl create mode 100644 test/runtests.jl diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..18791dd --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Arthur Brigatto and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..18e2621 --- /dev/null +++ b/Project.toml @@ -0,0 +1,13 @@ +name = "SeasonalNaive" +uuid = "4e5a55a7-a1e0-4c7c-8281-8d51e13076a6" +authors = ["Arthur Brigatto and contributors"] +version = "1.0.0-DEV" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e050bb --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# SeasonalNaive + +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://arthur-brigatto.github.io/SeasonalNaive.jl/stable/) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://arthur-brigatto.github.io/SeasonalNaive.jl/dev/) +[![Build Status](https://github.com/arthur-brigatto/SeasonalNaive.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/arthur-brigatto/SeasonalNaive.jl/actions/workflows/CI.yml?query=branch%3Amaster) +[![Coverage](https://codecov.io/gh/arthur-brigatto/SeasonalNaive.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/arthur-brigatto/SeasonalNaive.jl) + +A Julia package to forecast time series using the seasonal naïve model. + +Forecasts are done using the following equation: + +$`\hat{y}_{T+k} = y_{T+k-m*(\lfloor \frac{k+1}{m}\rfloor + 1)}`$ + +where $m$ is the seasonal period. diff --git a/docs/Project.toml b/docs/Project.toml new file mode 100644 index 0000000..27a7a55 --- /dev/null +++ b/docs/Project.toml @@ -0,0 +1,3 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +SeasonalNaive = "4e5a55a7-a1e0-4c7c-8281-8d51e13076a6" diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 0000000..33a245a --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,25 @@ +using SeasonalNaive +using Documenter + +DocMeta.setdocmeta!(SeasonalNaive, :DocTestSetup, :(using SeasonalNaive); recursive=true) + +makedocs(; + modules=[SeasonalNaive], + authors="Arthur Brigatto and contributors", + repo="https://github.com/arthur-brigatto/SeasonalNaive.jl/blob/{commit}{path}#{line}", + sitename="SeasonalNaive.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://arthur-brigatto.github.io/SeasonalNaive.jl", + edit_link="master", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) + +deploydocs(; + repo="github.com/arthur-brigatto/SeasonalNaive.jl", + devbranch="master", +) diff --git a/docs/src/index.md b/docs/src/index.md new file mode 100644 index 0000000..dc41483 --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1,14 @@ +```@meta +CurrentModule = SeasonalNaive +``` + +# SeasonalNaive + +Documentation for [SeasonalNaive](https://github.com/arthur-brigatto/SeasonalNaive.jl). + +```@index +``` + +```@autodocs +Modules = [SeasonalNaive] +``` diff --git a/src/SeasonalNaive.jl b/src/SeasonalNaive.jl new file mode 100644 index 0000000..01d05e1 --- /dev/null +++ b/src/SeasonalNaive.jl @@ -0,0 +1,7 @@ +module SeasonalNaive + + include("forecast.jl") + + export forecast + +end diff --git a/src/forecast.jl b/src/forecast.jl new file mode 100644 index 0000000..4f30a56 --- /dev/null +++ b/src/forecast.jl @@ -0,0 +1,11 @@ +function forecast(past_data::Vector{Float64}, seasonality::Int64, steps_ahead::Int64) + + forecasts = zeros(steps_ahead)::Vector{Float64} + for k in 1:steps_ahead + forecast = past_data[Int(end + k - seasonality*(floor((k - 1)/seasonality)+1))] + forecasts[k] = forecast + end + + return forecasts + +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..0c23f49 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,20 @@ +using SeasonalNaive +using Test + +@testset "SeasonalNaive.jl" begin + @testset "forecast season 120" begin + past_data = rand(120) + forecasted = forecast(past_data, 120, 120) + @test past_data == forecasted + end + @testset "forecast season 12" begin + past_data = rand(60) + forecasted = forecast(past_data, 12, 12) + @test past_data[end-11: end] == forecasted + end + @testset "forecast season 13" begin + past_data = rand(60) + forecasted = forecast(past_data, 13, 26) + @test [past_data[end-12: end]; past_data[end-12: end]] == forecasted + end +end