Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated syntax @doc #26

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/combine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Base: hcat, vcat, merge
# return ts(yy, x.index, y.fields)
# end

@doc """
"""
Outer join two TS objects by index.

Equivalent to `x` OUTER JOIN `y` ON `x.index` = `y.index`.

`ojoin(x::TS, y::TS)::TS`
""" ->
"""
function ojoin(x::TS, y::TS)::TS
if isempty(x) && !isempty(y)
return y
Expand All @@ -35,13 +35,13 @@ function ojoin(x::TS, y::TS)::TS
return ts([xvals yvals], sort(idx), [x.fields; y.fields])
end

@doc """
"""
Inner join two TS objects by index.

Equivalent to `x` INNER JOIN `y` on `x.index` = `y.index`.

`ijoin(x::TS, y::TS)::TS`
""" ->
"""
function ijoin(x::TS, y::TS)::TS
if isempty(x) && !isempty(y)
return y
Expand All @@ -54,24 +54,24 @@ function ijoin(x::TS, y::TS)::TS
return ts([x[idx].values y[idx].values], idx, [x.fields; y.fields])
end

@doc """
"""
Left join two TS objects by index.

Equivalent to `x` LEFT JOIN `y` ON `x.index` = `y.index`.

`ljoin(x::TS, y::TS)::TS`
""" ->
"""
function ljoin(x::TS, y::TS)::TS
return [x y[intersect(x.index, y.index)]]
end

@doc """
"""
Right join two TS objects by index.

Equivalent to `x` RIGHT JOIN `y` ON `x.index` = `y.index`.

`rjoin(x::TS, y::TS)::TS`
""" ->
"""
function rjoin(x::TS, y::TS)::TS
return [x[intersect(x.index, y.index)] y]
end
Expand Down Expand Up @@ -100,13 +100,13 @@ function vcat(series::TS...)
return out
end

@doc """
"""
Merge two TS objects by index.

The `join` argument specifies the logic used to perform the merge, and may take on the values 'o' (outer join), 'i' (inner join), 'l' (left join), or 'r' (right join). Defaults to outer join, whose result is the same as `hcat(x, y)` or `[x y]`.

`merge(x::TS, y::TS; join::Char='o')::TS`
""" ->
"""
function merge(x::TS, y::TS; join::Char='o')::TS
@assert join == 'o' || join == 'i' || join == 'l' || join == 'r' "`join` must be 'o', 'i', 'l', or 'r'."
if join == 'o'
Expand Down
32 changes: 16 additions & 16 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const YAHOO_TMP = "https://ca.finance.yahoo.com/quote/^GSPC/history?p=^GSPC" #
const QUANDL_URL = "https://www.quandl.com/api/v3/datasets" # for querying quandl's servers
const GOOGLE_URL = "http://finance.google.com/finance/historical?" # for querying google finance's servers

@doc """
"""
Read contents from a text file into a TS object.

`tsread(file::String; dlm::Char=',', header::Bool=true, eol::Char='\\n', indextype::Type=Date, format::String="yyyy-mm-dd")`
Expand All @@ -36,7 +36,7 @@ Index Open High Low Last Change Settle Volume OpenIntere
2016-08-29 316.25 318.75 310.75 312.0 4.5 311.75 111379.0 94676.0
2016-08-30 311.75 312.75 303.5 304.0 7.75 304.0 123102.0 66033.0
```
""" ->
"""
function tsread(file::String; dlm::Char=',', header::Bool=true, eol::Char='\n', indextype::Type=Date, format::String="yyyy-mm-dd")::TS
@assert indextype == Date || indextype == DateTime "Argument `indextype` must be either `Date` or `DateTime`."
csv = Vector{String}(split(read(file, String), eol))
Expand Down Expand Up @@ -67,11 +67,11 @@ function tsread(file::String; dlm::Char=',', header::Bool=true, eol::Char='\n',
return TS(arr, indextype.(idx), fields)
end

@doc """
"""
Write TS object to a text file.

`tswrite(x::TS, file::String; dlm::Char=',', header::Bool=true, eol::Char='\\n')`
""" ->
"""
function tswrite(x::TS, file::String; dlm::Char=',', header::Bool=true, eol::Char='\n')::Nothing
outfile = open(file, "w")
if header
Expand Down Expand Up @@ -154,7 +154,7 @@ end
# ==============================================================================
# QUANDL INTERFACE =============================================================
# ==============================================================================
@doc """
"""
Set up Quandl user account authorization. Run once passing your Quandl API key, and it will be saved for future use.

`quandl_auth{T<:String}(key::T="")::String`
Expand All @@ -169,7 +169,7 @@ julia> quandl_auth("Your_API_Key")
julia> quandl_auth()
"Your_API_Key"
```
""" ->
"""
function quandl_auth(key::T=""; authfile::T=expanduser("~/quandl-auth"))::String where {T<:String}
if key == ""
if isfile(authfile)
Expand All @@ -183,7 +183,7 @@ function quandl_auth(key::T=""; authfile::T=expanduser("~/quandl-auth"))::String
return key
end

@doc """
"""
Download time series data from Quandl as a TS object.
```
quandl(code::String;
Expand Down Expand Up @@ -212,7 +212,7 @@ Index Open High Low Last Change Settle Volume PreviousDayOp
2016-12-31 53.87 54.09 53.41 53.89 0.05 53.72 266762.0 457983.0
2017-12-31 48.47 49.63 48.38 49.6 1.14 49.51 540748.0 606895.0
```
""" ->
"""
function quandl(code::String;
from::String="",
thru::String="",
Expand Down Expand Up @@ -244,22 +244,22 @@ function quandl(code::String;
return TS(indata[1], indata[2], indata[3][2:end])
end

@doc """
"""
Download Quandl metadata for a database and dataset into a Julia Dict object.

`quandl_meta(database::String, dataset::String)`
""" ->
"""
function quandl_meta(database::String, dataset::String)::Dict{String,Any}
resp = HTTP.get("$QUANDL_URL/$database/$dataset/metadata.json")
@assert resp.status == 200 "Error downloading metadata from Quandl."
return JSON.parse(String(resp.body))["dataset"]
end

@doc """
"""
Search Quandl for data in a given database, `db`, or matching a given query, `qry`.

`quandl_search(;db::String="", qry::String="", perpage::Int=1, pagenum::Int=1)`
""" ->
"""
function quandl_search(;db::String="", qry::String="", perpage::Int=1, pagenum::Int=1)
@assert db!="" || qry!="" "Must enter a database or a search query."
dbstr = db == "" ? "" : "database_code=$db&"
Expand All @@ -278,7 +278,7 @@ function yahoo_get_crumb()::Tuple{SubString{String}, Dict{String, HTTP.Cookie}}
return (m[1], HTTP.cookies(response))
end

@doc """
"""
Download stock price data from Yahoo! Finance into a TS object.

`yahoo(symb::String; from::String="1900-01-01", thru::String=string(Dates.today()), freq::String="d", event::String="history", crumb_tuple::Tuple{SubString{String}, Dict{String, HTTP.Cookie}}=yahoo_get_crumb())::TS`
Expand Down Expand Up @@ -309,7 +309,7 @@ Index Open High Low Close Volume AdjClose
2017-03-20 140.4 142.8 139.73 140.64 2.54857e7 140.64
2017-03-27 139.39 144.49 138.62 144.12 2.86449e7 144.12
```
""" ->
"""
function yahoo(symb::String;
from::String="1900-01-01",
thru::String=string(Dates.today()),
Expand Down Expand Up @@ -344,7 +344,7 @@ end
# ==============================================================================
# QUANDL INTERFACE =============================================================
# ==============================================================================
@doc """
"""
Download stock price data from Google Finance into a TS object.

`google(symb::String; from::String="2000-01-01", thru::String=string(Dates.today()))::TS`
Expand Down Expand Up @@ -372,7 +372,7 @@ Index Open High Low Close Volume
2017-05-26 152.85 153.0 152.06 152.49 2.443507e6
2017-05-30 151.95 152.67 151.59 151.73 3.666032e6
```
""" ->
"""
function google(symb::String;
from::String="2000-01-01",
thru::String=string(Dates.today()))::TS
Expand Down
4 changes: 2 additions & 2 deletions src/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ function corlag(x::AbstractArray{T,1}, n::Int=1) where {T<:Number}
return cor(x[idx.-n], x[idx])
end

@doc """
"""
Compute the autocorrelation function of a univariate time series

`acf{T<:Number}(x::AbstractArray{T,1}, maxlag::Int=15; lags::AbstractArray{Int,1}=0:maxlag)`
""" ->
"""
function acf(x::Vector{T}, maxlag::Int=15; lags::AbstractArray{Int,1}=0:maxlag)::Vector{Float64} where {T<:Number}
@assert all(lags .< size(x,1)-2)
return map((n) -> corlag(x, n), lags)
Expand Down
32 changes: 16 additions & 16 deletions src/slice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
Methods for slicing and dicing TS objects
=#

@doc """
"""
Get the first `n` observations of a TS object
""" ->
"""
head(x::TS{V,T}, n::Int=5) where {V,T} = x[1:n,:]

@doc """
"""
Get the last `n` observations of a TS object
""" ->
"""
tail(x::TS{V,T}, n::Int=5) where {V,T} = x[end-n+1:end,:]

@doc """
"""
Get the indexes of all rows in an Array containing NaN values
""" ->
"""
function nanrows(x::Array{Float64}; fun::Function=any)::BitVector
@assert fun == any || fun == all "Argument `fun` must be either `any` or `all`"
cutrows = falses(size(x,1))
Expand All @@ -26,9 +26,9 @@ function nanrows(x::Array{Float64}; fun::Function=any)::BitVector
return cutrows
end

@doc """
"""
Get the indexes of all columns in an Array containing NaN values
""" ->
"""
function nancols(x::Array{Float64}; fun::Function=any)::BitVector
@assert fun == any || fun == all "Argument `fun` must be either `any` or `all`"
cutcols = falses(size(x,2))
Expand All @@ -43,9 +43,9 @@ end
nanrows(x::TS{V,T}; args...) where {V,T} = nanrows(x.values; args...)
nancols(x::TS{V,T}; args...) where {V,T} = nancols(x.values; args...)

@doc """
"""
Drop missing (NaN) values from an Array
""" ->
"""
function dropnan(x::Array{Float64}; dim::Int=1, fun::Function=any)
@assert dim == 1 || dim == 2 || dim == 3 "Argument `dim` must be 1 (rows), 2 (cols), or 3 (both)."
if dim == 1 # rows only
Expand All @@ -58,9 +58,9 @@ function dropnan(x::Array{Float64}; dim::Int=1, fun::Function=any)
end
end

@doc """
"""
Drop missing (NaN) values from a TS object
""" ->
"""
function dropnan(x::TS{V,T}; dim::Int=1, fun::Function=any) where {V,T}
@assert dim == 1 || dim == 2 || dim == 3 "Argument `dim` must be 1 (rows), 2 (columns), or 3 (both)."
if dim == 1
Expand Down Expand Up @@ -137,9 +137,9 @@ function linterp!(x::AbstractArray{Float64,2})
end

# TODO: make this more efficient (learn how to assign and not mutate)
@doc """
"""
Fill missing (NaN) values from a TS object
""" ->
"""
function fillnan(x::TS{V,T}, method::Symbol=:ffill) where {V,T}
c = nancols(x.values)
if !any(c)
Expand All @@ -161,9 +161,9 @@ function fillnan(x::TS{V,T}, method::Symbol=:ffill) where {V,T}
return ts(v, x.index, x.fields)
end

@doc """
"""
Replace missing (NaN) values from a TS object with filled values.
""" ->
"""
function fillnan!(x::TS{V,T}, method::Symbol=:ffill)::Nothing where {V,T}
c = nancols(x.values)
if !any(c)
Expand Down
4 changes: 2 additions & 2 deletions src/ts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ end

abstract type AbstractTS end

@doc """
"""
Time series type aimed at efficiency and simplicity.

Motivated by the `xts` package in R and the `pandas` package in Python.
""" ->
"""
mutable struct TS{V<:Real,T<:TimeType}
values::Matrix{V}
index::Vector{T}
Expand Down