From 9d80527524ced723edf7807964c458b38c3f2c43 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Thu, 25 Apr 2024 09:03:44 +0000 Subject: [PATCH] build based on e17f2c6 --- dev/api/index.html | 61 ++- dev/demo_finance/index.html | 208 +++++----- dev/index.html | 2 +- dev/search/index.html | 2 +- dev/search_index.js | 2 +- dev/ts-plot.svg | 122 +++--- dev/user_guide/index.html | 802 ++++++++++++++++++------------------ 7 files changed, 593 insertions(+), 606 deletions(-) diff --git a/dev/api/index.html b/dev/api/index.html index 74d5f30..1980f0a 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -30,7 +30,7 @@ 0.586022 0.586022 0.0521332 0.0521332 0.26864 0.26864 - 0.108871 0.108871source
TSFrames.TSFrameType
struct TSFrame
+ 0.108871   0.108871
source
TSFrames.TSFrameType
struct TSFrame
   coredata :: DataFrame
 end

::TSFrame - A type to hold ordered data with an index.

A TSFrame object is essentially a DataFrame with a specific column marked as an index. The input DataFrame is sorted during construction and is stored under the property coredata. The index is stored in the Index column of coredata.

Permitted data inputs to the constructors are DataFrame, Vector, and 2-dimensional Array. If an index is already not present in the constructor then a sequential integer index is created automatically.

TSFrame(coredata::DataFrame): Here, the constructor looks for a column named Index in coredata as the index column, if this is not found then the first column of coredata is made the index by default. If coredata only has a single column then a new sequential index is generated.

Since TSFrame.coredata is a DataFrame it can be operated upon independently using methods provided by the DataFrames package (ex. transform, combine, etc.).

Constructors

TSFrame(coredata::DataFrame, index::Union{String, Symbol, Int}; issorted = false, copycols = true)
 TSFrame(coredata::DataFrame, index::AbstractVector{T}; issorted = false, copycols = true) where {T<:Union{Int, TimeType}}
@@ -304,18 +304,18 @@
 
 julia> ts = TSFrame(Date, [(Int64, "col1"), (String, "col2"), (Float64, "col3")]) # using strings instead of symbols
 0×3 TSFrame with Date Index
-
source
Base.:==Method

Equality

Two TSFrame are considered equal if their `coredata` property is equal.
+
source
Base.:==Method

Equality

Two TSFrame are considered equal if their `coredata` property is equal.
 Base.:(==)(tsf1::TSFrame, tsf2::TSFrame)::Bool
-Base.isequal(tsf1::TSFrame, tsf2::TSFrame)::Bool
source
Base.firstMethod

First Row

first(ts::TSFrame)

Returns the first row of ts as a TSFrame object.

Examples

julia> first(TSFrame(1:10))
+Base.isequal(tsf1::TSFrame, tsf2::TSFrame)::Bool
source
Base.firstMethod

First Row

first(ts::TSFrame)

Returns the first row of ts as a TSFrame object.

Examples

julia> first(TSFrame(1:10))
 (10 x 1) TSFrame with Dates.Date Index
 
  Index       x1
  Date        Float64
 ───────────────────────
  2022-02-01  0.768448
-
source
Base.iterateFunction

Iterators

Base.iterate(tsf::TSFrame)
+
source
Base.iterateFunction

Iterators

Base.iterate(tsf::TSFrame)
 
-Returns a row-based iterator for `tsf`.
source
Base.joinMethod

Joins/Column-binding

join(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol=:JoinAll)

TSFrame objects can be combined together column-wise using Index as the column key. There are four kinds of column-binding operations possible as of now. Each join operation works by performing a Set operation on the Index column and then merging the datasets based on the output from the Set operation. Each operation changes column names in the final object automatically if the operation encounters duplicate column names amongst the TSFrame objects.

The following join types are supported:

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinInner) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinBoth)

a.k.a. inner join, takes the intersection of the indexes of ts1 and ts2, and then merges the columns of both the objects. The resulting object will only contain rows which are present in both the objects' indexes. The function will rename columns in the final object if they had same names in the TSFrame objects.

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinOuter) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinAll):

a.k.a. outer join, takes the union of the indexes of ts1 and ts2 before merging the other columns of input objects. The output will contain rows which are present in all the input objects while inserting missing values where a row was not present in any of the objects. This is the default behaviour if no jointype is provided.

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinLeft):

Left join takes the index values which are present in the left object ts1 and finds matching index values in the right object ts2. The resulting object includes all the rows from the left object, the column values from the left object, and the values associated with matching index rows on the right. The operation inserts missing values where in the unmatched rows of the right object.

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinRight)

Right join, similar to left join but works in the opposite direction. The final object contains all the rows from the right object while inserting missing values in rows missing from the left object.

The default behaviour is to assume jointype=:JoinAll if no jointype is provided to the join method.

Joining multiple TSFrames is also supported. The syntax is

join(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol)

where jointype must be one of :JoinInner, :JoinBoth, :JoinOuter, :JoinAll, :JoinLeft or :JoinRight. Note that join on multiple TSFrames is left associative.

cbind is an alias for join method.

Examples

julia> using Random;
+Returns a row-based iterator for `tsf`.
source
Base.joinMethod

Joins/Column-binding

join(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol=:JoinAll)

TSFrame objects can be combined together column-wise using Index as the column key. There are four kinds of column-binding operations possible as of now. Each join operation works by performing a Set operation on the Index column and then merging the datasets based on the output from the Set operation. Each operation changes column names in the final object automatically if the operation encounters duplicate column names amongst the TSFrame objects.

The following join types are supported:

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinInner) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinBoth)

a.k.a. inner join, takes the intersection of the indexes of ts1 and ts2, and then merges the columns of both the objects. The resulting object will only contain rows which are present in both the objects' indexes. The function will rename columns in the final object if they had same names in the TSFrame objects.

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinOuter) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinAll):

a.k.a. outer join, takes the union of the indexes of ts1 and ts2 before merging the other columns of input objects. The output will contain rows which are present in all the input objects while inserting missing values where a row was not present in any of the objects. This is the default behaviour if no jointype is provided.

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinLeft):

Left join takes the index values which are present in the left object ts1 and finds matching index values in the right object ts2. The resulting object includes all the rows from the left object, the column values from the left object, and the values associated with matching index rows on the right. The operation inserts missing values where in the unmatched rows of the right object.

join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinRight)

Right join, similar to left join but works in the opposite direction. The final object contains all the rows from the right object while inserting missing values in rows missing from the left object.

The default behaviour is to assume jointype=:JoinAll if no jointype is provided to the join method.

Joining multiple TSFrames is also supported. The syntax is

join(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol)

where jointype must be one of :JoinInner, :JoinBoth, :JoinOuter, :JoinAll, :JoinLeft or :JoinRight. Note that join on multiple TSFrames is left associative.

cbind is an alias for join method.

Examples

julia> using Random;
 
 julia> random(x) = rand(MersenneTwister(123), x);
 
@@ -527,8 +527,8 @@
  2017-01-08  0.0521332  0.0521332  0.0521332
  2017-01-09  0.26864    0.26864    0.26864
  2017-01-10  0.108871   0.108871   0.108871
-
source
Base.sizeMethod

Size methods

size(ts::TSFrame)

Return the number of rows and columns of ts as a tuple.

Examples

julia> TSFrames.size(TSFrame([collect(1:100) collect(1:100) collect(1:100)]))
-(100, 3)
source
Base.vcatMethod

Row-merging (vcat/rbind)

vcat(ts1::TSFrame, ts2::TSFrame; colmerge::Symbol=:union)

Concatenate rows of two TSFrame objects, append ts2 to ts1.

The colmerge keyword argument specifies the column merge strategy. The value of colmerge is directly passed to cols argument of DataFrames.vcat.

Currently, DataFrames.vcat supports four types of column-merge strategies:

  1. :setequal: only merge if both objects have same column names, use the order of columns in ts1.
  2. :orderequal: only merge if both objects have same column names and columns are in the same order.
  3. :intersect: only merge the columns which are common to both objects, ignore the rest.
  4. :union: merge even if columns differ, the resulting object has all the columns filled with missing, if necessary.

Examples

julia> using Random;
+
source
Base.sizeMethod

Size methods

size(ts::TSFrame)

Return the number of rows and columns of ts as a tuple.

Examples

julia> TSFrames.size(TSFrame([collect(1:100) collect(1:100) collect(1:100)]))
+(100, 3)
source
Base.vcatMethod

Row-merging (vcat/rbind)

vcat(ts1::TSFrame, ts2::TSFrame; colmerge::Symbol=:union)

Concatenate rows of two TSFrame objects, append ts2 to ts1.

The colmerge keyword argument specifies the column merge strategy. The value of colmerge is directly passed to cols argument of DataFrames.vcat.

Currently, DataFrames.vcat supports four types of column-merge strategies:

  1. :setequal: only merge if both objects have same column names, use the order of columns in ts1.
  2. :orderequal: only merge if both objects have same column names and columns are in the same order.
  3. :intersect: only merge the columns which are common to both objects, ignore the rest.
  4. :union: merge even if columns differ, the resulting object has all the columns filled with missing, if necessary.

Examples

julia> using Random;
 
 julia> random(x) = rand(MersenneTwister(123), x);
 
@@ -655,7 +655,7 @@
  2017-01-28   0.278259
  2017-01-29   0.0231765
  2017-01-30   0.516704
-
source
RecipesBase.apply_recipeFunction

Plotting

plot(ts::TSFrame, cols::Vector{Int} = collect(1:TSFrames.ncol(ts)))
+
source
RecipesBase.apply_recipeFunction

Plotting

plot(ts::TSFrame, cols::Vector{Int} = collect(1:TSFrames.ncol(ts)))
 plot(ts::TSFrame, cols::Vector{T}) where {T<:Union{String, Symbol}}
 plot(ts::TSFrame, cols::T) where {T<:Union{Int, String, Symbol}}

Plots a TSFrame object with the index on the x-axis and selected cols on the y-axis. By default, plot all the columns. Columns can be selected using Int indexes, String(s), or Symbol(s).

Example

julia> using Random;
 julia> random(x) = rand(MersenneTwister(123), x);
@@ -695,7 +695,7 @@
 julia> # plot(ts[1:6], [:val1, :val3]);
 
 # plot columns 1 and 2 on a specified window size
-julia> # plot(ts, [1, 2], size=(600, 400));
source
TSFrames._check_consistencyMethod

Internal function to check consistency of the Index of a TSFrame object.

source
TSFrames.applyMethod

Apply/Period conversion

apply(ts::TSFrame,
+julia> # plot(ts, [1, 2], size=(600, 400));
source
TSFrames._check_consistencyMethod

Internal function to check consistency of the Index of a TSFrame object.

source
TSFrames.applyMethod

Apply/Period conversion

apply(ts::TSFrame,
       period::T,
       fun::V,
       index_at::Function=first;
@@ -797,7 +797,7 @@
  2017-02-19    0.319216
  2017-02-26    0.272058
  2017-03-05    0.23651
-
source
TSFrames.describeMethod

Summary statistics

describe(ts::TSFrame; cols=:)
+
source
TSFrames.describeMethod

Summary statistics

describe(ts::TSFrame; cols=:)
 describe(ts::TSFrame, stats::Union{Symbol, Pair}...; cols=:)

Compute summary statistics of ts. The output is a DataFrame containing standard statistics along with number of missing values and data types of columns. The cols keyword controls which subset of columns from ts to be selected. The stats keyword is used to control which summary statistics are to be printed. For more information about these keywords, check out the corresponding documentation from DataFrames.jl.

Examples

julia> using Random;
 julia> random(x) = rand(MersenneTwister(123), x...);
 julia> ts = TSFrame(random(([1, 2, 3, 4, missing], 10)))
@@ -833,20 +833,7 @@
      │ Symbol    Int64  Int64
 ─────┼────────────────────────
    1 │ x1            2     22
-
source
TSFrames.endpointsFunction

Computing end points

endpoints(timestamps::AbstractVector{T}, on::V) where {T<:Union{Date, DateTime, Time},
-                                                       V<:Union{
-                                                           Year,
-                                                           Quarter,
-                                                           Month,
-                                                           Week,
-                                                           Day,
-                                                           Hour,
-                                                           Minute,
-                                                           Second,
-                                                           Millisecond,
-                                                           Microsecond,
-                                                           Nanosecond
-                                                       }}
+
source
TSFrames.endpointsFunction

Computing end points

endpoints(timestamps::AbstractVector{T}, on::V) where {T<:Union{Date, DateTime, Time}, V<:Dates.Period}
 endpoints(ts::TSFrame, on::T) where {T<:Dates.Period}
 endpoints(ts::TSFrame, on::Symbol, k::Int=1)
 endpoints(ts::TSFrame, on::String, k::Int=1)
@@ -1079,7 +1066,7 @@
  2022-10-08T11:56:46
  2022-10-08T12:32:08
  2022-10-08T13:59:08
- 2022-10-08T14:37:17
source
TSFrames.headFunction

Head

head(ts::TSFrame, n::Int = 10)

Returns the first n rows of ts.

Examples

julia> head(TSFrame(1:100))
+ 2022-10-08T14:37:17
source
TSFrames.headFunction

Head

head(ts::TSFrame, n::Int = 10)

Returns the first n rows of ts.

Examples

julia> head(TSFrame(1:100))
 (10 x 1) TSFrame with Int64 Index
 
  Index  x1
@@ -1094,7 +1081,7 @@
      7      7
      8      8
      9      9
-    10     10
source
TSFrames.indexMethod

Index column

index(ts::TSFrame)

Return the index vector from the coredata DataFrame.

Examples

julia> using Random;
+    10     10
source
TSFrames.indexMethod

Index column

index(ts::TSFrame)

Return the index vector from the coredata DataFrame.

Examples

julia> using Random;
 
 julia> random(x) = rand(MersenneTwister(123), x);
 
@@ -1132,7 +1119,7 @@
  2022-11-01
 
 julia>  eltype(index(ts))
-Date
source
TSFrames.isregularMethod
isregular(timestamps::V, unit::T) where {V<:AbstractVector{TimeType}, T<:Dates.Period}
+Date
source
TSFrames.isregularMethod
isregular(timestamps::V, unit::T) where {V<:AbstractVector{TimeType}, T<:Dates.Period}
 isregular(timestamps::T) where {T<:AbstractVector{TimeType}}
 isregular(timestamps::AbstractVector{V}, unit::Symbol = :firstdiff) where {V<:TimeType}
 isregular(ts::TSFrame, unit::Symbol = :firstdiff)
@@ -1190,7 +1177,7 @@
 false
 
 julia> isregular(ts, :month)
-false
source
TSFrames.lagFunction

Lagging

lag(ts::TSFrame, lag_value::Int = 1)

Lag the ts object by the specified lag_value. The rows corresponding to lagged values will be rendered as missing. Negative values of lag are also accepted (see TSFrames.lead).

Examples

julia> using Random, Statistics;
+false
source
TSFrames.lagFunction

Lagging

lag(ts::TSFrame, lag_value::Int = 1)

Lag the ts object by the specified lag_value. The rows corresponding to lagged values will be rendered as missing. Negative values of lag are also accepted (see TSFrames.lead).

Examples

julia> using Random, Statistics;
 
 julia> random(x) = rand(MersenneTwister(123), x);
 
@@ -1248,7 +1235,7 @@
  2017-01-08        0.662555
  2017-01-09        0.586022
  2017-01-10        0.0521332
-
source
TSFrames.leadFunction

Leading

lead(ts::TSFrame, lead_value::Int = 1)

Similar to lag, this method leads the ts object by lead_value. The lead rows are inserted with missing. Negative values of lead are also accepted (see TSFrames.lag).

Examples

julia> using Random, Statistics;
+
source
TSFrames.leadFunction

Leading

lead(ts::TSFrame, lead_value::Int = 1)

Similar to lag, this method leads the ts object by lead_value. The lead rows are inserted with missing. Negative values of lead are also accepted (see TSFrames.lag).

Examples

julia> using Random, Statistics;
 
 julia> random(x) = rand(MersenneTwister(123), x);
 
@@ -1314,7 +1301,7 @@
  2017-01-08  0.108871
  2017-01-09  0.163666
  2017-01-10  0.473017
-
source
TSFrames.ncolMethod

Size methods

ncol(ts::TSFrame)

Return the number of columns of ts. nc is an alias for ncol.

Examples

julia> using Random;
+
source
TSFrames.ncolMethod

Size methods

ncol(ts::TSFrame)

Return the number of columns of ts. nc is an alias for ncol.

Examples

julia> using Random;
 
 julia> random(x) = rand(MersenneTwister(123), x);
 
@@ -1322,10 +1309,10 @@
 3
 
 julia> nc(TSFrame([random(100) random(100) random(100)]))
-3
source
TSFrames.nrowMethod

Size methods

nrow(ts::TSFrame)
+3
source
TSFrames.nrowMethod

Size methods

nrow(ts::TSFrame)
 nr(ts::TSFrame)

Return the number of rows of ts. nr is an alias for nrow.

Examples

julia> ts = TSFrame(collect(1:10))
 julia> TSFrames.nrow(ts)
-10
source
TSFrames.rename!Method

Column Rename

rename!(ts::TSFrame, colnames::AbstractVector{String}; makeunique::Bool=false)
+10
source
TSFrames.rename!Method

Column Rename

rename!(ts::TSFrame, colnames::AbstractVector{String}; makeunique::Bool=false)
 rename!(ts::TSFrame, colnames::AbstractVector{Symbol}; makeunique::Bool=false)
 rename!(ts::TSFrame, (from => to)::Pair...)
 rename!(ts::TSFrame, d::AbstractDict)
@@ -1441,7 +1428,7 @@
  2012-01-08      8     18
  2012-01-09      9     19
  2012-01-10     10     20
-
source
TSFrames.rollapplyMethod

Rolling Functions

rollapply(ts::TSFrame, fun::Function, windowsize::Int; bycolumn=true)

Apply function fun to rolling windows of ts. The output is a TSFrame object with (nrow(ts) - windowsize + 1) rows indexed with the last index value of each window.

The bycolumn argument should be set to true (default) if fun is to be applied to each column separately, and to false if fun takes a whole TSFrame as an input.

Examples

julia> rollapply(TSFrame([1:10 11:20]), mean, 5)
+
source
TSFrames.rollapplyMethod

Rolling Functions

rollapply(ts::TSFrame, fun::Function, windowsize::Int; bycolumn=true)

Apply function fun to rolling windows of ts. The output is a TSFrame object with (nrow(ts) - windowsize + 1) rows indexed with the last index value of each window.

The bycolumn argument should be set to true (default) if fun is to be applied to each column separately, and to false if fun takes a whole TSFrame as an input.

Examples

julia> rollapply(TSFrame([1:10 11:20]), mean, 5)
 6×2 TSFrame with Int64 Index
  Index  rolling_x1_mean  rolling_x2_mean 
  Int64  Float64          Float64         
@@ -1488,7 +1475,7 @@
  2001-01-07  ([1.0], 4.86475e-16)
  2001-01-08  ([1.0], 7.43103e-16)
  2001-01-09  ([1.0], 7.45753e-15)
- 2001-01-10  ([1.0], 9.28561e-15)
source
TSFrames.subsetMethod

Subsetting based on Index

subset(ts::TSFrame, from::T, to::T) where {T<:Union{Int, TimeType}}

Create a subset of ts based on the Index starting from (inclusive) till to (inclusive).

Examples

julia> using Random;
+ 2001-01-10  ([1.0], 9.28561e-15)
source
TSFrames.subsetMethod

Subsetting based on Index

subset(ts::TSFrame, from::T, to::T) where {T<:Union{Int, TimeType}}

Create a subset of ts based on the Index starting from (inclusive) till to (inclusive).

Examples

julia> using Random;
 julia> random(x) = rand(MersenneTwister(123), x);
 julia> dates = Date("2022-02-01"):Week(1):Date("2022-02-01")+Month(9);
 julia> ts = TSFrame(random(length(dates)), dates)
@@ -1612,7 +1599,7 @@
  2022-10-25  0.621379
  2022-11-01  0.348173
 
-
source
TSFrames.tailFunction

Tail

tail(ts::TSFrame, n::Int = 10)

Returns the last n rows of ts.

julia> tail(TSFrame(1:100))
+
source
TSFrames.tailFunction

Tail

tail(ts::TSFrame, n::Int = 10)

Returns the last n rows of ts.

julia> tail(TSFrame(1:100))
 (10 x 1) TSFrame with Int64 Index
 
  Index  x1
@@ -1627,7 +1614,7 @@
     97     97
     98     98
     99     99
-   100    100
source
TSFrames.to_periodMethod

Frequency conversion

Set of convenience methods for frequency conversion of TimeType index types. Internally, they call endpoints() to do the actual conversion. n is the number of periods of the period type. For example, to_monthly(tsf, 2) will resample the time series to "every 2 months".

to_period(tsf::TSFrame, period::T)::TSFrame where {T<:Period}
+   100    100
source
TSFrames.to_periodMethod

Frequency conversion

Set of convenience methods for frequency conversion of TimeType index types. Internally, they call endpoints() to do the actual conversion. n is the number of periods of the period type. For example, to_monthly(tsf, 2) will resample the time series to "every 2 months".

to_period(tsf::TSFrame, period::T)::TSFrame where {T<:Period}
 to_yearly(tsf::TSFrame, n=1)::TSFrame
 to_quarterly(tsf::TSFrame, n=1)::TSFrame
 to_monthly(tsf::TSFrame, n=1)::TSFrame
@@ -1638,4 +1625,4 @@
 to_seconds(tsf::TSFrame, n=1)::TSFrame
 to_milliseconds(tsf::TSFrame, n=1)::TSFrame
 to_microseconds(tsf::TSFrame, n=1)::TSFrame
-to_nanoseconds(tsf::TSFrame, n=1)::TSFrame
source
+to_nanoseconds(tsf::TSFrame, n=1)::TSFramesource diff --git a/dev/demo_finance/index.html b/dev/demo_finance/index.html index df3605d..5634dee 100644 --- a/dev/demo_finance/index.html +++ b/dev/demo_finance/index.html @@ -1,6 +1,6 @@ Basic demo of TSFrames · TSFrames.jl

Basic demo of TSFrames using financial data

Create a TSFrame object for IBM historical data

To load the IBM historical data, we will use the MarketData.yahoo function from MarketData.jl, which returns the data in the form of a TimeArray. We just simply pass this on to the TSFrame constructor.

julia> using TSFrames, MarketData, Plots, Statistics, ImputeERROR: ArgumentError: Package Impute not found in current path.
-- Run `import Pkg; Pkg.add("Impute")` to install the Impute package.
julia> ibm_ts = TSFrame(MarketData.yahoo(:IBM))13394×6 TSFrame with Date Index +- Run `import Pkg; Pkg.add("Impute")` to install the Impute package.
julia> ibm_ts = TSFrame(MarketData.yahoo(:IBM))13419×6 TSFrame with Date Index Index Open High Low Close AdjClose Volume Date Float64 Float64 Float64 Float64 Float64 Float64 ────────────────────────────────────────────────────────────────────────────── @@ -9,38 +9,38 @@ 1971-02-10 16.1568 16.1568 15.9775 16.1209 3.55327 648520.0 1971-02-11 16.1209 16.2285 16.097 16.1926 3.56908 579484.0 1971-02-12 16.1926 16.2285 16.1329 16.2285 3.57698 382836.0 - 1971-02-16 16.2285 16.4197 16.1926 16.3301 3.59936 684084.0 + 1971-02-16 16.2285 16.4197 16.1926 16.3301 3.59937 684084.0 1971-02-17 16.2703 16.2703 16.0492 16.0851 3.54537 652704.0 1971-02-18 16.0851 16.1209 15.7385 15.7385 3.46898 822156.0 ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ - 2024-03-11 195.09 195.38 190.88 191.73 191.73 4.7251e6 - 2024-03-12 192.46 199.18 192.15 197.78 197.78 5.8801e6 - 2024-03-13 197.55 198.1 195.32 196.7 196.7 3.9933e6 - 2024-03-14 196.95 197.75 192.12 193.43 193.43 4.1096e6 - 2024-03-15 191.99 193.06 190.7 191.07 191.07 8.8279e6 - 2024-03-18 191.7 193.23 190.32 191.69 191.69 5.4106e6 - 2024-03-19 191.49 193.58 190.28 193.34 193.34 5.317e6 - 13379 rows omitted

Create TSFrame object for AAPL

Similarly, we can create a TSFrame object for the AAPL data.

julia> aapl_ts = TSFrame(MarketData.yahoo(:AAPL))10907×6 TSFrame with Date Index
+ 2024-04-16  185.59    185.71    182.86    183.75    183.75          4.4737e6
+ 2024-04-17  184.16    184.67    181.78    183.1     183.1           3.003e6
+ 2024-04-18  182.35    183.46    180.17    181.47    181.47          2.8867e6
+ 2024-04-19  182.43    182.8     180.57    181.58    181.58          3.0376e6
+ 2024-04-22  182.45    183.32    180.45    181.9     181.9           3.0765e6
+ 2024-04-23  182.73    184.68    179.0     182.19    182.19          5.9502e6
+ 2024-04-24  183.17    184.29    181.4     184.1     184.1           7.5576e6
+                                                            13404 rows omitted

Create TSFrame object for AAPL

Similarly, we can create a TSFrame object for the AAPL data.

julia> aapl_ts = TSFrame(MarketData.yahoo(:AAPL))10932×6 TSFrame with Date Index
  Index       Open        High        Low         Close       AdjClose    Volum ⋯
  Date        Float64     Float64     Float64     Float64     Float64     Float ⋯
 ────────────────────────────────────────────────────────────────────────────────
  1980-12-12    0.128348    0.128906    0.128348    0.128348    0.099192  4.690 ⋯
  1980-12-15    0.12221     0.12221     0.121652    0.121652    0.094017  1.758
- 1980-12-16    0.113281    0.113281    0.112723    0.112723    0.087116  1.057
+ 1980-12-16    0.113281    0.113281    0.112723    0.112723    0.087117  1.057
  1980-12-17    0.115513    0.116071    0.115513    0.115513    0.089273  8.644
  1980-12-18    0.118862    0.11942     0.118862    0.118862    0.091861  7.344 ⋯
  1980-12-19    0.126116    0.126674    0.126116    0.126116    0.097467  4.863
  1980-12-22    0.132254    0.132813    0.132254    0.132254    0.102211  3.736
  1980-12-23    0.137835    0.138393    0.137835    0.137835    0.106524  4.695
      ⋮           ⋮           ⋮           ⋮           ⋮           ⋮           ⋮ ⋱
- 2024-03-11  172.94      174.38      172.05      172.75      172.75      6.013 ⋯
- 2024-03-12  173.15      174.03      171.01      173.23      173.23      5.982
- 2024-03-13  172.77      173.19      170.76      171.13      171.13      5.248
- 2024-03-14  172.91      174.31      172.05      173.0       173.0       7.291
- 2024-03-15  171.17      172.62      170.29      172.62      172.62      1.216 ⋯
- 2024-03-18  175.57      177.71      173.52      173.72      173.72      7.560
- 2024-03-19  174.34      176.61      173.03      176.08      176.08      5.513
-                                                 1 column and 10892 rows omitted

Create a 6-month subset of stock data

We would like to compare the stock returns for both the stocks for 6 months starting from June 1, 2021 till December 31, 2021. We use TSFrames.subset method to create new objects which contain the specified duration of data.

julia> date_from = Date(2021, 06, 01);
julia> date_to = Date(2021, 12, 31);
julia> ibm = TSFrames.subset(ibm_ts, date_from, date_to)150×6 TSFrame with Date Index + 2024-04-16 171.75 173.76 168.27 169.38 169.38 7.371 ⋯ + 2024-04-17 169.61 170.65 168.0 168.0 168.0 5.090 + 2024-04-18 168.03 168.64 166.55 167.04 167.04 4.312 + 2024-04-19 166.21 166.4 164.08 165.0 165.0 6.777 + 2024-04-22 165.52 167.26 164.77 165.84 165.84 4.811 ⋯ + 2024-04-23 165.35 167.05 164.92 166.9 166.9 4.953 + 2024-04-24 166.54 169.3 166.21 169.02 169.02 4.812 + 1 column and 10917 rows omitted

Create a 6-month subset of stock data

We would like to compare the stock returns for both the stocks for 6 months starting from June 1, 2021 till December 31, 2021. We use TSFrames.subset method to create new objects which contain the specified duration of data.

julia> date_from = Date(2021, 06, 01);
julia> date_to = Date(2021, 12, 31);
julia> ibm = TSFrames.subset(ibm_ts, date_from, date_to)150×6 TSFrame with Date Index Index Open High Low Close AdjClose Volume Date Float64 Float64 Float64 Float64 Float64 Float64 ───────────────────────────────────────────────────────────────────── @@ -48,7 +48,7 @@ 2021-06-02 138.26 139.34 137.772 139.312 122.249 2.9151e6 2021-06-03 138.537 139.465 137.706 139.149 122.106 4.32061e6 2021-06-04 139.579 141.061 139.35 140.937 123.675 3.26132e6 - 2021-06-07 141.061 142.199 140.698 141.511 124.179 3.62198e6 + 2021-06-07 141.061 142.199 140.698 141.511 124.178 3.62198e6 2021-06-08 141.606 143.595 141.606 142.514 125.059 5.31378e6 2021-06-09 142.476 144.426 142.275 144.044 126.402 5.54725e6 2021-06-10 144.809 146.119 143.174 143.92 126.293 4.97739e6 @@ -74,7 +74,7 @@ 2021-06-10 127.02 128.19 125.94 126.11 124.159 7.11864e7 ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ 2021-12-22 173.04 175.86 172.15 175.64 173.435 9.21353e7 - 2021-12-23 175.85 176.85 175.27 176.28 174.067 6.83566e7 + 2021-12-23 175.85 176.85 175.27 176.28 174.066 6.83566e7 2021-12-27 177.09 180.42 177.07 180.33 178.066 7.49196e7 2021-12-28 180.16 181.33 178.53 179.29 177.039 7.91443e7 2021-12-29 179.33 180.63 178.14 179.38 177.128 6.23489e7 @@ -88,13 +88,13 @@ 2021-06-02 122.249 123.125 2021-06-03 122.106 121.629 2021-06-04 123.675 123.942 - 2021-06-07 124.179 123.952 + 2021-06-07 124.178 123.952 2021-06-08 125.059 124.779 2021-06-09 126.402 125.163 2021-06-10 126.293 124.159 ⋮ ⋮ ⋮ 2021-12-22 116.706 173.435 - 2021-12-23 117.498 174.067 + 2021-12-23 117.498 174.066 2021-12-27 118.388 178.066 2021-12-28 119.297 177.039 2021-12-29 119.944 177.128 @@ -108,13 +108,13 @@ 2021-06-02 122.249 123.125 2021-06-03 122.106 121.629 2021-06-04 123.675 123.942 - 2021-06-07 124.179 123.952 + 2021-06-07 124.178 123.952 2021-06-08 125.059 124.779 2021-06-09 126.402 125.163 2021-06-10 126.293 124.159 ⋮ ⋮ ⋮ 2021-12-22 116.706 173.435 - 2021-12-23 117.498 174.067 + 2021-12-23 117.498 174.066 2021-12-27 118.388 178.066 2021-12-28 119.297 177.039 2021-12-29 119.944 177.128 @@ -138,120 +138,120 @@ 2021-12-03 106.893 159.808 2021-12-10 111.615 177.197 2021-12-17 114.592 168.991 - 2021-12-23 117.498 174.067 + 2021-12-23 117.498 174.066 2021-12-31 120.223 175.34 16 rows omitted

Compute weekly returns using the familiar log and diff functions

julia> ibm_aapl_weekly_returns = diff(log.(ibm_aapl_weekly))31×2 TSFrame with Date Index
  Index       IBM_log           AAPL_log
  Date        Float64?          Float64?
 ────────────────────────────────────────────────
  2021-06-04  missing           missing
- 2021-06-11        0.0258467         0.0115308
- 2021-06-18       -0.0554491         0.0241274
- 2021-06-25        0.0256603         0.020109
- 2021-07-02       -0.0475582         0.0501812
- 2021-07-09        0.0106556         0.0361352
- 2021-07-16       -0.0186869         0.00878229
- 2021-07-23        0.0174141         0.0147144
+ 2021-06-11        0.0258468         0.0115307
+ 2021-06-18       -0.055449          0.0241273
+ 2021-06-25        0.0256603         0.0201095
+ 2021-07-02       -0.0475582         0.0501808
+ 2021-07-09        0.0106557         0.0361355
+ 2021-07-16       -0.018687          0.00878208
+ 2021-07-23        0.0174141         0.0147147
      ⋮              ⋮                 ⋮
  2021-11-19       -0.0247661         0.0680367
- 2021-11-26       -0.0020703        -0.0235705
- 2021-12-03        0.0258271         0.0315733
- 2021-12-10        0.0432291         0.103288
- 2021-12-17        0.0263246        -0.0474146
- 2021-12-23        0.0250371         0.0295917
- 2021-12-31        0.0229303         0.00729144
+ 2021-11-26       -0.0020703        -0.0235704
+ 2021-12-03        0.025827          0.031573
+ 2021-12-10        0.0432291         0.103289
+ 2021-12-17        0.0263248        -0.0474146
+ 2021-12-23        0.0250371         0.0295916
+ 2021-12-31        0.0229303         0.00729136
                                  16 rows omitted
julia> TSFrames.rename!(ibm_aapl_weekly_returns, [:IBM, :AAPL])31×2 TSFrame with Date Index Index IBM AAPL Date Float64? Float64? ──────────────────────────────────────────────── 2021-06-04 missing missing - 2021-06-11 0.0258467 0.0115308 - 2021-06-18 -0.0554491 0.0241274 - 2021-06-25 0.0256603 0.020109 - 2021-07-02 -0.0475582 0.0501812 - 2021-07-09 0.0106556 0.0361352 - 2021-07-16 -0.0186869 0.00878229 - 2021-07-23 0.0174141 0.0147144 + 2021-06-11 0.0258468 0.0115307 + 2021-06-18 -0.055449 0.0241273 + 2021-06-25 0.0256603 0.0201095 + 2021-07-02 -0.0475582 0.0501808 + 2021-07-09 0.0106557 0.0361355 + 2021-07-16 -0.018687 0.00878208 + 2021-07-23 0.0174141 0.0147147 ⋮ ⋮ ⋮ 2021-11-19 -0.0247661 0.0680367 - 2021-11-26 -0.0020703 -0.0235705 - 2021-12-03 0.0258271 0.0315733 - 2021-12-10 0.0432291 0.103288 - 2021-12-17 0.0263246 -0.0474146 - 2021-12-23 0.0250371 0.0295917 - 2021-12-31 0.0229303 0.00729144 - 16 rows omitted

Compute standard deviation of weekly returns

Computing standard deviation is done using the std function from Statistics package. The skipmissing is used to skip missing values which may have been generated while computing log returns or were already present in the data.

julia> ibm_std = std(skipmissing(ibm_aapl_weekly_returns[:, :IBM]))0.034079299383423495
julia> aapl_std = std(skipmissing(ibm_aapl_weekly_returns[:, :AAPL]))0.030582290427209696

Scatter plot of AAPL and IBM

Here, we use the Plots package to create a scatter plot with IBM weekly returns on the x-axis and Apple weekly returns on the y-axis.

plot(ibm_aapl_weekly_returns[:, :AAPL],
+ 2021-11-26       -0.0020703        -0.0235704
+ 2021-12-03        0.025827          0.031573
+ 2021-12-10        0.0432291         0.103289
+ 2021-12-17        0.0263248        -0.0474146
+ 2021-12-23        0.0250371         0.0295916
+ 2021-12-31        0.0229303         0.00729136
+                                 16 rows omitted

Compute standard deviation of weekly returns

Computing standard deviation is done using the std function from Statistics package. The skipmissing is used to skip missing values which may have been generated while computing log returns or were already present in the data.

julia> ibm_std = std(skipmissing(ibm_aapl_weekly_returns[:, :IBM]))0.03407925932018218
julia> aapl_std = std(skipmissing(ibm_aapl_weekly_returns[:, :AAPL]))0.030582272016784234

Scatter plot of AAPL and IBM

Here, we use the Plots package to create a scatter plot with IBM weekly returns on the x-axis and Apple weekly returns on the y-axis.

plot(ibm_aapl_weekly_returns[:, :AAPL],
     ibm_aapl_weekly_returns[:, :IBM],
     seriestype = :scatter;
     xlabel = "AAPL",
     ylabel = "IBM",
     legend = false)

Aggregation and rolling window operations

Here, we compute realised volatility of returns of both IBM and Apple stock weekly and bi-monthly. Then, we compute daily returns volatility on a rolling basis with a window size of 10.

julia> daily_returns = diff(log.(ibm_aapl))150×2 TSFrame with Date Index
- Index       IBM_log           AAPL_log
- Date        Float64?          Float64?
-─────────────────────────────────────────────────
- 2021-06-01  missing           missing
- 2021-06-02        0.0105551         0.00625657
- 2021-06-03       -0.00116735       -0.0122287
- 2021-06-04        0.0127661         0.0188436
- 2021-06-07        0.00406161        7.94693e-5
- 2021-06-08        0.00706863        0.00664985
- 2021-06-09        0.0106761         0.00307242
- 2021-06-10       -0.00086313       -0.00805569
-     ⋮              ⋮                  ⋮
- 2021-12-22        0.00602969        0.0152027
- 2021-12-23        0.0067594         0.00363725
- 2021-12-27        0.00755           0.0227149
- 2021-12-28        0.00764438       -0.00578402
- 2021-12-29        0.00541392        0.000502097
- 2021-12-30        0.00419079       -0.00660025
- 2021-12-31       -0.00186875       -0.00354125
-                                 135 rows omitted
julia> rvol = apply(daily_returns, Week(1), std) # Compute the realised volatility31×2 TSFrame with Date Index + Index IBM_log AAPL_log + Date Float64? Float64? +────────────────────────────────────────────────── + 2021-06-01 missing missing + 2021-06-02 0.0105553 0.00625651 + 2021-06-03 -0.00116728 -0.0122286 + 2021-06-04 0.0127659 0.0188435 + 2021-06-07 0.0040616 7.94047e-5 + 2021-06-08 0.007069 0.00664985 + 2021-06-09 0.0106759 0.00307237 + 2021-06-10 -0.000863312 -0.00805564 + ⋮ ⋮ ⋮ + 2021-12-22 0.00602969 0.0152026 + 2021-12-23 0.00675946 0.00363716 + 2021-12-27 0.00755001 0.022715 + 2021-12-28 0.00764437 -0.00578402 + 2021-12-29 0.00541398 0.000502013 + 2021-12-30 0.00419073 -0.0066 + 2021-12-31 -0.00186874 -0.00354159 + 135 rows omitted
julia> rvol = apply(daily_returns, Week(1), std) # Compute the realised volatility31×2 TSFrame with Date Index Index IBM_log_std AAPL_log_std Date Float64? Float64? ──────────────────────────────────────────────── 2021-06-01 missing missing - 2021-06-07 0.00423144 0.00685038 - 2021-06-14 0.00515155 0.0140528 - 2021-06-21 0.0135566 0.00849511 - 2021-06-28 0.022242 0.00681128 - 2021-07-06 0.0077469 0.0123476 - 2021-07-12 0.00554725 0.0145982 - 2021-07-19 0.00913881 0.0201179 + 2021-06-07 0.00423146 0.00685033 + 2021-06-14 0.00515149 0.0140531 + 2021-06-21 0.0135566 0.00849503 + 2021-06-28 0.022242 0.00681127 + 2021-07-06 0.00774695 0.0123478 + 2021-07-12 0.00554723 0.0145982 + 2021-07-19 0.00913886 0.0201181 ⋮ ⋮ ⋮ - 2021-11-15 0.00421507 0.0107341 - 2021-11-22 0.00524026 0.017536 - 2021-11-29 0.014216 0.0188585 - 2021-12-06 0.00430291 0.0142466 - 2021-12-13 0.0139502 0.0249443 - 2021-12-20 0.0071901 0.0122394 + 2021-11-15 0.00421515 0.0107342 + 2021-11-22 0.00524026 0.0175358 + 2021-11-29 0.0142161 0.0188586 + 2021-12-06 0.00430293 0.0142466 + 2021-12-13 0.0139501 0.0249443 + 2021-12-20 0.00719018 0.0122395 2021-12-27 0.00389373 0.0121978 16 rows omitted
julia> rvol = apply(daily_returns, Month(2), std) # Every two months4×2 TSFrame with Date Index Index IBM_log_std AAPL_log_std Date Float64? Float64? ─────────────────────────────────────────────── 2021-06-01 missing missing - 2021-08-02 0.00863796 0.0124996 + 2021-08-02 0.00863794 0.0124996 2021-10-01 0.0187055 0.0131257 - 2021-12-01 0.00792973 0.0184033
julia> rollapply(daily_returns, std, 10) # Compute rolling vols141×2 TSFrame with Date Index + 2021-12-01 0.00792972 0.0184034
julia> rollapply(daily_returns, std, 10) # Compute rolling vols141×2 TSFrame with Date Index Index rolling_IBM_log_std rolling_AAPL_log_std Date Float64? Float64? ─────────────────────────────────────────────────────── - 2021-06-14 missing missing - 2021-06-15 0.00703763 0.0115999 - 2021-06-16 0.00777313 0.0115779 - 2021-06-17 0.00939336 0.0103008 - 2021-06-18 0.0096533 0.0105066 - 2021-06-21 0.0128877 0.0109084 - 2021-06-22 0.0125777 0.0111714 - 2021-06-23 0.0121089 0.0114156 + 2021-06-14 missing missing + 2021-06-15 0.00703764 0.0116 + 2021-06-16 0.00777309 0.011578 + 2021-06-17 0.00939335 0.0103009 + 2021-06-18 0.00965329 0.0105068 + 2021-06-21 0.0128877 0.0109086 + 2021-06-22 0.0125776 0.0111715 + 2021-06-23 0.0121089 0.0114157 ⋮ ⋮ ⋮ - 2021-12-22 0.0102034 0.0220221 - 2021-12-23 0.0102077 0.0220114 - 2021-12-27 0.0102132 0.0213968 - 2021-12-28 0.0079822 0.0202206 - 2021-12-29 0.00799232 0.0199266 - 2021-12-30 0.00678748 0.0179653 - 2021-12-31 0.00534796 0.0116642 + 2021-12-22 0.0102034 0.0220221 + 2021-12-23 0.0102076 0.0220114 + 2021-12-27 0.0102131 0.0213968 + 2021-12-28 0.00798225 0.0202205 + 2021-12-29 0.00799237 0.0199266 + 2021-12-30 0.00678751 0.0179653 + 2021-12-31 0.00534801 0.0116642 126 rows omitted

Rolling regression with a window of 10

One of the common finance problems is to run a rolling window regression of firm returns over market returns. For doing this, we will use the lm() function from the GLM package. We will create a separate function regress() which would take in the data as an argument and use pre-defined strings to identify the returns columns, pass them to lm(), and return the results.

We start by downloading the S&P500 daily data from Yahoo Finance, then performing the same steps as above to come to a joined TSFrame object containing daily returns of S&P500 and IBM stock prices. Then, use rollapply() with bycolumn=false to tell rollapply() to pass in the entire TSFrame to the function in one go for each iteration within the window.

julia> sp500 = TSFrame(MarketData.yahoo("^GSPC"));
julia> sp500_adjclose = TSFrames.subset(sp500, date_from, date_to)[:, ["AdjClose"]]150×1 TSFrame with Date Index Index AdjClose Date Float64 @@ -278,4 +278,4 @@ sd::Real = Statistics.std(residuals(ll)) return (co, sd) endERROR: LoadError: UndefVarError: `@formula` not defined -in expression starting at REPL[6]:2
julia> rollapply(sp500_ibm_returns, regress, 10, bycolumn=false)ERROR: UndefVarError: `sp500_ibm_returns` not defined
+in expression starting at REPL[6]:2
julia> rollapply(sp500_ibm_returns, regress, 10, bycolumn=false)ERROR: UndefVarError: `sp500_ibm_returns` not defined diff --git a/dev/index.html b/dev/index.html index 11ca167..3e26a4d 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Introduction · TSFrames.jl

TSFrames.jl

TSFrames provides a convenient interface for performing standard manipulations of timeseries data. The package uses DataFrame at it's core to allow powerful data manipulation functions while being lightweight. It is inspired by zoo and xts packages from the R world.

TSFrames wraps a familiar syntax for timeseries operations over DataFrame type, thereby, providing the user with full set of DataFrame functionalities as well. Integrations with other packages in the Julia ecosystem which are supported by DataFrames.jl come to TSFrames at little cost.

To start using TSFrames.jl take a look at the basic demo and then head to the User guide.

User guide

API reference

+Introduction · TSFrames.jl

TSFrames.jl

TSFrames provides a convenient interface for performing standard manipulations of timeseries data. The package uses DataFrame at it's core to allow powerful data manipulation functions while being lightweight. It is inspired by zoo and xts packages from the R world.

TSFrames wraps a familiar syntax for timeseries operations over DataFrame type, thereby, providing the user with full set of DataFrame functionalities as well. Integrations with other packages in the Julia ecosystem which are supported by DataFrames.jl come to TSFrames at little cost.

To start using TSFrames.jl take a look at the basic demo and then head to the User guide.

User guide

API reference

diff --git a/dev/search/index.html b/dev/search/index.html index 0b32924..3b7d224 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · TSFrames.jl

Loading search...

    +Search · TSFrames.jl

    Loading search...

      diff --git a/dev/search_index.js b/dev/search_index.js index 6e00492..7c21e51 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"api/","page":"API reference","title":"API reference","text":"CurrentModule = TSFrames","category":"page"},{"location":"api/#TSFrames-API-reference","page":"API reference","title":"TSFrames API reference","text":"","category":"section"},{"location":"api/","page":"API reference","title":"API reference","text":"API reference of TSFrames.","category":"page"},{"location":"api/","page":"API reference","title":"API reference","text":"","category":"page"},{"location":"api/","page":"API reference","title":"API reference","text":"Modules = [TSFrames]","category":"page"},{"location":"api/#Base.Matrix-Tuple{TSFrame}","page":"API reference","title":"Base.Matrix","text":"Conversion of non-Index data to Matrix\n\nData in non-index columns of a TSFrame object can be converted into a Matrix type for further numerical analysis using the Matrix() constructor.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> ts = TSFrame([random(10) random(10)])\njulia> show(ts)\n(10 x 2) TSFrame with Int64 Index\n\n Index x1 x2\n Int64 Float64 Float64\n─────────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n 4 0.395453 0.395453\n 5 0.313244 0.313244\n 6 0.662555 0.662555\n 7 0.586022 0.586022\n 8 0.0521332 0.0521332\n 9 0.26864 0.26864\n 10 0.108871 0.108871\n\njulia> Matrix(ts)\n10×2 Matrix{Float64}:\n 0.768448 0.768448\n 0.940515 0.940515\n 0.673959 0.673959\n 0.395453 0.395453\n 0.313244 0.313244\n 0.662555 0.662555\n 0.586022 0.586022\n 0.0521332 0.0521332\n 0.26864 0.26864\n 0.108871 0.108871\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.TSFrame","page":"API reference","title":"TSFrames.TSFrame","text":"struct TSFrame\n coredata :: DataFrame\nend\n\n::TSFrame - A type to hold ordered data with an index.\n\nA TSFrame object is essentially a DataFrame with a specific column marked as an index. The input DataFrame is sorted during construction and is stored under the property coredata. The index is stored in the Index column of coredata.\n\nPermitted data inputs to the constructors are DataFrame, Vector, and 2-dimensional Array. If an index is already not present in the constructor then a sequential integer index is created automatically.\n\nTSFrame(coredata::DataFrame): Here, the constructor looks for a column named Index in coredata as the index column, if this is not found then the first column of coredata is made the index by default. If coredata only has a single column then a new sequential index is generated.\n\nSince TSFrame.coredata is a DataFrame it can be operated upon independently using methods provided by the DataFrames package (ex. transform, combine, etc.).\n\nConstructors\n\nTSFrame(coredata::DataFrame, index::Union{String, Symbol, Int}; issorted = false, copycols = true)\nTSFrame(coredata::DataFrame, index::AbstractVector{T}; issorted = false, copycols = true) where {T<:Union{Int, TimeType}}\nTSFrame(coredata::DataFrame; issorted = false, copycols = true)\nTSFrame(coredata::DataFrame, index::UnitRange{Int}; issorted = false, copycols = true)\nTSFrame(coredata::AbstractVector{T}, index::AbstractVector{V}; colnames=:auto, issorted = false, copycols = true) where {T, V}\nTSFrame(coredata::AbstractVector{T}; colnames=:auto, issorted = false, copycols = true) where {T}\nTSFrame(coredata::AbstractArray{T,2}; colnames=:auto, issorted = false, copycols = true) where {T}\nTSFrame(coredata::AbstractArray{T,2}, index::AbstractVector{V}; colnames=:auto, issorted = false, copycols = true) where {T, V}\nTSFrame(IndexType::DataType; n::Int=1)\nTSFrame(IndexType::DataType, cols::Vector{Tuple{DataType, S}}; issorted = false, copycols = true) where S <: Union{Symbol, String}\n\nWhen issorted is true, no sort operations are performed on the input. Whencopycolsistrue, the inputs are not copied, but placed directly in the TSFrame. This can be dangerous, so please only set this tofalse` if the input arrays will not be mutated later.\n\nissorted = true, copycols = false offers performance benefits, especially when constructing TSFrames in loops or other performance sensitive code.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> df = DataFrame(x1 = random(10))\n10×1 DataFrame\n Row │ x1\n │ Float64\n─────┼───────────\n 1 │ 0.768448\n 2 │ 0.940515\n 3 │ 0.673959\n 4 │ 0.395453\n 5 │ 0.313244\n 6 │ 0.662555\n 7 │ 0.586022\n 8 │ 0.0521332\n 9 │ 0.26864\n 10 │ 0.108871\n\njulia> ts = TSFrame(df) # generates index\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Float64\n──────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n 4 0.395453\n 5 0.313244\n 6 0.662555\n 7 0.586022\n 8 0.0521332\n 9 0.26864\n 10 0.108871\n\n# ts.coredata is a DataFrame\njulia> combine(ts.coredata, :x1 => Statistics.mean, DataFrames.nrow)\n1×2 DataFrame\n Row │ x1_mean nrow\n │ Float64 Int64\n─────┼────────────────\n 1 │ 0.49898 418\n\njulia> df = DataFrame(ind = [1, 2, 3], x1 = random(3))\n3×2 DataFrame\n Row │ ind x1\n │ Int64 Float64\n─────┼─────────────────\n 1 │ 1 0.768448\n 2 │ 2 0.940515\n 3 │ 3 0.673959\n\njulia> ts = TSFrame(df, 1) # the first column is index\n(3 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Float64\n─────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n\njulia> df = DataFrame(x1 = random(3), x2 = random(3), Index = [1, 2, 3]);\n3×3 DataFrame\n Row │ x1 x2 Index\n │ Float64 Float64 Int64\n─────┼───────────────────────────\n 1 │ 0.768448 0.768448 1\n 2 │ 0.940515 0.940515 2\n 3 │ 0.673959 0.673959 3\n\njulia> ts = TSFrame(df) # uses existing `Index` column\n(3 x 2) TSFrame with Int64 Index\n\n Index x1 x2\n Int64 Float64 Float64\n───────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> df = DataFrame(dates = dates, x1 = random(10))\n10×2 DataFrame\n Row │ dates x1\n │ Date Float64\n─────┼───────────────────────\n 1 │ 2017-01-01 0.768448\n 2 │ 2017-01-02 0.940515\n 3 │ 2017-01-03 0.673959\n 4 │ 2017-01-04 0.395453\n 5 │ 2017-01-05 0.313244\n 6 │ 2017-01-06 0.662555\n 7 │ 2017-01-07 0.586022\n 8 │ 2017-01-08 0.0521332\n 9 │ 2017-01-09 0.26864\n 10 │ 2017-01-10 0.108871\n\njulia> ts = TSFrame(df, :dates)\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> ts = TSFrame(DataFrame(x1=random(10)), dates);\n\njulia> ts = TSFrame(random(10))\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Float64\n──────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n 4 0.395453\n 5 0.313244\n 6 0.662555\n 7 0.586022\n 8 0.0521332\n 9 0.26864\n 10 0.108871\n\njulia> ts = TSFrame(random(10), colnames=[:A]) # column is named A\n(10 x 1) TSFrame with Int64 Index\n\n Index A\n Int64 Float64\n──────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n 4 0.395453\n 5 0.313244\n 6 0.662555\n 7 0.586022\n 8 0.0521332\n 9 0.26864\n 10 0.108871\n\njulia> ts = TSFrame(random(10), dates)\n(10 x 1) TSFrame with Date Index\n\n Index x1 \n Date Float64 \n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> ts = TSFrame(random(10), dates, colnames=[:A]) # column is named A\n(10 x 1) TSFrame with Date Index\n\n Index A \n Date Float64 \n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> ts = TSFrame([random(10) random(10)]) # matrix object\n(10 x 2) TSFrame with Int64 Index\n\n Index x1 x2 \n Int64 Float64 Float64 \n─────────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n 4 0.395453 0.395453\n 5 0.313244 0.313244\n 6 0.662555 0.662555\n 7 0.586022 0.586022\n 8 0.0521332 0.0521332\n 9 0.26864 0.26864\n 10 0.108871 0.108871\n\njulia> ts = TSFrame([random(10) random(10)], colnames=[:A, :B]) # columns are named A and B\n(10 x 2) TSFrame with Int64 Index\n\n Index A B \n Int64 Float64 Float64 \n─────────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n 4 0.395453 0.395453\n 5 0.313244 0.313244\n 6 0.662555 0.662555\n 7 0.586022 0.586022\n 8 0.0521332 0.0521332\n 9 0.26864 0.26864\n 10 0.108871 0.108871\n\njulia> ts = TSFrame([random(10) random(10)], dates) \n(10 x 2) TSFrame with Date Index\n\n Index x1 x2\n Date Float64 Float64\n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\njulia> ts = TSFrame([random(10) random(10)], dates, colnames=[:A, :B]) # columns are named A and B\n(10 x 2) TSFrame with Date Index\n\n Index A B \n Date Float64 Float64 \n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\njulia> ts = TSFrame(Int64; n=5) # empty TSFrame with 5 columns of type Any and with Int64 index type\n0×5 TSFrame with Int64 Index\n\njulia> ts = TSFrame(Date, [(Int64, :col1), (String, :col2), (Float64, :col3)]) # empty TSFrame with specific column names and types\n0×3 TSFrame with Date Index\n\njulia> ts = TSFrame(Date, [(Int64, \"col1\"), (String, \"col2\"), (Float64, \"col3\")]) # using strings instead of symbols\n0×3 TSFrame with Date Index\n\n\n\n\n\n\n","category":"type"},{"location":"api/#Base.:==-Tuple{TSFrame, TSFrame}","page":"API reference","title":"Base.:==","text":"Equality\n\nTwo TSFrame are considered equal if their `coredata` property is equal.\nBase.:(==)(tsf1::TSFrame, tsf2::TSFrame)::Bool\nBase.isequal(tsf1::TSFrame, tsf2::TSFrame)::Bool\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.first-Tuple{TSFrame}","page":"API reference","title":"Base.first","text":"First Row\n\nfirst(ts::TSFrame)\n\nReturns the first row of ts as a TSFrame object.\n\nExamples\n\njulia> first(TSFrame(1:10))\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-02-01 0.768448\n\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.iterate","page":"API reference","title":"Base.iterate","text":"Iterators\n\nBase.iterate(tsf::TSFrame)\n\nReturns a row-based iterator for `tsf`.\n\n\n\n\n\n","category":"function"},{"location":"api/#Base.join-Tuple{TSFrame, TSFrame, Vararg{Any}}","page":"API reference","title":"Base.join","text":"Joins/Column-binding\n\njoin(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol=:JoinAll)\n\nTSFrame objects can be combined together column-wise using Index as the column key. There are four kinds of column-binding operations possible as of now. Each join operation works by performing a Set operation on the Index column and then merging the datasets based on the output from the Set operation. Each operation changes column names in the final object automatically if the operation encounters duplicate column names amongst the TSFrame objects.\n\nThe following join types are supported:\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinInner) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinBoth)\n\na.k.a. inner join, takes the intersection of the indexes of ts1 and ts2, and then merges the columns of both the objects. The resulting object will only contain rows which are present in both the objects' indexes. The function will rename columns in the final object if they had same names in the TSFrame objects.\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinOuter) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinAll):\n\na.k.a. outer join, takes the union of the indexes of ts1 and ts2 before merging the other columns of input objects. The output will contain rows which are present in all the input objects while inserting missing values where a row was not present in any of the objects. This is the default behaviour if no jointype is provided.\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinLeft):\n\nLeft join takes the index values which are present in the left object ts1 and finds matching index values in the right object ts2. The resulting object includes all the rows from the left object, the column values from the left object, and the values associated with matching index rows on the right. The operation inserts missing values where in the unmatched rows of the right object.\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinRight)\n\nRight join, similar to left join but works in the opposite direction. The final object contains all the rows from the right object while inserting missing values in rows missing from the left object.\n\nThe default behaviour is to assume jointype=:JoinAll if no jointype is provided to the join method.\n\nJoining multiple TSFrames is also supported. The syntax is\n\njoin(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol)\n\nwhere jointype must be one of :JoinInner, :JoinBoth, :JoinOuter, :JoinAll, :JoinLeft or :JoinRight. Note that join on multiple TSFrames is left associative.\n\ncbind is an alias for join method.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> ts1 = TSFrame(random(length(dates)), dates);\njulia> show(ts1)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,30));\n\njulia> ts2 = TSFrame(random(length(dates)), dates);\njulia> show(ts2)\n30×1 TSFrame with Date Index\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n 2017-01-11 0.163666\n 2017-01-12 0.473017\n 2017-01-13 0.865412\n 2017-01-14 0.617492\n 2017-01-15 0.285698\n 2017-01-16 0.463847\n 2017-01-17 0.275819\n 2017-01-18 0.446568\n 2017-01-19 0.582318\n 2017-01-20 0.255981\n 2017-01-21 0.70586\n 2017-01-22 0.291978\n 2017-01-23 0.281066\n 2017-01-24 0.792931\n 2017-01-25 0.20923\n 2017-01-26 0.918165\n 2017-01-27 0.614255\n 2017-01-28 0.802665\n 2017-01-29 0.555668\n 2017-01-30 0.940782\n\n# join on all index values\n# equivalent to `join(ts1, ts2; jointype=:JoinAll)` call\njulia> join(ts1, ts2)\n(30 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64? Float64?\n────────────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n ⋮ ⋮ ⋮\n 2017-01-22 missing 0.291978\n 2017-01-23 missing 0.281066\n 2017-01-24 missing 0.792931\n 2017-01-25 missing 0.20923\n 2017-01-26 missing 0.918165\n 2017-01-27 missing 0.614255\n 2017-01-28 missing 0.802665\n 2017-01-29 missing 0.555668\n 2017-01-30 missing 0.940782\n 11 rows omitted\n\n# alias to `join()`\njulia> cbind(ts1, ts2);\n\n# join only the common index values\njulia> join(ts1, ts2; jointype=:JoinBoth)\n(10 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64 Float64\n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\n# keep index values of `ts1`\njulia> join(ts1, ts2; jointype=:JoinLeft)\n(10 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64 Float64?\n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\n# keep index values of `ts2`\njulia> join(ts1, ts2; jointype=:JoinRight)\n(30 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64? Float64\n────────────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n ⋮ ⋮ ⋮\n 2017-01-22 missing 0.291978\n 2017-01-23 missing 0.281066\n 2017-01-24 missing 0.792931\n 2017-01-25 missing 0.20923\n 2017-01-26 missing 0.918165\n 2017-01-27 missing 0.614255\n 2017-01-28 missing 0.802665\n 2017-01-29 missing 0.555668\n 2017-01-30 missing 0.940782\n 11 rows omitted\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,30));\n\njulia> ts3 = TSFrame(random(length(dates)), dates);\njulia> show(ts3)\n30×1 TSFrame with Date Index\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n 2017-01-11 0.163666\n 2017-01-12 0.473017\n 2017-01-13 0.865412\n 2017-01-14 0.617492\n 2017-01-15 0.285698\n 2017-01-16 0.463847\n 2017-01-17 0.275819\n 2017-01-18 0.446568\n 2017-01-19 0.582318\n 2017-01-20 0.255981\n 2017-01-21 0.70586\n 2017-01-22 0.291978\n 2017-01-23 0.281066\n 2017-01-24 0.792931\n 2017-01-25 0.20923\n 2017-01-26 0.918165\n 2017-01-27 0.614255\n 2017-01-28 0.802665\n 2017-01-29 0.555668\n 2017-01-30 0.940782\n\n# joining multiple TSFrame objects\njulia> join(ts1, ts2, ts3; jointype=:JoinLeft)\n10×3 TSFrame with Date Index\n Index x1 x1_1 x1_2\n Date Float64 Float64? Float64?\n─────────────────────────────────────────────\n 2017-01-01 0.768448 0.768448 0.768448\n 2017-01-02 0.940515 0.940515 0.940515\n 2017-01-03 0.673959 0.673959 0.673959\n 2017-01-04 0.395453 0.395453 0.395453\n 2017-01-05 0.313244 0.313244 0.313244\n 2017-01-06 0.662555 0.662555 0.662555\n 2017-01-07 0.586022 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864 0.26864\n 2017-01-10 0.108871 0.108871 0.108871\n\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.size-Tuple{TSFrame}","page":"API reference","title":"Base.size","text":"Size methods\n\nsize(ts::TSFrame)\n\nReturn the number of rows and columns of ts as a tuple.\n\nExamples\n\njulia> TSFrames.size(TSFrame([collect(1:100) collect(1:100) collect(1:100)]))\n(100, 3)\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.vcat-Tuple{TSFrame, TSFrame}","page":"API reference","title":"Base.vcat","text":"Row-merging (vcat/rbind)\n\nvcat(ts1::TSFrame, ts2::TSFrame; colmerge::Symbol=:union)\n\nConcatenate rows of two TSFrame objects, append ts2 to ts1.\n\nThe colmerge keyword argument specifies the column merge strategy. The value of colmerge is directly passed to cols argument of DataFrames.vcat.\n\nCurrently, DataFrames.vcat supports four types of column-merge strategies:\n\n:setequal: only merge if both objects have same column names, use the order of columns in ts1.\n:orderequal: only merge if both objects have same column names and columns are in the same order.\n:intersect: only merge the columns which are common to both objects, ignore the rest.\n:union: merge even if columns differ, the resulting object has all the columns filled with missing, if necessary.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates1 = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> dates2 = collect(Date(2017,1,11):Day(1):Date(2017,1,30));\n\njulia> ts1 = TSFrame([randn(length(dates1)) randn(length(dates1))], dates1)\njulia> show(ts1)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n────────────────────────\n 2017-01-01 -0.420348\n 2017-01-02 0.109363\n 2017-01-03 -0.0702014\n 2017-01-04 0.165618\n 2017-01-05 -0.0556799\n 2017-01-06 -0.147801\n 2017-01-07 -2.50723\n 2017-01-08 -0.099783\n 2017-01-09 0.177526\n 2017-01-10 -1.08461\n\njulia> df = DataFrame(x1 = randn(length(dates2)), y1 = randn(length(dates2)))\njulia> ts2 = TSFrame(df, dates2)\njulia> show(ts2)\n(20 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n────────────────────────\n 2017-01-11 2.15087\n 2017-01-12 0.9203\n 2017-01-13 -0.0879142\n 2017-01-14 -0.930109\n 2017-01-15 0.061117\n 2017-01-16 0.0434627\n 2017-01-17 0.0834733\n 2017-01-18 -1.52281\n ⋮ ⋮\n 2017-01-23 -0.756143\n 2017-01-24 0.491623\n 2017-01-25 0.549672\n 2017-01-26 0.570689\n 2017-01-27 -0.380011\n 2017-01-28 -2.09965\n 2017-01-29 1.37289\n 2017-01-30 -0.462384\n 4 rows omitted\n\n\njulia> vcat(ts1, ts2)\n(30 x 3) TSFrame with Date Index\n\n Index x1 x2 y1\n Date Float64 Float64? Float64?\n─────────────────────────────────────────────────────────\n 2017-01-01 -0.524798 -1.4949 missing\n 2017-01-02 -0.719611 -1.1278 missing\n 2017-01-03 0.0926092 1.19778 missing\n 2017-01-04 0.236237 1.39115 missing\n 2017-01-05 0.369588 1.21792 missing\n 2017-01-06 1.65287 -0.930058 missing\n 2017-01-07 0.761301 0.23794 missing\n 2017-01-08 -0.571046 -0.480486 missing\n 2017-01-09 -2.01905 -0.46391 missing\n 2017-01-10 0.193942 -1.01471 missing\n 2017-01-11 0.239041 missing -0.473429\n 2017-01-12 0.286036 missing -0.90377\n 2017-01-13 0.683429 missing -0.128489\n 2017-01-14 -1.51442 missing -2.39843\n 2017-01-15 -0.581341 missing -0.12265\n 2017-01-16 1.07059 missing -0.916064\n 2017-01-17 0.859396 missing 0.0162969\n 2017-01-18 -1.93127 missing 2.11127\n 2017-01-19 0.529477 missing 0.636964\n 2017-01-20 0.817429 missing -0.34038\n 2017-01-21 -0.682296 missing -0.971262\n 2017-01-22 1.36232 missing -0.236323\n 2017-01-23 0.143188 missing -0.501722\n 2017-01-24 0.621845 missing -1.20016\n 2017-01-25 0.076199 missing -1.36616\n 2017-01-26 0.379672 missing -0.555395\n 2017-01-27 0.494473 missing 1.05389\n 2017-01-28 0.278259 missing -0.358983\n 2017-01-29 0.0231765 missing 0.712526\n 2017-01-30 0.516704 missing 0.216855\n\njulia> vcat(ts1, ts2; colmerge=:intersect)\n(30 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n────────────────────────\n 2017-01-01 -0.524798\n 2017-01-02 -0.719611\n 2017-01-03 0.0926092\n 2017-01-04 0.236237\n 2017-01-05 0.369588\n 2017-01-06 1.65287\n 2017-01-07 0.761301\n 2017-01-08 -0.571046\n 2017-01-09 -2.01905\n 2017-01-10 0.193942\n 2017-01-11 0.239041\n 2017-01-12 0.286036\n 2017-01-13 0.683429\n 2017-01-14 -1.51442\n 2017-01-15 -0.581341\n 2017-01-16 1.07059\n 2017-01-17 0.859396\n 2017-01-18 -1.93127\n 2017-01-19 0.529477\n 2017-01-20 0.817429\n 2017-01-21 -0.682296\n 2017-01-22 1.36232\n 2017-01-23 0.143188\n 2017-01-24 0.621845\n 2017-01-25 0.076199\n 2017-01-26 0.379672\n 2017-01-27 0.494473\n 2017-01-28 0.278259\n 2017-01-29 0.0231765\n 2017-01-30 0.516704\n\n\n\n\n\n\n","category":"method"},{"location":"api/#RecipesBase.apply_recipe","page":"API reference","title":"RecipesBase.apply_recipe","text":"Plotting\n\nplot(ts::TSFrame, cols::Vector{Int} = collect(1:TSFrames.ncol(ts)))\nplot(ts::TSFrame, cols::Vector{T}) where {T<:Union{String, Symbol}}\nplot(ts::TSFrame, cols::T) where {T<:Union{Int, String, Symbol}}\n\nPlots a TSFrame object with the index on the x-axis and selected cols on the y-axis. By default, plot all the columns. Columns can be selected using Int indexes, String(s), or Symbol(s).\n\nExample\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = Date(\"2022-01-01\"):Month(1):Date(\"2022-01-01\")+Month(11);\n\njulia> df = DataFrame(Index = dates,\n val1 = random(12),\n val2 = random(12),\n val3 = random(12));\n\njulia> ts = TSFrame(df)\njulia> show(ts)\n(12 x 3) TSFrame with Dates.Date Index\n\n Index val1 val2 val3\n Date Float64 Float64 Float64\n────────────────────────────────────────────────\n 2022-01-01 -0.319954 0.974594 -0.552977\n 2022-02-01 -0.0386735 -0.171675 0.779539\n 2022-03-01 1.67678 -1.75251 0.820462\n 2022-04-01 1.69702 -0.0130037 1.0507\n 2022-05-01 0.992128 0.76957 -1.28008\n 2022-06-01 -0.315461 -0.543976 -0.117256\n 2022-07-01 -1.18952 -1.12867 -0.0829082\n 2022-08-01 0.159595 0.450044 -0.231828\n 2022-09-01 0.501436 0.265327 -0.948532\n 2022-10-01 -2.10516 -1.11489 0.285194\n 2022-11-01 -0.781082 -1.20202 -0.639953\n 2022-12-01 -0.169184 1.34879 1.33361\n\n\njulia> using Plots\n\njulia> # plot(ts)\n\n# plot first 6 rows with selected columns\njulia> # plot(ts[1:6], [:val1, :val3]);\n\n# plot columns 1 and 2 on a specified window size\njulia> # plot(ts, [1, 2], size=(600, 400));\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames._check_consistency-Tuple{TSFrame}","page":"API reference","title":"TSFrames._check_consistency","text":"Internal function to check consistency of the Index of a TSFrame object.\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.apply-Union{Tuple{V}, Tuple{T}, Tuple{TSFrame, T, V}, Tuple{TSFrame, T, V, Function}} where {T<:Dates.Period, V<:Function}","page":"API reference","title":"TSFrames.apply","text":"Apply/Period conversion\n\napply(ts::TSFrame,\n period::T,\n fun::V,\n index_at::Function=first;\n renamecols::Bool=true)\n where {T<:Dates.Period, V <: Function}\n\nApply fun to ts object based on period and return correctly indexed rows. This method is used for doing aggregation over a time period or to convert ts into an object of lower frequency (ex. from daily series to monthly).\n\nperiod is any of Period types in the Dates module. Conversion from lower to a higher frequency will throw an error as interpolation isn't currently handled by this method.\n\nBy default, the method uses the first value of the index within the period to index the resulting aggregated object. This behaviour can be controlled by index_at argument which can take first or last as an input.\n\nKeyword arguments\n\nrenamecols::Bool=true: whether to rename column names in the resulting object. If false, the column name is automatically generated based on the name of fun otherwise existing column names are used.\n\nExamples\n\njulia> using Random, Statistics;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2018,3,10));\n\njulia> ts = TSFrame(random(length(dates)), dates)\njulia> show(ts[1:10])\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> apply(ts, Month(1), first)\n(15 x 1) TSFrame with Date Index\n\n Index x1_first\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-02-01 0.790201\n 2017-03-01 0.467219\n 2017-04-01 0.783473\n 2017-05-01 0.651354\n 2017-06-01 0.373346\n 2017-07-01 0.83296\n 2017-08-01 0.132716\n 2017-09-01 0.27899\n 2017-10-01 0.995414\n 2017-11-01 0.214132\n 2017-12-01 0.832917\n 2018-01-01 0.0409471\n 2018-02-01 0.720163\n 2018-03-01 0.87459\n\n# alternate months\njulia> apply(ts, Month(2), first)\n(8 x 1) TSFrame with Date Index\n\n Index x1_first\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-03-01 0.467219\n 2017-05-01 0.651354\n 2017-07-01 0.83296\n 2017-09-01 0.27899\n 2017-11-01 0.214132\n 2018-01-01 0.0409471\n 2018-03-01 0.87459\n\n\njulia> ts_weekly = apply(ts, Week(1), Statistics.std) # weekly standard deviation\njulia> show(ts_weekly[1:10])\n(10 x 1) TSFrame with Date Index\n\n Index x1_std\n Date Float64\n────────────────────────\n 2017-01-01 NaN\n 2017-01-02 0.28935\n 2017-01-09 0.270842\n 2017-01-16 0.170197\n 2017-01-23 0.269573\n 2017-01-30 0.326687\n 2017-02-06 0.279935\n 2017-02-13 0.319216\n 2017-02-20 0.272058\n 2017-02-27 0.23651\n\n\njulia> ts_weekly = apply(ts, Week(1), Statistics.std, last) # indexed by last date of the week\njulia> show(ts_weekly[1:10])\n(10 x 1) TSFrame with Date Index\n\n Index x1_std\n Date Float64\n────────────────────────\n 2017-01-01 NaN\n 2017-01-08 0.28935\n 2017-01-15 0.270842\n 2017-01-22 0.170197\n 2017-01-29 0.269573\n 2017-02-05 0.326687\n 2017-02-12 0.279935\n 2017-02-19 0.319216\n 2017-02-26 0.272058\n 2017-03-05 0.23651\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.describe-Tuple{IO, TSFrame}","page":"API reference","title":"TSFrames.describe","text":"Summary statistics\n\ndescribe(ts::TSFrame; cols=:)\ndescribe(ts::TSFrame, stats::Union{Symbol, Pair}...; cols=:)\n\nCompute summary statistics of ts. The output is a DataFrame containing standard statistics along with number of missing values and data types of columns. The cols keyword controls which subset of columns from ts to be selected. The stats keyword is used to control which summary statistics are to be printed. For more information about these keywords, check out the corresponding documentation from DataFrames.jl.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x...);\njulia> ts = TSFrame(random(([1, 2, 3, 4, missing], 10)))\njulia> describe(ts)\n2×7 DataFrame\n Row │ variable mean min median max nmissing eltype\n │ Symbol Float64 Int64 Float64 Int64 Int64 Type\n─────┼───────────────────────────────────────────────────────────────────────────\n 1 │ Index 5.5 1 5.5 10 0 Int64\n 2 │ x1 2.75 2 3.0 4 2 Union{Missing, Int64}\njulia> describe(ts, cols=:Index)\n1×7 DataFrame\n Row │ variable mean min median max nmissing eltype\n │ Symbol Float64 Int64 Float64 Int64 Int64 DataType\n─────┼──────────────────────────────────────────────────────────────\n 1 │ Index 5.5 1 5.5 10 0 Int64\njulia> describe(ts, :min, :max, cols=:x1)\n1×3 DataFrame\n Row │ variable min max\n │ Symbol Int64 Int64\n─────┼────────────────────────\n 1 │ x1 2 4\njulia> describe(ts, :min, sum => :sum)\n2×3 DataFrame\n Row │ variable min sum\n │ Symbol Int64 Int64\n─────┼────────────────────────\n 1 │ Index 1 55\n 2 │ x1 2 22\njulia> describe(ts, :min, sum => :sum, cols=:x1)\n1×3 DataFrame\n Row │ variable min sum\n │ Symbol Int64 Int64\n─────┼────────────────────────\n 1 │ x1 2 22\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.endpoints","page":"API reference","title":"TSFrames.endpoints","text":"Computing end points\n\nendpoints(timestamps::AbstractVector{T}, on::V) where {T<:Union{Date, DateTime, Time},\n V<:Union{\n Year,\n Quarter,\n Month,\n Week,\n Day,\n Hour,\n Minute,\n Second,\n Millisecond,\n Microsecond,\n Nanosecond\n }}\nendpoints(ts::TSFrame, on::T) where {T<:Dates.Period}\nendpoints(ts::TSFrame, on::Symbol, k::Int=1)\nendpoints(ts::TSFrame, on::String, k::Int=1)\nendpoints(ts::TSFrame, on::Function, k::Int=1)\nendpoints(values::AbstractVector, on::Function, k::Int=1)\n\nReturn an integer vector of values for last observation in timestamps for each period given by on. The values are picked up every on.value instance of the period.\n\nCan be used to subset a TSFrame object directly using this function's return value. The methods work for regular time series of any periodicity and irregular time series belonging to any of the time-based types provided by the Dates module.\n\nThe primary method works for series of all time types including Date, DateTime, and Time, and for on belonging to any of the sub-types of Dates.Period. The ::TSFrame methods are provided for convenience and call the primary method directly using the Index column.\n\nFor the methods accepting on of Function type the values vector will get converted into unique period-groups which act as unique keys. The method uses these keys to create groups of values and uses the period provided by on to pick up the last observation in each group. k decides the number of groups to skip. For example, k=2 picks every alternate group starting from the 2ⁿᵈ element out of the ones created by on. See the examples below to see how the function works in the real world. The on function should return a Vector to be used as grouping keys.\n\nendpoints(ts::TSFrame, on::Symbol) and endpoints(ts::TSFrame, on::String) are convenience methods where valid values for on are: :years, :quarters, :months, :weeks, :days, :hours, :minutes, :seconds, :milliseconds, :microseconds, and :nanoseconds.\n\nNote, that except for on::Function all other methods expect Index type of TSFrame to be a subtype of TimeType.\n\nThe method returns Vector{Int} corresponding to the matched values in the first argument.\n\nExamples\n\njulia> using Random\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = Date(2017):Day(1):Date(2019);\njulia> ts = TSFrame(random(length(dates)), dates)\n(731 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n ⋮ ⋮\n 2018-12-24 0.812797\n 2018-12-25 0.158056\n 2018-12-26 0.269285\n 2018-12-27 0.15065\n 2018-12-28 0.916177\n 2018-12-29 0.278016\n 2018-12-30 0.617211\n 2018-12-31 0.67549\n 2019-01-01 0.910285\n 712 rows omitted\n\njulia> ep = endpoints(ts, Month(1))\n25-element Vector{Int64}:\n 31\n 59\n 90\n 120\n 151\n 181\n 212\n 243\n 273\n 304\n 334\n 365\n 396\n 424\n 455\n 485\n 516\n 546\n 577\n 608\n 638\n 669\n 699\n 730\n 731\n\njulia> ts[ep]\n(25 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-31 0.48\n 2017-02-28 0.458476\n 2017-03-31 0.274441\n 2017-04-30 0.413966\n 2017-05-31 0.734931\n 2017-06-30 0.257159\n 2017-07-31 0.415851\n 2017-08-31 0.0377973\n 2017-09-30 0.934059\n 2017-10-31 0.413175\n 2017-11-30 0.557009\n 2017-12-31 0.346659\n 2018-01-31 0.174777\n 2018-02-28 0.432223\n 2018-03-31 0.835142\n 2018-04-30 0.945539\n 2018-05-31 0.0635483\n 2018-06-30 0.589922\n 2018-07-31 0.285088\n 2018-08-31 0.912558\n 2018-09-30 0.238931\n 2018-10-31 0.49775\n 2018-11-30 0.830232\n 2018-12-31 0.67549\n 2019-01-01 0.910285\n\njulia> diff(index(ts[ep]))\n24-element Vector{Day}:\n 28 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 31 days\n 28 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 1 day\n\n# every 2ⁿᵈ month\njulia> ts[endpoints(ts, Month(2))]\n(12 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-02-28 0.458476\n 2017-04-30 0.413966\n 2017-06-30 0.257159\n 2017-08-31 0.0377973\n 2017-10-31 0.413175\n 2017-12-31 0.346659\n 2018-02-28 0.432223\n 2018-04-30 0.945539\n 2018-06-30 0.589922\n 2018-08-31 0.912558\n 2018-10-31 0.49775\n 2018-12-31 0.67549\n 2019-01-01 0.910285\n\n# Weekly points using a function\njulia> endpoints(ts, i -> lastdayofweek.(i), 1)\n106-element Vector{Int64}:\n 1\n 8\n 15\n 22\n 29\n 36\n 43\n ⋮\n 694\n 701\n 708\n 715\n 722\n 729\n 731\n\njulia> endpoints(ts, i -> lastdayofweek.(i), 1) == endpoints(ts, Week(1))\ntrue\n\n# Time type series\njulia> timestampsminutes = collect(Time(9, 1, 2):Minute(1):Time(11, 2, 3));\njulia> timestampsminutes[endpoints(timestampsminutes, Minute(2))]\n61-element Vector{Time}:\n 09:02:02\n 09:04:02\n 09:06:02\n 09:08:02\n 09:10:02\n 09:12:02\n 09:14:02\n 09:16:02\n 09:18:02\n 09:20:02\n 09:22:02\n 09:24:02\n ⋮\n 10:40:02\n 10:42:02\n 10:44:02\n 10:46:02\n 10:48:02\n 10:50:02\n 10:52:02\n 10:54:02\n 10:56:02\n 10:58:02\n 11:00:02\n 11:02:02\n\njulia> timestampsminutes[endpoints(timestampsminutes, Hour(1))]\n3-element Vector{Time}:\n 09:59:02\n 10:59:02\n 11:02:02\n\n## Irregular series\njulia> datetimeseconds = collect(range(DateTime(2022, 10, 08) + Hour(9),\n DateTime(2022, 10, 08) + Hour(15) + Minute(29),\n step=Second(1)));\njulia> datetimesecondsrandom = sample(MersenneTwister(123), datetimeseconds, 20, replace=false, ordered=true)\n17-element Vector{DateTime}:\n 2022-10-08T09:20:16\n 2022-10-08T09:32:00\n 2022-10-08T09:43:57\n 2022-10-08T10:13:27\n 2022-10-08T10:44:34\n 2022-10-08T11:04:23\n 2022-10-08T11:08:37\n 2022-10-08T11:46:51\n 2022-10-08T11:56:46\n 2022-10-08T12:14:22\n 2022-10-08T12:32:08\n 2022-10-08T13:28:42\n 2022-10-08T13:34:33\n 2022-10-08T13:54:11\n 2022-10-08T13:59:08\n 2022-10-08T14:05:57\n 2022-10-08T14:37:17\n\njulia> datetimesecondsrandom[endpoints(datetimesecondsrandom, Hour(1))]\n6-element Vector{DateTime}:\n 2022-10-08T09:43:57\n 2022-10-08T10:44:34\n 2022-10-08T11:56:46\n 2022-10-08T12:32:08\n 2022-10-08T13:59:08\n 2022-10-08T14:37:17\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.head","page":"API reference","title":"TSFrames.head","text":"Head\n\nhead(ts::TSFrame, n::Int = 10)\n\nReturns the first n rows of ts.\n\nExamples\n\njulia> head(TSFrame(1:100))\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Int64\n──────────────\n 1 1\n 2 2\n 3 3\n 4 4\n 5 5\n 6 6\n 7 7\n 8 8\n 9 9\n 10 10\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.index-Tuple{TSFrame}","page":"API reference","title":"TSFrames.index","text":"Index column\n\nindex(ts::TSFrame)\n\nReturn the index vector from the coredata DataFrame.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> ts = TSFrame(random(10), Date(\"2022-02-01\"):Month(1):Date(\"2022-02-01\")+Month(9));\n\n\njulia> show(ts)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-02-01 0.768448\n 2022-03-01 0.940515\n 2022-04-01 0.673959\n 2022-05-01 0.395453\n 2022-06-01 0.313244\n 2022-07-01 0.662555\n 2022-08-01 0.586022\n 2022-09-01 0.0521332\n 2022-10-01 0.26864\n 2022-11-01 0.108871\n\njulia> index(ts)\n10-element Vector{Date}:\n 2022-02-01\n 2022-03-01\n 2022-04-01\n 2022-05-01\n 2022-06-01\n 2022-07-01\n 2022-08-01\n 2022-09-01\n 2022-10-01\n 2022-11-01\n\njulia> eltype(index(ts))\nDate\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.isregular-Union{Tuple{AbstractVector{V}}, Tuple{V}, Tuple{AbstractVector{V}, Symbol}} where V<:Dates.TimeType","page":"API reference","title":"TSFrames.isregular","text":"isregular(timestamps::V, unit::T) where {V<:AbstractVector{TimeType}, T<:Dates.Period}\nisregular(timestamps::T) where {T<:AbstractVector{TimeType}}\nisregular(timestamps::AbstractVector{V}, unit::Symbol = :firstdiff) where {V<:TimeType}\nisregular(ts::TSFrame, unit::Symbol = :firstdiff)\nisregular(ts::TSFrame, unit::T) where {T<:Dates.Period}\n\nCheck if ts is regular.\n\nif unit == :firstdiff then it checks if first difference of index is constant\notherwise it will check if first difference is constant with respect to specified timeperiod.\n\nFor eg. if unit == :month then check if first difference is constant with respect to months.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates=collect(Date(2017,1,1):Day(1):Date(2017,1,10))\n10-element Vector{Date}:\n 2017-01-01\n 2017-01-02\n 2017-01-03\n 2017-01-04\n 2017-01-05\n 2017-01-06\n 2017-01-07\n 2017-01-08\n 2017-01-09\n 2017-01-10\n\njulia> isregular(dates) # check if regular\ntrue\n\njulia> isregular(dates, Day(1)) # check if regular with a time difference of 1 day\ntrue\n\njulia> isregular(dates, Day(2)) # check if regular with a time difference of 2 days\nfalse\n\njulia> isregular(dates, :month) # check if regular with respect to months\nfalse\n\njulia> ts = TSFrame(random(10), dates)\n10×1 TSFrame with Date Index\n Index x1 \n Date Float64 \n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> isregular(ts)\ntrue\n\njulia> isregular(ts, Day(1))\ntrue\n\njulia> isregular(ts, Day(2))\nfalse\n\njulia> isregular(ts, :month)\nfalse\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.lag","page":"API reference","title":"TSFrames.lag","text":"Lagging\n\nlag(ts::TSFrame, lag_value::Int = 1)\n\nLag the ts object by the specified lag_value. The rows corresponding to lagged values will be rendered as missing. Negative values of lag are also accepted (see TSFrames.lead).\n\nExamples\n\njulia> using Random, Statistics;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> ts = TSFrame(random(length(dates)), dates);\njulia> show(ts)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\n\njulia> lag(ts)\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n─────────────────────────────\n 2017-01-01 missing\n 2017-01-02 0.768448\n 2017-01-03 0.940515\n 2017-01-04 0.673959\n 2017-01-05 0.395453\n 2017-01-06 0.313244\n 2017-01-07 0.662555\n 2017-01-08 0.586022\n 2017-01-09 0.0521332\n 2017-01-10 0.26864\n\njulia> lag(ts, 2) # lags by 2 values\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n─────────────────────────────\n 2017-01-01 missing\n 2017-01-02 missing\n 2017-01-03 0.768448\n 2017-01-04 0.940515\n 2017-01-05 0.673959\n 2017-01-06 0.395453\n 2017-01-07 0.313244\n 2017-01-08 0.662555\n 2017-01-09 0.586022\n 2017-01-10 0.0521332\n\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.lead","page":"API reference","title":"TSFrames.lead","text":"Leading\n\nlead(ts::TSFrame, lead_value::Int = 1)\n\nSimilar to lag, this method leads the ts object by lead_value. The lead rows are inserted with missing. Negative values of lead are also accepted (see TSFrames.lag).\n\nExamples\n\njulia> using Random, Statistics;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2018,3,10));\n\njulia> ts = TSFrame(DataFrame(Index = dates, x1 = random(length(dates))))\njulia> show(ts)\n(434 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n ⋮ ⋮\n 2018-03-03 0.127635\n 2018-03-04 0.147813\n 2018-03-05 0.873555\n 2018-03-06 0.486486\n 2018-03-07 0.495525\n 2018-03-08 0.64075\n 2018-03-09 0.375126\n 2018-03-10 0.0338698\n 418 rows omitted\n\n\njulia> lead(ts)[1:10] # leads once\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n───────────────────────\n 2017-01-01 0.940515\n 2017-01-02 0.673959\n 2017-01-03 0.395453\n 2017-01-04 0.313244\n 2017-01-05 0.662555\n 2017-01-06 0.586022\n 2017-01-07 0.0521332\n 2017-01-08 0.26864\n 2017-01-09 0.108871\n 2017-01-10 0.163666\n\njulia> lead(ts, 2)[1:10] # leads by 2 values\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n───────────────────────\n 2017-01-01 0.673959\n 2017-01-02 0.395453\n 2017-01-03 0.313244\n 2017-01-04 0.662555\n 2017-01-05 0.586022\n 2017-01-06 0.0521332\n 2017-01-07 0.26864\n 2017-01-08 0.108871\n 2017-01-09 0.163666\n 2017-01-10 0.473017\n\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.ncol-Tuple{TSFrame}","page":"API reference","title":"TSFrames.ncol","text":"Size methods\n\nncol(ts::TSFrame)\n\nReturn the number of columns of ts. nc is an alias for ncol.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> TSFrames.ncol(TSFrame([random(100) random(100) random(100)]))\n3\n\njulia> nc(TSFrame([random(100) random(100) random(100)]))\n3\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.nrow-Tuple{TSFrame}","page":"API reference","title":"TSFrames.nrow","text":"Size methods\n\nnrow(ts::TSFrame)\nnr(ts::TSFrame)\n\nReturn the number of rows of ts. nr is an alias for nrow.\n\nExamples\n\njulia> ts = TSFrame(collect(1:10))\njulia> TSFrames.nrow(ts)\n10\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.rename!-Tuple{TSFrame, AbstractVector{String}}","page":"API reference","title":"TSFrames.rename!","text":"Column Rename\n\nrename!(ts::TSFrame, colnames::AbstractVector{String}; makeunique::Bool=false)\nrename!(ts::TSFrame, colnames::AbstractVector{Symbol}; makeunique::Bool=false)\nrename!(ts::TSFrame, (from => to)::Pair...)\nrename!(ts::TSFrame, d::AbstractDict)\nrename!(ts::TSFrame, d::AbstractVector{<:Pair})\nrename!(f::Function, ts::TSFrame)\n\nRenames columns of ts in-place. The interface is similar to DataFrames.jl's renaming interface.\n\nArguments\n\nts: the TSFrame.\ncolnames: an AbstractVector containing Strings or Symbols. Must be of the same length as the number of non-Index columns in ts, and cannot contain the string \"Index\" or the symbol :Index.\nmakeunique: if false (which is the default), an error will be raised if colnames contains duplicate names. If true, then duplicate names will be suffixed with _i (i starting at 1 for the first duplicate).\nd: an AbstractDict or an AbstractVector of Pairs that maps original names to new names. Cannot map :Index to any other column name.\nf: a function which for each non-Index column takes the old name as a String and returns the new name as a String.\n\nIf pairs are passed to rename! (as positional arguments or as a dictionary or as a vector), then\n\nfrom can be a String or a Symbol.\nto can be a String or a Symbol.\nMixing Strings and Symbols in from and to is not allowed.\n\njulia> ts = TSFrame(DataFrame(Index=Date(2012, 1, 1):Day(1):Date(2012, 1, 10), x1=1:10, x2=11:20))\n10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, [\"X1\", \"X2\"])\n 10×2 TSFrame with Date Index\n Index X1 X2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, [:x1, :x2])\n10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, :x1 => :X1, :x2 => :X2)\n10×2 TSFrame with Date Index\n Index X1 X2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, Dict(\"X1\" => :x1, \"X2\" => :x2))\n 10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, [:x1 => \"X1\", :x2 => \"X2\"])\n10×2 TSFrame with Date Index\n Index X1 X2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename(lowercase, ts)\n10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.rollapply-Tuple{TSFrame, Function, Int64}","page":"API reference","title":"TSFrames.rollapply","text":"Rolling Functions\n\nrollapply(ts::TSFrame, fun::Function, windowsize::Int; bycolumn=true)\n\nApply function fun to rolling windows of ts. The output is a TSFrame object with (nrow(ts) - windowsize + 1) rows indexed with the last index value of each window.\n\nThe bycolumn argument should be set to true (default) if fun is to be applied to each column separately, and to false if fun takes a whole TSFrame as an input.\n\nExamples\n\njulia> rollapply(TSFrame([1:10 11:20]), mean, 5)\n6×2 TSFrame with Int64 Index\n Index rolling_x1_mean rolling_x2_mean \n Int64 Float64 Float64 \n─────────────────────────────────────────\n 5 3.0 13.0\n 6 4.0 14.0\n 7 5.0 15.0\n 8 6.0 16.0\n 9 7.0 17.0\n 10 8.0 18.0\n\njulia> dates = Date(2001, 1, 1):Day(1):Date(2001, 1, 10);\njulia> df = DataFrame(Index=dates, inrchf=1:10, usdchf=1:10, eurchf=1:10, gbpchf=1:10, jpychf=1:10);\njulia> ts = TSFrame(df)\n10×5 TSFrame with Date Index\n Index inrchf usdchf eurchf gbpchf jpychf \n Date Int64 Int64 Int64 Int64 Int64 \n────────────────────────────────────────────────────\n 2001-01-01 1 1 1 1 1\n 2001-01-02 2 2 2 2 2\n 2001-01-03 3 3 3 3 3\n 2001-01-04 4 4 4 4 4\n 2001-01-05 5 5 5 5 5\n 2001-01-06 6 6 6 6 6\n 2001-01-07 7 7 7 7 7\n 2001-01-08 8 8 8 8 8\n 2001-01-09 9 9 9 9 9\n 2001-01-10 10 10 10 10 10\n\njulia> function regress(ts) # defining function for multiple regressions\n ll = lm(@formula(inrchf ~ usdchf + eurchf + gbpchf + jpychf), ts.coredata[:, Not(:Index)])\n co = coef(ll)[coefnames(ll) .== \"usdchf\"]\n sd = Statistics.std(residuals(ll))\n return (co, sd)\n end\n\njulia> rollapply(ts, regress, 5; bycolumn=false) # doing multiple regressions\n6×1 TSFrame with Date Index\n Index rolling_regress \n Date Tuple… \n──────────────────────────────────\n 2001-01-05 ([1.0], 9.93014e-17)\n 2001-01-06 ([1.0], 1.27168e-15)\n 2001-01-07 ([1.0], 4.86475e-16)\n 2001-01-08 ([1.0], 7.43103e-16)\n 2001-01-09 ([1.0], 7.45753e-15)\n 2001-01-10 ([1.0], 9.28561e-15)\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.subset-Union{Tuple{T}, Tuple{TSFrame, T, T}} where T<:Union{Int64, Dates.TimeType}","page":"API reference","title":"TSFrames.subset","text":"Subsetting based on Index\n\nsubset(ts::TSFrame, from::T, to::T) where {T<:Union{Int, TimeType}}\n\nCreate a subset of ts based on the Index starting from (inclusive) till to (inclusive).\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = Date(\"2022-02-01\"):Week(1):Date(\"2022-02-01\")+Month(9);\njulia> ts = TSFrame(random(length(dates)), dates)\njulia> show(ts)\n(40 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-02-01 0.768448\n 2022-02-08 0.940515\n 2022-02-15 0.673959\n 2022-02-22 0.395453\n 2022-03-01 0.313244\n 2022-03-08 0.662555\n 2022-03-15 0.586022\n 2022-03-22 0.0521332\n 2022-03-29 0.26864\n 2022-04-05 0.108871\n 2022-04-12 0.163666\n 2022-04-19 0.473017\n 2022-04-26 0.865412\n 2022-05-03 0.617492\n 2022-05-10 0.285698\n 2022-05-17 0.463847\n 2022-05-24 0.275819\n 2022-05-31 0.446568\n 2022-06-07 0.582318\n 2022-06-14 0.255981\n 2022-06-21 0.70586\n 2022-06-28 0.291978\n 2022-07-05 0.281066\n 2022-07-12 0.792931\n 2022-07-19 0.20923\n 2022-07-26 0.918165\n 2022-08-02 0.614255\n 2022-08-09 0.802665\n 2022-08-16 0.555668\n 2022-08-23 0.940782\n 2022-08-30 0.48\n 2022-09-06 0.790201\n 2022-09-13 0.356221\n 2022-09-20 0.900925\n 2022-09-27 0.529253\n 2022-10-04 0.031831\n 2022-10-11 0.900681\n 2022-10-18 0.940299\n 2022-10-25 0.621379\n 2022-11-01 0.348173\n\njulia> subset(ts, Date(2022, 03), Date(2022, 07))\n(18 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-03-01 0.313244\n 2022-03-08 0.662555\n 2022-03-15 0.586022\n 2022-03-22 0.0521332\n 2022-03-29 0.26864\n 2022-04-05 0.108871\n 2022-04-12 0.163666\n 2022-04-19 0.473017\n 2022-04-26 0.865412\n 2022-05-03 0.617492\n 2022-05-10 0.285698\n 2022-05-17 0.463847\n 2022-05-24 0.275819\n 2022-05-31 0.446568\n 2022-06-07 0.582318\n 2022-06-14 0.255981\n 2022-06-21 0.70586\n 2022-06-28 0.291978\n\njulia> subset(TSFrame(1:20, -9:10), -4, 5)\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Int64\n──────────────\n -4 6\n -3 7\n -2 8\n -1 9\n 0 10\n 1 11\n 2 12\n 3 13\n 4 14\n 5 15\n\njulia> subset(ts,:,Date(\"2022-04-12\"))\n(11 x 1) TSFrame with Date Index\n\n Index x1 \n Date Float64 \n───────────────────────\n 2022-02-01 0.768448\n 2022-02-08 0.940515\n 2022-02-15 0.673959\n 2022-02-22 0.395453\n 2022-03-01 0.313244\n 2022-03-08 0.662555\n 2022-03-15 0.586022\n 2022-03-22 0.0521332\n 2022-03-29 0.26864\n 2022-04-05 0.108871\n 2022-04-12 0.163666\n\njulia> subset(ts,Date(\"2022-9-27\"),:)\n(6 x 1) TSFrame with Date Index\n\n Index x1 \n Date Float64 \n──────────────────────\n 2022-09-27 0.529253\n 2022-10-04 0.031831\n 2022-10-11 0.900681\n 2022-10-18 0.940299\n 2022-10-25 0.621379\n 2022-11-01 0.348173\n\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.tail","page":"API reference","title":"TSFrames.tail","text":"Tail\n\ntail(ts::TSFrame, n::Int = 10)\n\nReturns the last n rows of ts.\n\njulia> tail(TSFrame(1:100))\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Int64\n──────────────\n 91 91\n 92 92\n 93 93\n 94 94\n 95 95\n 96 96\n 97 97\n 98 98\n 99 99\n 100 100\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.to_period-Union{Tuple{T}, Tuple{TSFrame, T}} where T<:Dates.Period","page":"API reference","title":"TSFrames.to_period","text":"Frequency conversion\n\nSet of convenience methods for frequency conversion of TimeType index types. Internally, they call endpoints() to do the actual conversion. n is the number of periods of the period type. For example, to_monthly(tsf, 2) will resample the time series to \"every 2 months\".\n\nto_period(tsf::TSFrame, period::T)::TSFrame where {T<:Period}\nto_yearly(tsf::TSFrame, n=1)::TSFrame\nto_quarterly(tsf::TSFrame, n=1)::TSFrame\nto_monthly(tsf::TSFrame, n=1)::TSFrame\nto_weekly(tsf::TSFrame, n=1)::TSFrame\nto_daily(tsf::TSFrame, n=1)::TSFrame\nto_hourly(tsf::TSFrame, n=1)::TSFrame\nto_minutes(tsf::TSFrame, n=1)::TSFrame\nto_seconds(tsf::TSFrame, n=1)::TSFrame\nto_milliseconds(tsf::TSFrame, n=1)::TSFrame\nto_microseconds(tsf::TSFrame, n=1)::TSFrame\nto_nanoseconds(tsf::TSFrame, n=1)::TSFrame\n\n\n\n\n\n","category":"method"},{"location":"user_guide/#User-guide","page":"User guide","title":"User guide","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"This page describes how to use the TSFrames package for timeseries data handling.","category":"page"},{"location":"user_guide/#Installation","page":"User guide","title":"Installation","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using Pkg\njulia> Pkg.add(url=\"https://github.com/xKDR/TSFrames.jl\")","category":"page"},{"location":"user_guide/#Constructing-TSFrame-objects","page":"User guide","title":"Constructing TSFrame objects","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"After installing TSFrames you need to load the package in Julia environment. Then, create a basic TSFrame object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using TSFrames;\nts = TSFrame(1:10)\nts.coredata","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The basic TSFrame constructor takes in a Vector of any type and automatically generates an index out of it (the Index column).","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"There are many ways to construct a TSFrame object. For real world applications you would want to read in a CSV file or download a dataset as a DataFrame and then operate on it. You can easily convert a DataFrame to a TSFrame object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using CSV, DataFrames, TSFrames, Dates\ndates = Date(2007, 1, 1):Day(1):Date(2008, 03, 06)\nts = TSFrame(DataFrame(Index=dates, value=10*rand(431)))","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"In the above example you generate a random DataFrame and convert it into a TSFrame object ts. The top line of the ts object tells you the number of rows (431 here) and the number of columns (1) along with the Type of Index (Dates.Date in the above example).","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"You can also fetch the number of rows and columns by using nr(ts), nc(ts), and size(ts) methods. Respectively, they fetch the number of rows, columns, and a Tuple of row and column numbers. A length(::TSFrame) method is also provided for convenience which returns the number of rows of it's argument.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"nr(ts)\nnc(ts)\nsize(ts)\nlength(ts)","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Names of data columns can be fetched using the names(ts) method which returns a Vector{String} object. The Index column can be fetched as an object of Vector type by using the index(ts) method, it can also be fetched directly using the underlying coredata property of TSFrame: ts.coredata[!, :Index].","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"names(ts)\nindex(ts)","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Another simpler way to read a CSV is to pass TSFrame as a sink to the CSV.read function.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> ts = CSV.File(filename, TSFrame)","category":"page"},{"location":"user_guide/#Indexing-and-subsetting","page":"User guide","title":"Indexing and subsetting","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"One of the primary features of a timeseries package is to provide ways to index or subset a dataset using convenient interfaces. TSFrames makes it easier to index a TSFrame object by providing multiple intuitive getindex methods which work by just using the regular square parentheses([ ]).","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts[1] # first row\nts[[3, 5], [1]] # third & fifth row, and first column\nts[1:10, 1] # first 10 rows and the first column as a vector\nts[1, [:value]] # using the column name","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Apart from integer-based row indexing and integer, name based column indexing, TSFrames provides special subsetting methods for date and time types defined inside the Dates module.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts[Date(2007, 1, 10)] # on January 10, 2007\nts[[Date(2007, 1, 10), Date(2007, 1, 11)]] # January 10, 11\nts[Year(2007), Month(1)] # entire January 2007\nts[Year(2007), Quarter(2)]","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Finally, one can also use the dot notation to get a column as a vector.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts.value # get the value column as a vector","category":"page"},{"location":"user_guide/#Summary-statistics","page":"User guide","title":"Summary statistics","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The describe() method prints summary statistics of the TSFrame object. The output is a DataFrame which includes the number of missing values, data types of columns along with computed statistical values.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"TSFrames.describe(ts)","category":"page"},{"location":"user_guide/#Plotting","page":"User guide","title":"Plotting","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"A TSFrame object can be plotted using the plot() function of the Plots package. The plotting functionality is provided by RecipesBase package so all the flexibility and functionality of the Plots package is available for users.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using Plots\nplot(ts, size=(600,400); legend=false)","category":"page"},{"location":"user_guide/#Applying-a-function-over-a-period","page":"User guide","title":"Applying a function over a period","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The apply method allows you to aggregate the TSFrame object over a period type (Dates.Period(@ref)) and return the output of applying the function on each period. For example, to convert frequency of daily timeseries to monthly you may use first(), last(), or Statistics.mean() functions and the period as Dates.Month.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using Statistics\nts_monthly = apply(ts, Month(1), last) # convert to monthly series using the last value for each month\nts_weekly = apply(ts, Week(1), Statistics.std) # compute weekly standard deviation\napply(ts, Week(1), Statistics.std, last) # same as above but index contains the last date of the week\napply(ts, Week(1), Statistics.std, last, renamecols=false) # do not rename column","category":"page"},{"location":"user_guide/#Joins:-Row-and-column-binding-with-other-objects","page":"User guide","title":"Joins: Row and column binding with other objects","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"TSFrames provides methods to join two TSFrame objects by columns: join (alias: cbind) or by rows: vcat (alias: rbind). Both the methods provide some basic intelligence while doing the merge.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"join merges two datasets based on the Index values of both objects. Depending on the join strategy employed the final object may only contain index values only from the left object (using jointype=:JoinLeft), the right object (using jointype=:JoinRight), intersection of both objects (using jointype=:JoinBoth), or a union of both objects (jointype=:JoinAll) while inserting missing values where index values are missing from any of the other object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"dates = collect(Date(2007,1,1):Day(1):Date(2007,1,30));\nts2 = TSFrame(rand(length(dates)), dates)\njoin(ts, ts2; jointype=:JoinAll) # cbind/join on Index column","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"vcat also works similarly but merges two datasets by rows. This method also uses certain strategies provided via colmerge argument to check for certain conditions before doing the merge, throwing an error if the conditions are not satisfied.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"colmerge can be passed setequal which merges only if both objects have same column names, orderequal which merges only if both objects have same column names and columns are in the same order, intersect merges only the columns which are common to both objects, and union which merges even if the columns differ between the two objects, the resulting object has the columns filled with missing, if necessary.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"For vcat, if the values of Index are same in the two objects then all the index values along with values in other columns are kept in the resulting object. So, a vcat operation may result in duplicate Index values and the results from other operations may differ or even throw unknown errors.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"dates = collect(Date(2008,4,1):Day(1):Date(2008,4,30));\nts3 = TSFrame(DataFrame(values=rand(length(dates)), Index=dates))\nvcat(ts, ts3) # do the merge","category":"page"},{"location":"user_guide/#Rolling-window-operations","page":"User guide","title":"Rolling window operations","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The rollapply applies a function over a fixed-size rolling window on the dataset. In the example below, we compute the 10-day average of dataset values on a rolling basis.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"rollapply(ts, mean, 10)","category":"page"},{"location":"user_guide/#Computing-rolling-difference-and-percent-change","page":"User guide","title":"Computing rolling difference and percent change","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Similar to apply and rollapply there are specific methods to compute rolling differences and percent changes of a TSFrame object. The diff method computes mathematical difference of values in adjacent rows, inserting missing in the first row. pctchange computes the percentage change between adjacent rows.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"diff(ts)\npctchange(ts)","category":"page"},{"location":"user_guide/#Computing-log-of-data-values","page":"User guide","title":"Computing log of data values","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"log.(ts)","category":"page"},{"location":"user_guide/#Creating-lagged/leading-series","page":"User guide","title":"Creating lagged/leading series","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"lag() and lead() provide ways to lag or lead a series respectively by a fixed value, inserting missing where required.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"lag(ts, 2)\nlead(ts, 2)","category":"page"},{"location":"user_guide/#Converting-to-Matrix-and-DataFrame","page":"User guide","title":"Converting to Matrix and DataFrame","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"You can easily convert a TSFrame object into a Matrix or fetch the DataFrame for doing operations which are outside of the TSFrames scope.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts[:, 1] # convert column 1 to a vector of floats\nMatrix(ts) # convert entire TSFrame into a Matrix\nselect(ts.coredata, :Index, :value, DataFrames.nrow) # use the underlying DataFrame for other operations","category":"page"},{"location":"user_guide/#Writing-TSFrame-into-a-CSV-file","page":"User guide","title":"Writing TSFrame into a CSV file","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Writing a TSFrame object into a CSV file can be done easily by using the underlying coredata property. This DataFrame can be passed to the CSV.write method for writing into a file.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"CSV.write(\"/tmp/demo_ts.csv\", ts)","category":"page"},{"location":"user_guide/#Broadcasting","page":"User guide","title":"Broadcasting","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Broadcasting can be used on a TSFrame object to apply a function to a subset of it's columns.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using TSFrames, DataFrames;\n\njulia> ts = TSFrame(DataFrame(Index = [1, 2, 3, 4, 5], A = [10.1, 12.4, 42.4, 24.1, 242.5], B = [2, 4, 6, 8, 10]))\n(5 x 2) TSFrame with Int64 Index\n\n Index A B \n Int64 Float64 Int64 \n───────────────────────\n 1 10.1 2\n 2 12.4 4\n 3 42.4 6\n 4 24.1 8\n 5 242.5 10\n\njulia> sin_A = sin.(ts[:, [:A]]) # get sin of column A\n(5 x 1) TSFrame with Int64 Index\n\n Index A_sin\n Int64 Float64\n──────────────────\n 1 -0.625071\n 2 -0.165604\n 3 -0.999934\n 4 -0.858707\n 5 -0.562466\n\njulia> log_ts = log.(ts) # take log of all columns\n(5 x 2) TSFrame with Int64 Index\n\n Index A_log B_log\n Int64 Float64 Float64\n──────────────────────────\n 1 2.31254 0.693147\n 2 2.5177 1.38629\n 3 3.74715 1.79176\n 4 3.18221 2.07944\n 5 5.491 2.30259\n\njulia> log_ts = log.(ts[:, [:A, :B]]) # can specify multiple columns\n(5 x 2) TSFrame with Int64 Index\n\n Index A_log B_log\n Int64 Float64 Float64\n──────────────────────────\n 1 2.31254 0.693147\n 2 2.5177 1.38629\n 3 3.74715 1.79176\n 4 3.18221 2.07944\n 5 5.491 2.30259\n","category":"page"},{"location":"user_guide/#[Tables.jl](https://github.com/JuliaData/Tables.jl)-Integration","page":"User guide","title":"Tables.jl Integration","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"TSFrame objects are Tables.jl compatible. This integration enables easy conversion between the TSFrame format and other formats which are Tables.jl compatible.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"As an example, first consider the following code which converts a TSFrame object into a DataFrame, a TimeArray and a CSV file respectively.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using TSFrames, TimeSeries, Dates, DataFrames, CSV;\n\njulia> dates = Date(2018, 1, 1):Day(1):Date(2018, 12, 31)\nDate(\"2018-01-01\"):Day(1):Date(\"2018-12-31\")\n\njulia> ts = TSFrame(DataFrame(Index = dates, x1 = 1:365));\n\n# conversion to DataFrames\njulia> df = DataFrame(ts);\n\n# conversion to TimeArray\njulia> timeArray = TimeArray(ts, timestamp = :Index);\n\n# writing to CSV\njulia> CSV.write(\"ts.csv\", ts);\n","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Next, here is some code which converts a DataFrame, a TimeArray and a CSV file to a TSFrame object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using TSFrames, DataFrames, CSV, TimeSeries, Dates;\n\n# converting DataFrame to TSFrame\njulia> ts = TSFrame(DataFrame(Index=1:10, x1=1:10));\n\n# converting from TimeArray to TSFrame\njulia> dates = Date(2018, 1, 1):Day(1):Date(2018, 12, 31)\nDate(\"2018-01-01\"):Day(1):Date(\"2018-12-31\")\n\njulia> ta = TimeArray(dates, rand(length(dates)));\n\njulia> ts = TSFrame(ta);\n\n# converting from CSV to TSFrame\njulia> CSV.read(\"ts.csv\", TSFrame);","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"note: Note\nThis discussion warrants a note about how we've implemented the Tables.jl interfaces. Since TSFrame objects are nothing but a wrapper around a DataFrame, our implementations of these interfaces just call DataFrames.jl's implementations. Moreover, while constructing TSFrame objects out of other Tables.jl compatible types, our constructor first converts the input table to a DataFrame, and then converts the DataFrame to a TSFrame object.","category":"page"},{"location":"demo_finance/#Basic-demo-of-TSFrames-using-financial-data","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames using financial data","text":"","category":"section"},{"location":"demo_finance/#Create-a-TSFrame-object-for-IBM-historical-data","page":"Basic demo of TSFrames","title":"Create a TSFrame object for IBM historical data","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"To load the IBM historical data, we will use the MarketData.yahoo function from MarketData.jl, which returns the data in the form of a TimeArray. We just simply pass this on to the TSFrame constructor.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"using TSFrames, MarketData, Plots, Statistics, Impute\nibm_ts = TSFrame(MarketData.yahoo(:IBM))","category":"page"},{"location":"demo_finance/#Create-TSFrame-object-for-AAPL","page":"Basic demo of TSFrames","title":"Create TSFrame object for AAPL","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Similarly, we can create a TSFrame object for the AAPL data.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"aapl_ts = TSFrame(MarketData.yahoo(:AAPL))","category":"page"},{"location":"demo_finance/#Create-a-6-month-subset-of-stock-data","page":"Basic demo of TSFrames","title":"Create a 6-month subset of stock data","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"We would like to compare the stock returns for both the stocks for 6 months starting from June 1, 2021 till December 31, 2021. We use TSFrames.subset method to create new objects which contain the specified duration of data.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"date_from = Date(2021, 06, 01);\ndate_to = Date(2021, 12, 31);\n\nibm = TSFrames.subset(ibm_ts, date_from, date_to)","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"aapl = TSFrames.subset(aapl_ts, date_from, date_to)","category":"page"},{"location":"demo_finance/#Combine-adjusted-closing-prices-of-both-stocks-into-one-object","page":"Basic demo of TSFrames","title":"Combine adjusted closing prices of both stocks into one object","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"We now join (cbind) both the stocks' data into a single object for further analysis. We use TSFrames.join to create two columns containing adjusted closing prices of both the stocks. The join happens by comparing the Index values (dates) of the two objects. The resulting object contains two columns with exactly the same dates for which both the objects have data, all the other rows are omitted from the result.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl = TSFrames.join(ibm[:, [\"AdjClose\"]], aapl[:, [\"AdjClose\"]]; jointype=:JoinBoth)\nTSFrames.rename!(ibm_aapl, [:IBM, :AAPL])","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"After the join operation the column names are modified because we merged two same-named columns (AdjClose) so we use TSFrames.rename!() method to rename the columns to easily remembered stock names.","category":"page"},{"location":"demo_finance/#Fill-missing-values","page":"Basic demo of TSFrames","title":"Fill missing values","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl = ibm_aapl |> Impute.locf()","category":"page"},{"location":"demo_finance/#Convert-data-into-weekly-frequency-using-last-values","page":"Basic demo of TSFrames","title":"Convert data into weekly frequency using last values","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Here, we convert daily stock data into weekly frequency by taking the value with which the trading closed on the last day of the week as the week's price.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl_weekly = to_weekly(ibm_aapl)","category":"page"},{"location":"demo_finance/#Compute-weekly-returns-using-the-familiar-log-and-diff-functions","page":"Basic demo of TSFrames","title":"Compute weekly returns using the familiar log and diff functions","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl_weekly_returns = diff(log.(ibm_aapl_weekly))\nTSFrames.rename!(ibm_aapl_weekly_returns, [:IBM, :AAPL])","category":"page"},{"location":"demo_finance/#Compute-standard-deviation-of-weekly-returns","page":"Basic demo of TSFrames","title":"Compute standard deviation of weekly returns","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Computing standard deviation is done using the std function from Statistics package. The skipmissing is used to skip missing values which may have been generated while computing log returns or were already present in the data.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_std = std(skipmissing(ibm_aapl_weekly_returns[:, :IBM]))","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"aapl_std = std(skipmissing(ibm_aapl_weekly_returns[:, :AAPL]))","category":"page"},{"location":"demo_finance/#Scatter-plot-of-AAPL-and-IBM","page":"Basic demo of TSFrames","title":"Scatter plot of AAPL and IBM","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Here, we use the Plots package to create a scatter plot with IBM weekly returns on the x-axis and Apple weekly returns on the y-axis.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ENV[\"GKSwstype\"] = \"100\" # hide\nplot(ibm_aapl_weekly_returns[:, :AAPL],\n ibm_aapl_weekly_returns[:, :IBM],\n seriestype = :scatter;\n xlabel = \"AAPL\",\n ylabel = \"IBM\",\n legend = false)\nsavefig(\"ts-plot.svg\"); nothing # hide","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"(Image: )","category":"page"},{"location":"demo_finance/#Aggregation-and-rolling-window-operations","page":"Basic demo of TSFrames","title":"Aggregation and rolling window operations","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Here, we compute realised volatility of returns of both IBM and Apple stock weekly and bi-monthly. Then, we compute daily returns volatility on a rolling basis with a window size of 10.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"daily_returns = diff(log.(ibm_aapl))\nrvol = apply(daily_returns, Week(1), std) # Compute the realised volatility\nrvol = apply(daily_returns, Month(2), std) # Every two months\nrollapply(daily_returns, std, 10) # Compute rolling vols","category":"page"},{"location":"demo_finance/#Rolling-regression-with-a-window-of-10","page":"Basic demo of TSFrames","title":"Rolling regression with a window of 10","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"One of the common finance problems is to run a rolling window regression of firm returns over market returns. For doing this, we will use the lm() function from the GLM package. We will create a separate function regress() which would take in the data as an argument and use pre-defined strings to identify the returns columns, pass them to lm(), and return the results.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"We start by downloading the S&P500 daily data from Yahoo Finance, then performing the same steps as above to come to a joined TSFrame object containing daily returns of S&P500 and IBM stock prices. Then, use rollapply() with bycolumn=false to tell rollapply() to pass in the entire TSFrame to the function in one go for each iteration within the window.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"sp500 = TSFrame(MarketData.yahoo(\"^GSPC\"));\nsp500_adjclose = TSFrames.subset(sp500, date_from, date_to)[:, [\"AdjClose\"]]\n\nsp500_ibm = join(sp500_adjclose, ibm_adjclose, jointype=:JoinBoth)\nsp500_ibm_returns = diff(log.(sp500_ibm))\nTSFrames.rename!(sp500_ibm_returns, [\"SP500\", \"IBM\"]);\n\nfunction regress(data)\n ll = lm(@formula(IBM ~ SP500), data)\n co::Real = coef(ll)[coefnames(ll) .== \"IBM\"][1]\n sd::Real = Statistics.std(residuals(ll))\n return (co, sd)\nend\n\nrollapply(sp500_ibm_returns, regress, 10, bycolumn=false)","category":"page"},{"location":"#TSFrames.jl","page":"Introduction","title":"TSFrames.jl","text":"","category":"section"},{"location":"","page":"Introduction","title":"Introduction","text":"TSFrames provides a convenient interface for performing standard manipulations of timeseries data. The package uses DataFrame at it's core to allow powerful data manipulation functions while being lightweight. It is inspired by zoo and xts packages from the R world.","category":"page"},{"location":"","page":"Introduction","title":"Introduction","text":"TSFrames wraps a familiar syntax for timeseries operations over DataFrame type, thereby, providing the user with full set of DataFrame functionalities as well. Integrations with other packages in the Julia ecosystem which are supported by DataFrames.jl come to TSFrames at little cost.","category":"page"},{"location":"","page":"Introduction","title":"Introduction","text":"To start using TSFrames.jl take a look at the basic demo and then head to the User guide.","category":"page"},{"location":"#User-guide","page":"Introduction","title":"User guide","text":"","category":"section"},{"location":"","page":"Introduction","title":"Introduction","text":"Pages = [\"user_guide.md\"]","category":"page"},{"location":"#API-reference","page":"Introduction","title":"API reference","text":"","category":"section"},{"location":"","page":"Introduction","title":"Introduction","text":"Pages = [\"api.md\"]","category":"page"}] +[{"location":"api/","page":"API reference","title":"API reference","text":"CurrentModule = TSFrames","category":"page"},{"location":"api/#TSFrames-API-reference","page":"API reference","title":"TSFrames API reference","text":"","category":"section"},{"location":"api/","page":"API reference","title":"API reference","text":"API reference of TSFrames.","category":"page"},{"location":"api/","page":"API reference","title":"API reference","text":"","category":"page"},{"location":"api/","page":"API reference","title":"API reference","text":"Modules = [TSFrames]","category":"page"},{"location":"api/#Base.Matrix-Tuple{TSFrame}","page":"API reference","title":"Base.Matrix","text":"Conversion of non-Index data to Matrix\n\nData in non-index columns of a TSFrame object can be converted into a Matrix type for further numerical analysis using the Matrix() constructor.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> ts = TSFrame([random(10) random(10)])\njulia> show(ts)\n(10 x 2) TSFrame with Int64 Index\n\n Index x1 x2\n Int64 Float64 Float64\n─────────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n 4 0.395453 0.395453\n 5 0.313244 0.313244\n 6 0.662555 0.662555\n 7 0.586022 0.586022\n 8 0.0521332 0.0521332\n 9 0.26864 0.26864\n 10 0.108871 0.108871\n\njulia> Matrix(ts)\n10×2 Matrix{Float64}:\n 0.768448 0.768448\n 0.940515 0.940515\n 0.673959 0.673959\n 0.395453 0.395453\n 0.313244 0.313244\n 0.662555 0.662555\n 0.586022 0.586022\n 0.0521332 0.0521332\n 0.26864 0.26864\n 0.108871 0.108871\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.TSFrame","page":"API reference","title":"TSFrames.TSFrame","text":"struct TSFrame\n coredata :: DataFrame\nend\n\n::TSFrame - A type to hold ordered data with an index.\n\nA TSFrame object is essentially a DataFrame with a specific column marked as an index. The input DataFrame is sorted during construction and is stored under the property coredata. The index is stored in the Index column of coredata.\n\nPermitted data inputs to the constructors are DataFrame, Vector, and 2-dimensional Array. If an index is already not present in the constructor then a sequential integer index is created automatically.\n\nTSFrame(coredata::DataFrame): Here, the constructor looks for a column named Index in coredata as the index column, if this is not found then the first column of coredata is made the index by default. If coredata only has a single column then a new sequential index is generated.\n\nSince TSFrame.coredata is a DataFrame it can be operated upon independently using methods provided by the DataFrames package (ex. transform, combine, etc.).\n\nConstructors\n\nTSFrame(coredata::DataFrame, index::Union{String, Symbol, Int}; issorted = false, copycols = true)\nTSFrame(coredata::DataFrame, index::AbstractVector{T}; issorted = false, copycols = true) where {T<:Union{Int, TimeType}}\nTSFrame(coredata::DataFrame; issorted = false, copycols = true)\nTSFrame(coredata::DataFrame, index::UnitRange{Int}; issorted = false, copycols = true)\nTSFrame(coredata::AbstractVector{T}, index::AbstractVector{V}; colnames=:auto, issorted = false, copycols = true) where {T, V}\nTSFrame(coredata::AbstractVector{T}; colnames=:auto, issorted = false, copycols = true) where {T}\nTSFrame(coredata::AbstractArray{T,2}; colnames=:auto, issorted = false, copycols = true) where {T}\nTSFrame(coredata::AbstractArray{T,2}, index::AbstractVector{V}; colnames=:auto, issorted = false, copycols = true) where {T, V}\nTSFrame(IndexType::DataType; n::Int=1)\nTSFrame(IndexType::DataType, cols::Vector{Tuple{DataType, S}}; issorted = false, copycols = true) where S <: Union{Symbol, String}\n\nWhen issorted is true, no sort operations are performed on the input. Whencopycolsistrue, the inputs are not copied, but placed directly in the TSFrame. This can be dangerous, so please only set this tofalse` if the input arrays will not be mutated later.\n\nissorted = true, copycols = false offers performance benefits, especially when constructing TSFrames in loops or other performance sensitive code.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> df = DataFrame(x1 = random(10))\n10×1 DataFrame\n Row │ x1\n │ Float64\n─────┼───────────\n 1 │ 0.768448\n 2 │ 0.940515\n 3 │ 0.673959\n 4 │ 0.395453\n 5 │ 0.313244\n 6 │ 0.662555\n 7 │ 0.586022\n 8 │ 0.0521332\n 9 │ 0.26864\n 10 │ 0.108871\n\njulia> ts = TSFrame(df) # generates index\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Float64\n──────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n 4 0.395453\n 5 0.313244\n 6 0.662555\n 7 0.586022\n 8 0.0521332\n 9 0.26864\n 10 0.108871\n\n# ts.coredata is a DataFrame\njulia> combine(ts.coredata, :x1 => Statistics.mean, DataFrames.nrow)\n1×2 DataFrame\n Row │ x1_mean nrow\n │ Float64 Int64\n─────┼────────────────\n 1 │ 0.49898 418\n\njulia> df = DataFrame(ind = [1, 2, 3], x1 = random(3))\n3×2 DataFrame\n Row │ ind x1\n │ Int64 Float64\n─────┼─────────────────\n 1 │ 1 0.768448\n 2 │ 2 0.940515\n 3 │ 3 0.673959\n\njulia> ts = TSFrame(df, 1) # the first column is index\n(3 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Float64\n─────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n\njulia> df = DataFrame(x1 = random(3), x2 = random(3), Index = [1, 2, 3]);\n3×3 DataFrame\n Row │ x1 x2 Index\n │ Float64 Float64 Int64\n─────┼───────────────────────────\n 1 │ 0.768448 0.768448 1\n 2 │ 0.940515 0.940515 2\n 3 │ 0.673959 0.673959 3\n\njulia> ts = TSFrame(df) # uses existing `Index` column\n(3 x 2) TSFrame with Int64 Index\n\n Index x1 x2\n Int64 Float64 Float64\n───────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> df = DataFrame(dates = dates, x1 = random(10))\n10×2 DataFrame\n Row │ dates x1\n │ Date Float64\n─────┼───────────────────────\n 1 │ 2017-01-01 0.768448\n 2 │ 2017-01-02 0.940515\n 3 │ 2017-01-03 0.673959\n 4 │ 2017-01-04 0.395453\n 5 │ 2017-01-05 0.313244\n 6 │ 2017-01-06 0.662555\n 7 │ 2017-01-07 0.586022\n 8 │ 2017-01-08 0.0521332\n 9 │ 2017-01-09 0.26864\n 10 │ 2017-01-10 0.108871\n\njulia> ts = TSFrame(df, :dates)\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> ts = TSFrame(DataFrame(x1=random(10)), dates);\n\njulia> ts = TSFrame(random(10))\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Float64\n──────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n 4 0.395453\n 5 0.313244\n 6 0.662555\n 7 0.586022\n 8 0.0521332\n 9 0.26864\n 10 0.108871\n\njulia> ts = TSFrame(random(10), colnames=[:A]) # column is named A\n(10 x 1) TSFrame with Int64 Index\n\n Index A\n Int64 Float64\n──────────────────\n 1 0.768448\n 2 0.940515\n 3 0.673959\n 4 0.395453\n 5 0.313244\n 6 0.662555\n 7 0.586022\n 8 0.0521332\n 9 0.26864\n 10 0.108871\n\njulia> ts = TSFrame(random(10), dates)\n(10 x 1) TSFrame with Date Index\n\n Index x1 \n Date Float64 \n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> ts = TSFrame(random(10), dates, colnames=[:A]) # column is named A\n(10 x 1) TSFrame with Date Index\n\n Index A \n Date Float64 \n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> ts = TSFrame([random(10) random(10)]) # matrix object\n(10 x 2) TSFrame with Int64 Index\n\n Index x1 x2 \n Int64 Float64 Float64 \n─────────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n 4 0.395453 0.395453\n 5 0.313244 0.313244\n 6 0.662555 0.662555\n 7 0.586022 0.586022\n 8 0.0521332 0.0521332\n 9 0.26864 0.26864\n 10 0.108871 0.108871\n\njulia> ts = TSFrame([random(10) random(10)], colnames=[:A, :B]) # columns are named A and B\n(10 x 2) TSFrame with Int64 Index\n\n Index A B \n Int64 Float64 Float64 \n─────────────────────────────\n 1 0.768448 0.768448\n 2 0.940515 0.940515\n 3 0.673959 0.673959\n 4 0.395453 0.395453\n 5 0.313244 0.313244\n 6 0.662555 0.662555\n 7 0.586022 0.586022\n 8 0.0521332 0.0521332\n 9 0.26864 0.26864\n 10 0.108871 0.108871\n\njulia> ts = TSFrame([random(10) random(10)], dates) \n(10 x 2) TSFrame with Date Index\n\n Index x1 x2\n Date Float64 Float64\n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\njulia> ts = TSFrame([random(10) random(10)], dates, colnames=[:A, :B]) # columns are named A and B\n(10 x 2) TSFrame with Date Index\n\n Index A B \n Date Float64 Float64 \n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\njulia> ts = TSFrame(Int64; n=5) # empty TSFrame with 5 columns of type Any and with Int64 index type\n0×5 TSFrame with Int64 Index\n\njulia> ts = TSFrame(Date, [(Int64, :col1), (String, :col2), (Float64, :col3)]) # empty TSFrame with specific column names and types\n0×3 TSFrame with Date Index\n\njulia> ts = TSFrame(Date, [(Int64, \"col1\"), (String, \"col2\"), (Float64, \"col3\")]) # using strings instead of symbols\n0×3 TSFrame with Date Index\n\n\n\n\n\n\n","category":"type"},{"location":"api/#Base.:==-Tuple{TSFrame, TSFrame}","page":"API reference","title":"Base.:==","text":"Equality\n\nTwo TSFrame are considered equal if their `coredata` property is equal.\nBase.:(==)(tsf1::TSFrame, tsf2::TSFrame)::Bool\nBase.isequal(tsf1::TSFrame, tsf2::TSFrame)::Bool\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.first-Tuple{TSFrame}","page":"API reference","title":"Base.first","text":"First Row\n\nfirst(ts::TSFrame)\n\nReturns the first row of ts as a TSFrame object.\n\nExamples\n\njulia> first(TSFrame(1:10))\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-02-01 0.768448\n\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.iterate","page":"API reference","title":"Base.iterate","text":"Iterators\n\nBase.iterate(tsf::TSFrame)\n\nReturns a row-based iterator for `tsf`.\n\n\n\n\n\n","category":"function"},{"location":"api/#Base.join-Tuple{TSFrame, TSFrame, Vararg{Any}}","page":"API reference","title":"Base.join","text":"Joins/Column-binding\n\njoin(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol=:JoinAll)\n\nTSFrame objects can be combined together column-wise using Index as the column key. There are four kinds of column-binding operations possible as of now. Each join operation works by performing a Set operation on the Index column and then merging the datasets based on the output from the Set operation. Each operation changes column names in the final object automatically if the operation encounters duplicate column names amongst the TSFrame objects.\n\nThe following join types are supported:\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinInner) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinBoth)\n\na.k.a. inner join, takes the intersection of the indexes of ts1 and ts2, and then merges the columns of both the objects. The resulting object will only contain rows which are present in both the objects' indexes. The function will rename columns in the final object if they had same names in the TSFrame objects.\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinOuter) and join(ts1::TSFrame, ts2::TSFrame; jointype=:JoinAll):\n\na.k.a. outer join, takes the union of the indexes of ts1 and ts2 before merging the other columns of input objects. The output will contain rows which are present in all the input objects while inserting missing values where a row was not present in any of the objects. This is the default behaviour if no jointype is provided.\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinLeft):\n\nLeft join takes the index values which are present in the left object ts1 and finds matching index values in the right object ts2. The resulting object includes all the rows from the left object, the column values from the left object, and the values associated with matching index rows on the right. The operation inserts missing values where in the unmatched rows of the right object.\n\njoin(ts1::TSFrame, ts2::TSFrame; jointype=:JoinRight)\n\nRight join, similar to left join but works in the opposite direction. The final object contains all the rows from the right object while inserting missing values in rows missing from the left object.\n\nThe default behaviour is to assume jointype=:JoinAll if no jointype is provided to the join method.\n\nJoining multiple TSFrames is also supported. The syntax is\n\njoin(ts1::TSFrame, ts2::TSFrame, ts...; jointype::Symbol)\n\nwhere jointype must be one of :JoinInner, :JoinBoth, :JoinOuter, :JoinAll, :JoinLeft or :JoinRight. Note that join on multiple TSFrames is left associative.\n\ncbind is an alias for join method.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> ts1 = TSFrame(random(length(dates)), dates);\njulia> show(ts1)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,30));\n\njulia> ts2 = TSFrame(random(length(dates)), dates);\njulia> show(ts2)\n30×1 TSFrame with Date Index\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n 2017-01-11 0.163666\n 2017-01-12 0.473017\n 2017-01-13 0.865412\n 2017-01-14 0.617492\n 2017-01-15 0.285698\n 2017-01-16 0.463847\n 2017-01-17 0.275819\n 2017-01-18 0.446568\n 2017-01-19 0.582318\n 2017-01-20 0.255981\n 2017-01-21 0.70586\n 2017-01-22 0.291978\n 2017-01-23 0.281066\n 2017-01-24 0.792931\n 2017-01-25 0.20923\n 2017-01-26 0.918165\n 2017-01-27 0.614255\n 2017-01-28 0.802665\n 2017-01-29 0.555668\n 2017-01-30 0.940782\n\n# join on all index values\n# equivalent to `join(ts1, ts2; jointype=:JoinAll)` call\njulia> join(ts1, ts2)\n(30 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64? Float64?\n────────────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n ⋮ ⋮ ⋮\n 2017-01-22 missing 0.291978\n 2017-01-23 missing 0.281066\n 2017-01-24 missing 0.792931\n 2017-01-25 missing 0.20923\n 2017-01-26 missing 0.918165\n 2017-01-27 missing 0.614255\n 2017-01-28 missing 0.802665\n 2017-01-29 missing 0.555668\n 2017-01-30 missing 0.940782\n 11 rows omitted\n\n# alias to `join()`\njulia> cbind(ts1, ts2);\n\n# join only the common index values\njulia> join(ts1, ts2; jointype=:JoinBoth)\n(10 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64 Float64\n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\n# keep index values of `ts1`\njulia> join(ts1, ts2; jointype=:JoinLeft)\n(10 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64 Float64?\n──────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n\n# keep index values of `ts2`\njulia> join(ts1, ts2; jointype=:JoinRight)\n(30 x 2) TSFrame with Date Index\n Index x1 x1_1\n Date Float64? Float64\n────────────────────────────────────────\n 2017-01-01 0.768448 0.768448\n 2017-01-02 0.940515 0.940515\n 2017-01-03 0.673959 0.673959\n 2017-01-04 0.395453 0.395453\n 2017-01-05 0.313244 0.313244\n 2017-01-06 0.662555 0.662555\n 2017-01-07 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864\n 2017-01-10 0.108871 0.108871\n ⋮ ⋮ ⋮\n 2017-01-22 missing 0.291978\n 2017-01-23 missing 0.281066\n 2017-01-24 missing 0.792931\n 2017-01-25 missing 0.20923\n 2017-01-26 missing 0.918165\n 2017-01-27 missing 0.614255\n 2017-01-28 missing 0.802665\n 2017-01-29 missing 0.555668\n 2017-01-30 missing 0.940782\n 11 rows omitted\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,30));\n\njulia> ts3 = TSFrame(random(length(dates)), dates);\njulia> show(ts3)\n30×1 TSFrame with Date Index\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n 2017-01-11 0.163666\n 2017-01-12 0.473017\n 2017-01-13 0.865412\n 2017-01-14 0.617492\n 2017-01-15 0.285698\n 2017-01-16 0.463847\n 2017-01-17 0.275819\n 2017-01-18 0.446568\n 2017-01-19 0.582318\n 2017-01-20 0.255981\n 2017-01-21 0.70586\n 2017-01-22 0.291978\n 2017-01-23 0.281066\n 2017-01-24 0.792931\n 2017-01-25 0.20923\n 2017-01-26 0.918165\n 2017-01-27 0.614255\n 2017-01-28 0.802665\n 2017-01-29 0.555668\n 2017-01-30 0.940782\n\n# joining multiple TSFrame objects\njulia> join(ts1, ts2, ts3; jointype=:JoinLeft)\n10×3 TSFrame with Date Index\n Index x1 x1_1 x1_2\n Date Float64 Float64? Float64?\n─────────────────────────────────────────────\n 2017-01-01 0.768448 0.768448 0.768448\n 2017-01-02 0.940515 0.940515 0.940515\n 2017-01-03 0.673959 0.673959 0.673959\n 2017-01-04 0.395453 0.395453 0.395453\n 2017-01-05 0.313244 0.313244 0.313244\n 2017-01-06 0.662555 0.662555 0.662555\n 2017-01-07 0.586022 0.586022 0.586022\n 2017-01-08 0.0521332 0.0521332 0.0521332\n 2017-01-09 0.26864 0.26864 0.26864\n 2017-01-10 0.108871 0.108871 0.108871\n\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.size-Tuple{TSFrame}","page":"API reference","title":"Base.size","text":"Size methods\n\nsize(ts::TSFrame)\n\nReturn the number of rows and columns of ts as a tuple.\n\nExamples\n\njulia> TSFrames.size(TSFrame([collect(1:100) collect(1:100) collect(1:100)]))\n(100, 3)\n\n\n\n\n\n","category":"method"},{"location":"api/#Base.vcat-Tuple{TSFrame, TSFrame}","page":"API reference","title":"Base.vcat","text":"Row-merging (vcat/rbind)\n\nvcat(ts1::TSFrame, ts2::TSFrame; colmerge::Symbol=:union)\n\nConcatenate rows of two TSFrame objects, append ts2 to ts1.\n\nThe colmerge keyword argument specifies the column merge strategy. The value of colmerge is directly passed to cols argument of DataFrames.vcat.\n\nCurrently, DataFrames.vcat supports four types of column-merge strategies:\n\n:setequal: only merge if both objects have same column names, use the order of columns in ts1.\n:orderequal: only merge if both objects have same column names and columns are in the same order.\n:intersect: only merge the columns which are common to both objects, ignore the rest.\n:union: merge even if columns differ, the resulting object has all the columns filled with missing, if necessary.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates1 = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> dates2 = collect(Date(2017,1,11):Day(1):Date(2017,1,30));\n\njulia> ts1 = TSFrame([randn(length(dates1)) randn(length(dates1))], dates1)\njulia> show(ts1)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n────────────────────────\n 2017-01-01 -0.420348\n 2017-01-02 0.109363\n 2017-01-03 -0.0702014\n 2017-01-04 0.165618\n 2017-01-05 -0.0556799\n 2017-01-06 -0.147801\n 2017-01-07 -2.50723\n 2017-01-08 -0.099783\n 2017-01-09 0.177526\n 2017-01-10 -1.08461\n\njulia> df = DataFrame(x1 = randn(length(dates2)), y1 = randn(length(dates2)))\njulia> ts2 = TSFrame(df, dates2)\njulia> show(ts2)\n(20 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n────────────────────────\n 2017-01-11 2.15087\n 2017-01-12 0.9203\n 2017-01-13 -0.0879142\n 2017-01-14 -0.930109\n 2017-01-15 0.061117\n 2017-01-16 0.0434627\n 2017-01-17 0.0834733\n 2017-01-18 -1.52281\n ⋮ ⋮\n 2017-01-23 -0.756143\n 2017-01-24 0.491623\n 2017-01-25 0.549672\n 2017-01-26 0.570689\n 2017-01-27 -0.380011\n 2017-01-28 -2.09965\n 2017-01-29 1.37289\n 2017-01-30 -0.462384\n 4 rows omitted\n\n\njulia> vcat(ts1, ts2)\n(30 x 3) TSFrame with Date Index\n\n Index x1 x2 y1\n Date Float64 Float64? Float64?\n─────────────────────────────────────────────────────────\n 2017-01-01 -0.524798 -1.4949 missing\n 2017-01-02 -0.719611 -1.1278 missing\n 2017-01-03 0.0926092 1.19778 missing\n 2017-01-04 0.236237 1.39115 missing\n 2017-01-05 0.369588 1.21792 missing\n 2017-01-06 1.65287 -0.930058 missing\n 2017-01-07 0.761301 0.23794 missing\n 2017-01-08 -0.571046 -0.480486 missing\n 2017-01-09 -2.01905 -0.46391 missing\n 2017-01-10 0.193942 -1.01471 missing\n 2017-01-11 0.239041 missing -0.473429\n 2017-01-12 0.286036 missing -0.90377\n 2017-01-13 0.683429 missing -0.128489\n 2017-01-14 -1.51442 missing -2.39843\n 2017-01-15 -0.581341 missing -0.12265\n 2017-01-16 1.07059 missing -0.916064\n 2017-01-17 0.859396 missing 0.0162969\n 2017-01-18 -1.93127 missing 2.11127\n 2017-01-19 0.529477 missing 0.636964\n 2017-01-20 0.817429 missing -0.34038\n 2017-01-21 -0.682296 missing -0.971262\n 2017-01-22 1.36232 missing -0.236323\n 2017-01-23 0.143188 missing -0.501722\n 2017-01-24 0.621845 missing -1.20016\n 2017-01-25 0.076199 missing -1.36616\n 2017-01-26 0.379672 missing -0.555395\n 2017-01-27 0.494473 missing 1.05389\n 2017-01-28 0.278259 missing -0.358983\n 2017-01-29 0.0231765 missing 0.712526\n 2017-01-30 0.516704 missing 0.216855\n\njulia> vcat(ts1, ts2; colmerge=:intersect)\n(30 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n────────────────────────\n 2017-01-01 -0.524798\n 2017-01-02 -0.719611\n 2017-01-03 0.0926092\n 2017-01-04 0.236237\n 2017-01-05 0.369588\n 2017-01-06 1.65287\n 2017-01-07 0.761301\n 2017-01-08 -0.571046\n 2017-01-09 -2.01905\n 2017-01-10 0.193942\n 2017-01-11 0.239041\n 2017-01-12 0.286036\n 2017-01-13 0.683429\n 2017-01-14 -1.51442\n 2017-01-15 -0.581341\n 2017-01-16 1.07059\n 2017-01-17 0.859396\n 2017-01-18 -1.93127\n 2017-01-19 0.529477\n 2017-01-20 0.817429\n 2017-01-21 -0.682296\n 2017-01-22 1.36232\n 2017-01-23 0.143188\n 2017-01-24 0.621845\n 2017-01-25 0.076199\n 2017-01-26 0.379672\n 2017-01-27 0.494473\n 2017-01-28 0.278259\n 2017-01-29 0.0231765\n 2017-01-30 0.516704\n\n\n\n\n\n\n","category":"method"},{"location":"api/#RecipesBase.apply_recipe","page":"API reference","title":"RecipesBase.apply_recipe","text":"Plotting\n\nplot(ts::TSFrame, cols::Vector{Int} = collect(1:TSFrames.ncol(ts)))\nplot(ts::TSFrame, cols::Vector{T}) where {T<:Union{String, Symbol}}\nplot(ts::TSFrame, cols::T) where {T<:Union{Int, String, Symbol}}\n\nPlots a TSFrame object with the index on the x-axis and selected cols on the y-axis. By default, plot all the columns. Columns can be selected using Int indexes, String(s), or Symbol(s).\n\nExample\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = Date(\"2022-01-01\"):Month(1):Date(\"2022-01-01\")+Month(11);\n\njulia> df = DataFrame(Index = dates,\n val1 = random(12),\n val2 = random(12),\n val3 = random(12));\n\njulia> ts = TSFrame(df)\njulia> show(ts)\n(12 x 3) TSFrame with Dates.Date Index\n\n Index val1 val2 val3\n Date Float64 Float64 Float64\n────────────────────────────────────────────────\n 2022-01-01 -0.319954 0.974594 -0.552977\n 2022-02-01 -0.0386735 -0.171675 0.779539\n 2022-03-01 1.67678 -1.75251 0.820462\n 2022-04-01 1.69702 -0.0130037 1.0507\n 2022-05-01 0.992128 0.76957 -1.28008\n 2022-06-01 -0.315461 -0.543976 -0.117256\n 2022-07-01 -1.18952 -1.12867 -0.0829082\n 2022-08-01 0.159595 0.450044 -0.231828\n 2022-09-01 0.501436 0.265327 -0.948532\n 2022-10-01 -2.10516 -1.11489 0.285194\n 2022-11-01 -0.781082 -1.20202 -0.639953\n 2022-12-01 -0.169184 1.34879 1.33361\n\n\njulia> using Plots\n\njulia> # plot(ts)\n\n# plot first 6 rows with selected columns\njulia> # plot(ts[1:6], [:val1, :val3]);\n\n# plot columns 1 and 2 on a specified window size\njulia> # plot(ts, [1, 2], size=(600, 400));\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames._check_consistency-Tuple{TSFrame}","page":"API reference","title":"TSFrames._check_consistency","text":"Internal function to check consistency of the Index of a TSFrame object.\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.apply-Union{Tuple{V}, Tuple{T}, Tuple{TSFrame, T, V}, Tuple{TSFrame, T, V, Function}} where {T<:Dates.Period, V<:Function}","page":"API reference","title":"TSFrames.apply","text":"Apply/Period conversion\n\napply(ts::TSFrame,\n period::T,\n fun::V,\n index_at::Function=first;\n renamecols::Bool=true)\n where {T<:Dates.Period, V <: Function}\n\nApply fun to ts object based on period and return correctly indexed rows. This method is used for doing aggregation over a time period or to convert ts into an object of lower frequency (ex. from daily series to monthly).\n\nperiod is any of Period types in the Dates module. Conversion from lower to a higher frequency will throw an error as interpolation isn't currently handled by this method.\n\nBy default, the method uses the first value of the index within the period to index the resulting aggregated object. This behaviour can be controlled by index_at argument which can take first or last as an input.\n\nKeyword arguments\n\nrenamecols::Bool=true: whether to rename column names in the resulting object. If false, the column name is automatically generated based on the name of fun otherwise existing column names are used.\n\nExamples\n\njulia> using Random, Statistics;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2018,3,10));\n\njulia> ts = TSFrame(random(length(dates)), dates)\njulia> show(ts[1:10])\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> apply(ts, Month(1), first)\n(15 x 1) TSFrame with Date Index\n\n Index x1_first\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-02-01 0.790201\n 2017-03-01 0.467219\n 2017-04-01 0.783473\n 2017-05-01 0.651354\n 2017-06-01 0.373346\n 2017-07-01 0.83296\n 2017-08-01 0.132716\n 2017-09-01 0.27899\n 2017-10-01 0.995414\n 2017-11-01 0.214132\n 2017-12-01 0.832917\n 2018-01-01 0.0409471\n 2018-02-01 0.720163\n 2018-03-01 0.87459\n\n# alternate months\njulia> apply(ts, Month(2), first)\n(8 x 1) TSFrame with Date Index\n\n Index x1_first\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-03-01 0.467219\n 2017-05-01 0.651354\n 2017-07-01 0.83296\n 2017-09-01 0.27899\n 2017-11-01 0.214132\n 2018-01-01 0.0409471\n 2018-03-01 0.87459\n\n\njulia> ts_weekly = apply(ts, Week(1), Statistics.std) # weekly standard deviation\njulia> show(ts_weekly[1:10])\n(10 x 1) TSFrame with Date Index\n\n Index x1_std\n Date Float64\n────────────────────────\n 2017-01-01 NaN\n 2017-01-02 0.28935\n 2017-01-09 0.270842\n 2017-01-16 0.170197\n 2017-01-23 0.269573\n 2017-01-30 0.326687\n 2017-02-06 0.279935\n 2017-02-13 0.319216\n 2017-02-20 0.272058\n 2017-02-27 0.23651\n\n\njulia> ts_weekly = apply(ts, Week(1), Statistics.std, last) # indexed by last date of the week\njulia> show(ts_weekly[1:10])\n(10 x 1) TSFrame with Date Index\n\n Index x1_std\n Date Float64\n────────────────────────\n 2017-01-01 NaN\n 2017-01-08 0.28935\n 2017-01-15 0.270842\n 2017-01-22 0.170197\n 2017-01-29 0.269573\n 2017-02-05 0.326687\n 2017-02-12 0.279935\n 2017-02-19 0.319216\n 2017-02-26 0.272058\n 2017-03-05 0.23651\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.describe-Tuple{IO, TSFrame}","page":"API reference","title":"TSFrames.describe","text":"Summary statistics\n\ndescribe(ts::TSFrame; cols=:)\ndescribe(ts::TSFrame, stats::Union{Symbol, Pair}...; cols=:)\n\nCompute summary statistics of ts. The output is a DataFrame containing standard statistics along with number of missing values and data types of columns. The cols keyword controls which subset of columns from ts to be selected. The stats keyword is used to control which summary statistics are to be printed. For more information about these keywords, check out the corresponding documentation from DataFrames.jl.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x...);\njulia> ts = TSFrame(random(([1, 2, 3, 4, missing], 10)))\njulia> describe(ts)\n2×7 DataFrame\n Row │ variable mean min median max nmissing eltype\n │ Symbol Float64 Int64 Float64 Int64 Int64 Type\n─────┼───────────────────────────────────────────────────────────────────────────\n 1 │ Index 5.5 1 5.5 10 0 Int64\n 2 │ x1 2.75 2 3.0 4 2 Union{Missing, Int64}\njulia> describe(ts, cols=:Index)\n1×7 DataFrame\n Row │ variable mean min median max nmissing eltype\n │ Symbol Float64 Int64 Float64 Int64 Int64 DataType\n─────┼──────────────────────────────────────────────────────────────\n 1 │ Index 5.5 1 5.5 10 0 Int64\njulia> describe(ts, :min, :max, cols=:x1)\n1×3 DataFrame\n Row │ variable min max\n │ Symbol Int64 Int64\n─────┼────────────────────────\n 1 │ x1 2 4\njulia> describe(ts, :min, sum => :sum)\n2×3 DataFrame\n Row │ variable min sum\n │ Symbol Int64 Int64\n─────┼────────────────────────\n 1 │ Index 1 55\n 2 │ x1 2 22\njulia> describe(ts, :min, sum => :sum, cols=:x1)\n1×3 DataFrame\n Row │ variable min sum\n │ Symbol Int64 Int64\n─────┼────────────────────────\n 1 │ x1 2 22\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.endpoints","page":"API reference","title":"TSFrames.endpoints","text":"Computing end points\n\nendpoints(timestamps::AbstractVector{T}, on::V) where {T<:Union{Date, DateTime, Time}, V<:Dates.Period}\nendpoints(ts::TSFrame, on::T) where {T<:Dates.Period}\nendpoints(ts::TSFrame, on::Symbol, k::Int=1)\nendpoints(ts::TSFrame, on::String, k::Int=1)\nendpoints(ts::TSFrame, on::Function, k::Int=1)\nendpoints(values::AbstractVector, on::Function, k::Int=1)\n\nReturn an integer vector of values for last observation in timestamps for each period given by on. The values are picked up every on.value instance of the period.\n\nCan be used to subset a TSFrame object directly using this function's return value. The methods work for regular time series of any periodicity and irregular time series belonging to any of the time-based types provided by the Dates module.\n\nThe primary method works for series of all time types including Date, DateTime, and Time, and for on belonging to any of the sub-types of Dates.Period. The ::TSFrame methods are provided for convenience and call the primary method directly using the Index column.\n\nFor the methods accepting on of Function type the values vector will get converted into unique period-groups which act as unique keys. The method uses these keys to create groups of values and uses the period provided by on to pick up the last observation in each group. k decides the number of groups to skip. For example, k=2 picks every alternate group starting from the 2ⁿᵈ element out of the ones created by on. See the examples below to see how the function works in the real world. The on function should return a Vector to be used as grouping keys.\n\nendpoints(ts::TSFrame, on::Symbol) and endpoints(ts::TSFrame, on::String) are convenience methods where valid values for on are: :years, :quarters, :months, :weeks, :days, :hours, :minutes, :seconds, :milliseconds, :microseconds, and :nanoseconds.\n\nNote, that except for on::Function all other methods expect Index type of TSFrame to be a subtype of TimeType.\n\nThe method returns Vector{Int} corresponding to the matched values in the first argument.\n\nExamples\n\njulia> using Random\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = Date(2017):Day(1):Date(2019);\njulia> ts = TSFrame(random(length(dates)), dates)\n(731 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n ⋮ ⋮\n 2018-12-24 0.812797\n 2018-12-25 0.158056\n 2018-12-26 0.269285\n 2018-12-27 0.15065\n 2018-12-28 0.916177\n 2018-12-29 0.278016\n 2018-12-30 0.617211\n 2018-12-31 0.67549\n 2019-01-01 0.910285\n 712 rows omitted\n\njulia> ep = endpoints(ts, Month(1))\n25-element Vector{Int64}:\n 31\n 59\n 90\n 120\n 151\n 181\n 212\n 243\n 273\n 304\n 334\n 365\n 396\n 424\n 455\n 485\n 516\n 546\n 577\n 608\n 638\n 669\n 699\n 730\n 731\n\njulia> ts[ep]\n(25 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-31 0.48\n 2017-02-28 0.458476\n 2017-03-31 0.274441\n 2017-04-30 0.413966\n 2017-05-31 0.734931\n 2017-06-30 0.257159\n 2017-07-31 0.415851\n 2017-08-31 0.0377973\n 2017-09-30 0.934059\n 2017-10-31 0.413175\n 2017-11-30 0.557009\n 2017-12-31 0.346659\n 2018-01-31 0.174777\n 2018-02-28 0.432223\n 2018-03-31 0.835142\n 2018-04-30 0.945539\n 2018-05-31 0.0635483\n 2018-06-30 0.589922\n 2018-07-31 0.285088\n 2018-08-31 0.912558\n 2018-09-30 0.238931\n 2018-10-31 0.49775\n 2018-11-30 0.830232\n 2018-12-31 0.67549\n 2019-01-01 0.910285\n\njulia> diff(index(ts[ep]))\n24-element Vector{Day}:\n 28 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 31 days\n 28 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 31 days\n 30 days\n 31 days\n 30 days\n 31 days\n 1 day\n\n# every 2ⁿᵈ month\njulia> ts[endpoints(ts, Month(2))]\n(12 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-02-28 0.458476\n 2017-04-30 0.413966\n 2017-06-30 0.257159\n 2017-08-31 0.0377973\n 2017-10-31 0.413175\n 2017-12-31 0.346659\n 2018-02-28 0.432223\n 2018-04-30 0.945539\n 2018-06-30 0.589922\n 2018-08-31 0.912558\n 2018-10-31 0.49775\n 2018-12-31 0.67549\n 2019-01-01 0.910285\n\n# Weekly points using a function\njulia> endpoints(ts, i -> lastdayofweek.(i), 1)\n106-element Vector{Int64}:\n 1\n 8\n 15\n 22\n 29\n 36\n 43\n ⋮\n 694\n 701\n 708\n 715\n 722\n 729\n 731\n\njulia> endpoints(ts, i -> lastdayofweek.(i), 1) == endpoints(ts, Week(1))\ntrue\n\n# Time type series\njulia> timestampsminutes = collect(Time(9, 1, 2):Minute(1):Time(11, 2, 3));\njulia> timestampsminutes[endpoints(timestampsminutes, Minute(2))]\n61-element Vector{Time}:\n 09:02:02\n 09:04:02\n 09:06:02\n 09:08:02\n 09:10:02\n 09:12:02\n 09:14:02\n 09:16:02\n 09:18:02\n 09:20:02\n 09:22:02\n 09:24:02\n ⋮\n 10:40:02\n 10:42:02\n 10:44:02\n 10:46:02\n 10:48:02\n 10:50:02\n 10:52:02\n 10:54:02\n 10:56:02\n 10:58:02\n 11:00:02\n 11:02:02\n\njulia> timestampsminutes[endpoints(timestampsminutes, Hour(1))]\n3-element Vector{Time}:\n 09:59:02\n 10:59:02\n 11:02:02\n\n## Irregular series\njulia> datetimeseconds = collect(range(DateTime(2022, 10, 08) + Hour(9),\n DateTime(2022, 10, 08) + Hour(15) + Minute(29),\n step=Second(1)));\njulia> datetimesecondsrandom = sample(MersenneTwister(123), datetimeseconds, 20, replace=false, ordered=true)\n17-element Vector{DateTime}:\n 2022-10-08T09:20:16\n 2022-10-08T09:32:00\n 2022-10-08T09:43:57\n 2022-10-08T10:13:27\n 2022-10-08T10:44:34\n 2022-10-08T11:04:23\n 2022-10-08T11:08:37\n 2022-10-08T11:46:51\n 2022-10-08T11:56:46\n 2022-10-08T12:14:22\n 2022-10-08T12:32:08\n 2022-10-08T13:28:42\n 2022-10-08T13:34:33\n 2022-10-08T13:54:11\n 2022-10-08T13:59:08\n 2022-10-08T14:05:57\n 2022-10-08T14:37:17\n\njulia> datetimesecondsrandom[endpoints(datetimesecondsrandom, Hour(1))]\n6-element Vector{DateTime}:\n 2022-10-08T09:43:57\n 2022-10-08T10:44:34\n 2022-10-08T11:56:46\n 2022-10-08T12:32:08\n 2022-10-08T13:59:08\n 2022-10-08T14:37:17\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.head","page":"API reference","title":"TSFrames.head","text":"Head\n\nhead(ts::TSFrame, n::Int = 10)\n\nReturns the first n rows of ts.\n\nExamples\n\njulia> head(TSFrame(1:100))\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Int64\n──────────────\n 1 1\n 2 2\n 3 3\n 4 4\n 5 5\n 6 6\n 7 7\n 8 8\n 9 9\n 10 10\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.index-Tuple{TSFrame}","page":"API reference","title":"TSFrames.index","text":"Index column\n\nindex(ts::TSFrame)\n\nReturn the index vector from the coredata DataFrame.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> ts = TSFrame(random(10), Date(\"2022-02-01\"):Month(1):Date(\"2022-02-01\")+Month(9));\n\n\njulia> show(ts)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-02-01 0.768448\n 2022-03-01 0.940515\n 2022-04-01 0.673959\n 2022-05-01 0.395453\n 2022-06-01 0.313244\n 2022-07-01 0.662555\n 2022-08-01 0.586022\n 2022-09-01 0.0521332\n 2022-10-01 0.26864\n 2022-11-01 0.108871\n\njulia> index(ts)\n10-element Vector{Date}:\n 2022-02-01\n 2022-03-01\n 2022-04-01\n 2022-05-01\n 2022-06-01\n 2022-07-01\n 2022-08-01\n 2022-09-01\n 2022-10-01\n 2022-11-01\n\njulia> eltype(index(ts))\nDate\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.isregular-Union{Tuple{AbstractVector{V}}, Tuple{V}, Tuple{AbstractVector{V}, Symbol}} where V<:Dates.TimeType","page":"API reference","title":"TSFrames.isregular","text":"isregular(timestamps::V, unit::T) where {V<:AbstractVector{TimeType}, T<:Dates.Period}\nisregular(timestamps::T) where {T<:AbstractVector{TimeType}}\nisregular(timestamps::AbstractVector{V}, unit::Symbol = :firstdiff) where {V<:TimeType}\nisregular(ts::TSFrame, unit::Symbol = :firstdiff)\nisregular(ts::TSFrame, unit::T) where {T<:Dates.Period}\n\nCheck if ts is regular.\n\nif unit == :firstdiff then it checks if first difference of index is constant\notherwise it will check if first difference is constant with respect to specified timeperiod.\n\nFor eg. if unit == :month then check if first difference is constant with respect to months.\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates=collect(Date(2017,1,1):Day(1):Date(2017,1,10))\n10-element Vector{Date}:\n 2017-01-01\n 2017-01-02\n 2017-01-03\n 2017-01-04\n 2017-01-05\n 2017-01-06\n 2017-01-07\n 2017-01-08\n 2017-01-09\n 2017-01-10\n\njulia> isregular(dates) # check if regular\ntrue\n\njulia> isregular(dates, Day(1)) # check if regular with a time difference of 1 day\ntrue\n\njulia> isregular(dates, Day(2)) # check if regular with a time difference of 2 days\nfalse\n\njulia> isregular(dates, :month) # check if regular with respect to months\nfalse\n\njulia> ts = TSFrame(random(10), dates)\n10×1 TSFrame with Date Index\n Index x1 \n Date Float64 \n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\njulia> isregular(ts)\ntrue\n\njulia> isregular(ts, Day(1))\ntrue\n\njulia> isregular(ts, Day(2))\nfalse\n\njulia> isregular(ts, :month)\nfalse\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.lag","page":"API reference","title":"TSFrames.lag","text":"Lagging\n\nlag(ts::TSFrame, lag_value::Int = 1)\n\nLag the ts object by the specified lag_value. The rows corresponding to lagged values will be rendered as missing. Negative values of lag are also accepted (see TSFrames.lead).\n\nExamples\n\njulia> using Random, Statistics;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2017,1,10));\n\njulia> ts = TSFrame(random(length(dates)), dates);\njulia> show(ts)\n(10 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n 2017-01-09 0.26864\n 2017-01-10 0.108871\n\n\njulia> lag(ts)\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n─────────────────────────────\n 2017-01-01 missing\n 2017-01-02 0.768448\n 2017-01-03 0.940515\n 2017-01-04 0.673959\n 2017-01-05 0.395453\n 2017-01-06 0.313244\n 2017-01-07 0.662555\n 2017-01-08 0.586022\n 2017-01-09 0.0521332\n 2017-01-10 0.26864\n\njulia> lag(ts, 2) # lags by 2 values\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n─────────────────────────────\n 2017-01-01 missing\n 2017-01-02 missing\n 2017-01-03 0.768448\n 2017-01-04 0.940515\n 2017-01-05 0.673959\n 2017-01-06 0.395453\n 2017-01-07 0.313244\n 2017-01-08 0.662555\n 2017-01-09 0.586022\n 2017-01-10 0.0521332\n\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.lead","page":"API reference","title":"TSFrames.lead","text":"Leading\n\nlead(ts::TSFrame, lead_value::Int = 1)\n\nSimilar to lag, this method leads the ts object by lead_value. The lead rows are inserted with missing. Negative values of lead are also accepted (see TSFrames.lag).\n\nExamples\n\njulia> using Random, Statistics;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> dates = collect(Date(2017,1,1):Day(1):Date(2018,3,10));\n\njulia> ts = TSFrame(DataFrame(Index = dates, x1 = random(length(dates))))\njulia> show(ts)\n(434 x 1) TSFrame with Dates.Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2017-01-01 0.768448\n 2017-01-02 0.940515\n 2017-01-03 0.673959\n 2017-01-04 0.395453\n 2017-01-05 0.313244\n 2017-01-06 0.662555\n 2017-01-07 0.586022\n 2017-01-08 0.0521332\n ⋮ ⋮\n 2018-03-03 0.127635\n 2018-03-04 0.147813\n 2018-03-05 0.873555\n 2018-03-06 0.486486\n 2018-03-07 0.495525\n 2018-03-08 0.64075\n 2018-03-09 0.375126\n 2018-03-10 0.0338698\n 418 rows omitted\n\n\njulia> lead(ts)[1:10] # leads once\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n───────────────────────\n 2017-01-01 0.940515\n 2017-01-02 0.673959\n 2017-01-03 0.395453\n 2017-01-04 0.313244\n 2017-01-05 0.662555\n 2017-01-06 0.586022\n 2017-01-07 0.0521332\n 2017-01-08 0.26864\n 2017-01-09 0.108871\n 2017-01-10 0.163666\n\njulia> lead(ts, 2)[1:10] # leads by 2 values\n(10 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64?\n───────────────────────\n 2017-01-01 0.673959\n 2017-01-02 0.395453\n 2017-01-03 0.313244\n 2017-01-04 0.662555\n 2017-01-05 0.586022\n 2017-01-06 0.0521332\n 2017-01-07 0.26864\n 2017-01-08 0.108871\n 2017-01-09 0.163666\n 2017-01-10 0.473017\n\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.ncol-Tuple{TSFrame}","page":"API reference","title":"TSFrames.ncol","text":"Size methods\n\nncol(ts::TSFrame)\n\nReturn the number of columns of ts. nc is an alias for ncol.\n\nExamples\n\njulia> using Random;\n\njulia> random(x) = rand(MersenneTwister(123), x);\n\njulia> TSFrames.ncol(TSFrame([random(100) random(100) random(100)]))\n3\n\njulia> nc(TSFrame([random(100) random(100) random(100)]))\n3\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.nrow-Tuple{TSFrame}","page":"API reference","title":"TSFrames.nrow","text":"Size methods\n\nnrow(ts::TSFrame)\nnr(ts::TSFrame)\n\nReturn the number of rows of ts. nr is an alias for nrow.\n\nExamples\n\njulia> ts = TSFrame(collect(1:10))\njulia> TSFrames.nrow(ts)\n10\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.rename!-Tuple{TSFrame, AbstractVector{String}}","page":"API reference","title":"TSFrames.rename!","text":"Column Rename\n\nrename!(ts::TSFrame, colnames::AbstractVector{String}; makeunique::Bool=false)\nrename!(ts::TSFrame, colnames::AbstractVector{Symbol}; makeunique::Bool=false)\nrename!(ts::TSFrame, (from => to)::Pair...)\nrename!(ts::TSFrame, d::AbstractDict)\nrename!(ts::TSFrame, d::AbstractVector{<:Pair})\nrename!(f::Function, ts::TSFrame)\n\nRenames columns of ts in-place. The interface is similar to DataFrames.jl's renaming interface.\n\nArguments\n\nts: the TSFrame.\ncolnames: an AbstractVector containing Strings or Symbols. Must be of the same length as the number of non-Index columns in ts, and cannot contain the string \"Index\" or the symbol :Index.\nmakeunique: if false (which is the default), an error will be raised if colnames contains duplicate names. If true, then duplicate names will be suffixed with _i (i starting at 1 for the first duplicate).\nd: an AbstractDict or an AbstractVector of Pairs that maps original names to new names. Cannot map :Index to any other column name.\nf: a function which for each non-Index column takes the old name as a String and returns the new name as a String.\n\nIf pairs are passed to rename! (as positional arguments or as a dictionary or as a vector), then\n\nfrom can be a String or a Symbol.\nto can be a String or a Symbol.\nMixing Strings and Symbols in from and to is not allowed.\n\njulia> ts = TSFrame(DataFrame(Index=Date(2012, 1, 1):Day(1):Date(2012, 1, 10), x1=1:10, x2=11:20))\n10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, [\"X1\", \"X2\"])\n 10×2 TSFrame with Date Index\n Index X1 X2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, [:x1, :x2])\n10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, :x1 => :X1, :x2 => :X2)\n10×2 TSFrame with Date Index\n Index X1 X2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, Dict(\"X1\" => :x1, \"X2\" => :x2))\n 10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename!(ts, [:x1 => \"X1\", :x2 => \"X2\"])\n10×2 TSFrame with Date Index\n Index X1 X2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\njulia> TSFrames.rename(lowercase, ts)\n10×2 TSFrame with Date Index\n Index x1 x2\n Date Int64 Int64\n──────────────────────────\n 2012-01-01 1 11\n 2012-01-02 2 12\n 2012-01-03 3 13\n 2012-01-04 4 14\n 2012-01-05 5 15\n 2012-01-06 6 16\n 2012-01-07 7 17\n 2012-01-08 8 18\n 2012-01-09 9 19\n 2012-01-10 10 20\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.rollapply-Tuple{TSFrame, Function, Int64}","page":"API reference","title":"TSFrames.rollapply","text":"Rolling Functions\n\nrollapply(ts::TSFrame, fun::Function, windowsize::Int; bycolumn=true)\n\nApply function fun to rolling windows of ts. The output is a TSFrame object with (nrow(ts) - windowsize + 1) rows indexed with the last index value of each window.\n\nThe bycolumn argument should be set to true (default) if fun is to be applied to each column separately, and to false if fun takes a whole TSFrame as an input.\n\nExamples\n\njulia> rollapply(TSFrame([1:10 11:20]), mean, 5)\n6×2 TSFrame with Int64 Index\n Index rolling_x1_mean rolling_x2_mean \n Int64 Float64 Float64 \n─────────────────────────────────────────\n 5 3.0 13.0\n 6 4.0 14.0\n 7 5.0 15.0\n 8 6.0 16.0\n 9 7.0 17.0\n 10 8.0 18.0\n\njulia> dates = Date(2001, 1, 1):Day(1):Date(2001, 1, 10);\njulia> df = DataFrame(Index=dates, inrchf=1:10, usdchf=1:10, eurchf=1:10, gbpchf=1:10, jpychf=1:10);\njulia> ts = TSFrame(df)\n10×5 TSFrame with Date Index\n Index inrchf usdchf eurchf gbpchf jpychf \n Date Int64 Int64 Int64 Int64 Int64 \n────────────────────────────────────────────────────\n 2001-01-01 1 1 1 1 1\n 2001-01-02 2 2 2 2 2\n 2001-01-03 3 3 3 3 3\n 2001-01-04 4 4 4 4 4\n 2001-01-05 5 5 5 5 5\n 2001-01-06 6 6 6 6 6\n 2001-01-07 7 7 7 7 7\n 2001-01-08 8 8 8 8 8\n 2001-01-09 9 9 9 9 9\n 2001-01-10 10 10 10 10 10\n\njulia> function regress(ts) # defining function for multiple regressions\n ll = lm(@formula(inrchf ~ usdchf + eurchf + gbpchf + jpychf), ts.coredata[:, Not(:Index)])\n co = coef(ll)[coefnames(ll) .== \"usdchf\"]\n sd = Statistics.std(residuals(ll))\n return (co, sd)\n end\n\njulia> rollapply(ts, regress, 5; bycolumn=false) # doing multiple regressions\n6×1 TSFrame with Date Index\n Index rolling_regress \n Date Tuple… \n──────────────────────────────────\n 2001-01-05 ([1.0], 9.93014e-17)\n 2001-01-06 ([1.0], 1.27168e-15)\n 2001-01-07 ([1.0], 4.86475e-16)\n 2001-01-08 ([1.0], 7.43103e-16)\n 2001-01-09 ([1.0], 7.45753e-15)\n 2001-01-10 ([1.0], 9.28561e-15)\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.subset-Union{Tuple{T}, Tuple{TSFrame, T, T}} where T<:Union{Int64, Dates.TimeType}","page":"API reference","title":"TSFrames.subset","text":"Subsetting based on Index\n\nsubset(ts::TSFrame, from::T, to::T) where {T<:Union{Int, TimeType}}\n\nCreate a subset of ts based on the Index starting from (inclusive) till to (inclusive).\n\nExamples\n\njulia> using Random;\njulia> random(x) = rand(MersenneTwister(123), x);\njulia> dates = Date(\"2022-02-01\"):Week(1):Date(\"2022-02-01\")+Month(9);\njulia> ts = TSFrame(random(length(dates)), dates)\njulia> show(ts)\n(40 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-02-01 0.768448\n 2022-02-08 0.940515\n 2022-02-15 0.673959\n 2022-02-22 0.395453\n 2022-03-01 0.313244\n 2022-03-08 0.662555\n 2022-03-15 0.586022\n 2022-03-22 0.0521332\n 2022-03-29 0.26864\n 2022-04-05 0.108871\n 2022-04-12 0.163666\n 2022-04-19 0.473017\n 2022-04-26 0.865412\n 2022-05-03 0.617492\n 2022-05-10 0.285698\n 2022-05-17 0.463847\n 2022-05-24 0.275819\n 2022-05-31 0.446568\n 2022-06-07 0.582318\n 2022-06-14 0.255981\n 2022-06-21 0.70586\n 2022-06-28 0.291978\n 2022-07-05 0.281066\n 2022-07-12 0.792931\n 2022-07-19 0.20923\n 2022-07-26 0.918165\n 2022-08-02 0.614255\n 2022-08-09 0.802665\n 2022-08-16 0.555668\n 2022-08-23 0.940782\n 2022-08-30 0.48\n 2022-09-06 0.790201\n 2022-09-13 0.356221\n 2022-09-20 0.900925\n 2022-09-27 0.529253\n 2022-10-04 0.031831\n 2022-10-11 0.900681\n 2022-10-18 0.940299\n 2022-10-25 0.621379\n 2022-11-01 0.348173\n\njulia> subset(ts, Date(2022, 03), Date(2022, 07))\n(18 x 1) TSFrame with Date Index\n\n Index x1\n Date Float64\n───────────────────────\n 2022-03-01 0.313244\n 2022-03-08 0.662555\n 2022-03-15 0.586022\n 2022-03-22 0.0521332\n 2022-03-29 0.26864\n 2022-04-05 0.108871\n 2022-04-12 0.163666\n 2022-04-19 0.473017\n 2022-04-26 0.865412\n 2022-05-03 0.617492\n 2022-05-10 0.285698\n 2022-05-17 0.463847\n 2022-05-24 0.275819\n 2022-05-31 0.446568\n 2022-06-07 0.582318\n 2022-06-14 0.255981\n 2022-06-21 0.70586\n 2022-06-28 0.291978\n\njulia> subset(TSFrame(1:20, -9:10), -4, 5)\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Int64\n──────────────\n -4 6\n -3 7\n -2 8\n -1 9\n 0 10\n 1 11\n 2 12\n 3 13\n 4 14\n 5 15\n\njulia> subset(ts,:,Date(\"2022-04-12\"))\n(11 x 1) TSFrame with Date Index\n\n Index x1 \n Date Float64 \n───────────────────────\n 2022-02-01 0.768448\n 2022-02-08 0.940515\n 2022-02-15 0.673959\n 2022-02-22 0.395453\n 2022-03-01 0.313244\n 2022-03-08 0.662555\n 2022-03-15 0.586022\n 2022-03-22 0.0521332\n 2022-03-29 0.26864\n 2022-04-05 0.108871\n 2022-04-12 0.163666\n\njulia> subset(ts,Date(\"2022-9-27\"),:)\n(6 x 1) TSFrame with Date Index\n\n Index x1 \n Date Float64 \n──────────────────────\n 2022-09-27 0.529253\n 2022-10-04 0.031831\n 2022-10-11 0.900681\n 2022-10-18 0.940299\n 2022-10-25 0.621379\n 2022-11-01 0.348173\n\n\n\n\n\n\n\n","category":"method"},{"location":"api/#TSFrames.tail","page":"API reference","title":"TSFrames.tail","text":"Tail\n\ntail(ts::TSFrame, n::Int = 10)\n\nReturns the last n rows of ts.\n\njulia> tail(TSFrame(1:100))\n(10 x 1) TSFrame with Int64 Index\n\n Index x1\n Int64 Int64\n──────────────\n 91 91\n 92 92\n 93 93\n 94 94\n 95 95\n 96 96\n 97 97\n 98 98\n 99 99\n 100 100\n\n\n\n\n\n","category":"function"},{"location":"api/#TSFrames.to_period-Union{Tuple{T}, Tuple{TSFrame, T}} where T<:Dates.Period","page":"API reference","title":"TSFrames.to_period","text":"Frequency conversion\n\nSet of convenience methods for frequency conversion of TimeType index types. Internally, they call endpoints() to do the actual conversion. n is the number of periods of the period type. For example, to_monthly(tsf, 2) will resample the time series to \"every 2 months\".\n\nto_period(tsf::TSFrame, period::T)::TSFrame where {T<:Period}\nto_yearly(tsf::TSFrame, n=1)::TSFrame\nto_quarterly(tsf::TSFrame, n=1)::TSFrame\nto_monthly(tsf::TSFrame, n=1)::TSFrame\nto_weekly(tsf::TSFrame, n=1)::TSFrame\nto_daily(tsf::TSFrame, n=1)::TSFrame\nto_hourly(tsf::TSFrame, n=1)::TSFrame\nto_minutes(tsf::TSFrame, n=1)::TSFrame\nto_seconds(tsf::TSFrame, n=1)::TSFrame\nto_milliseconds(tsf::TSFrame, n=1)::TSFrame\nto_microseconds(tsf::TSFrame, n=1)::TSFrame\nto_nanoseconds(tsf::TSFrame, n=1)::TSFrame\n\n\n\n\n\n","category":"method"},{"location":"user_guide/#User-guide","page":"User guide","title":"User guide","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"This page describes how to use the TSFrames package for timeseries data handling.","category":"page"},{"location":"user_guide/#Installation","page":"User guide","title":"Installation","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using Pkg\njulia> Pkg.add(url=\"https://github.com/xKDR/TSFrames.jl\")","category":"page"},{"location":"user_guide/#Constructing-TSFrame-objects","page":"User guide","title":"Constructing TSFrame objects","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"After installing TSFrames you need to load the package in Julia environment. Then, create a basic TSFrame object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using TSFrames;\nts = TSFrame(1:10)\nts.coredata","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The basic TSFrame constructor takes in a Vector of any type and automatically generates an index out of it (the Index column).","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"There are many ways to construct a TSFrame object. For real world applications you would want to read in a CSV file or download a dataset as a DataFrame and then operate on it. You can easily convert a DataFrame to a TSFrame object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using CSV, DataFrames, TSFrames, Dates\ndates = Date(2007, 1, 1):Day(1):Date(2008, 03, 06)\nts = TSFrame(DataFrame(Index=dates, value=10*rand(431)))","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"In the above example you generate a random DataFrame and convert it into a TSFrame object ts. The top line of the ts object tells you the number of rows (431 here) and the number of columns (1) along with the Type of Index (Dates.Date in the above example).","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"You can also fetch the number of rows and columns by using nr(ts), nc(ts), and size(ts) methods. Respectively, they fetch the number of rows, columns, and a Tuple of row and column numbers. A length(::TSFrame) method is also provided for convenience which returns the number of rows of it's argument.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"nr(ts)\nnc(ts)\nsize(ts)\nlength(ts)","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Names of data columns can be fetched using the names(ts) method which returns a Vector{String} object. The Index column can be fetched as an object of Vector type by using the index(ts) method, it can also be fetched directly using the underlying coredata property of TSFrame: ts.coredata[!, :Index].","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"names(ts)\nindex(ts)","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Another simpler way to read a CSV is to pass TSFrame as a sink to the CSV.read function.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> ts = CSV.File(filename, TSFrame)","category":"page"},{"location":"user_guide/#Indexing-and-subsetting","page":"User guide","title":"Indexing and subsetting","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"One of the primary features of a timeseries package is to provide ways to index or subset a dataset using convenient interfaces. TSFrames makes it easier to index a TSFrame object by providing multiple intuitive getindex methods which work by just using the regular square parentheses([ ]).","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts[1] # first row\nts[[3, 5], [1]] # third & fifth row, and first column\nts[1:10, 1] # first 10 rows and the first column as a vector\nts[1, [:value]] # using the column name","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Apart from integer-based row indexing and integer, name based column indexing, TSFrames provides special subsetting methods for date and time types defined inside the Dates module.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts[Date(2007, 1, 10)] # on January 10, 2007\nts[[Date(2007, 1, 10), Date(2007, 1, 11)]] # January 10, 11\nts[Year(2007), Month(1)] # entire January 2007\nts[Year(2007), Quarter(2)]","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Finally, one can also use the dot notation to get a column as a vector.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts.value # get the value column as a vector","category":"page"},{"location":"user_guide/#Summary-statistics","page":"User guide","title":"Summary statistics","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The describe() method prints summary statistics of the TSFrame object. The output is a DataFrame which includes the number of missing values, data types of columns along with computed statistical values.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"TSFrames.describe(ts)","category":"page"},{"location":"user_guide/#Plotting","page":"User guide","title":"Plotting","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"A TSFrame object can be plotted using the plot() function of the Plots package. The plotting functionality is provided by RecipesBase package so all the flexibility and functionality of the Plots package is available for users.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using Plots\nplot(ts, size=(600,400); legend=false)","category":"page"},{"location":"user_guide/#Applying-a-function-over-a-period","page":"User guide","title":"Applying a function over a period","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The apply method allows you to aggregate the TSFrame object over a period type (Dates.Period(@ref)) and return the output of applying the function on each period. For example, to convert frequency of daily timeseries to monthly you may use first(), last(), or Statistics.mean() functions and the period as Dates.Month.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"using Statistics\nts_monthly = apply(ts, Month(1), last) # convert to monthly series using the last value for each month\nts_weekly = apply(ts, Week(1), Statistics.std) # compute weekly standard deviation\napply(ts, Week(1), Statistics.std, last) # same as above but index contains the last date of the week\napply(ts, Week(1), Statistics.std, last, renamecols=false) # do not rename column","category":"page"},{"location":"user_guide/#Joins:-Row-and-column-binding-with-other-objects","page":"User guide","title":"Joins: Row and column binding with other objects","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"TSFrames provides methods to join two TSFrame objects by columns: join (alias: cbind) or by rows: vcat (alias: rbind). Both the methods provide some basic intelligence while doing the merge.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"join merges two datasets based on the Index values of both objects. Depending on the join strategy employed the final object may only contain index values only from the left object (using jointype=:JoinLeft), the right object (using jointype=:JoinRight), intersection of both objects (using jointype=:JoinBoth), or a union of both objects (jointype=:JoinAll) while inserting missing values where index values are missing from any of the other object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"dates = collect(Date(2007,1,1):Day(1):Date(2007,1,30));\nts2 = TSFrame(rand(length(dates)), dates)\njoin(ts, ts2; jointype=:JoinAll) # cbind/join on Index column","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"vcat also works similarly but merges two datasets by rows. This method also uses certain strategies provided via colmerge argument to check for certain conditions before doing the merge, throwing an error if the conditions are not satisfied.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"colmerge can be passed setequal which merges only if both objects have same column names, orderequal which merges only if both objects have same column names and columns are in the same order, intersect merges only the columns which are common to both objects, and union which merges even if the columns differ between the two objects, the resulting object has the columns filled with missing, if necessary.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"For vcat, if the values of Index are same in the two objects then all the index values along with values in other columns are kept in the resulting object. So, a vcat operation may result in duplicate Index values and the results from other operations may differ or even throw unknown errors.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"dates = collect(Date(2008,4,1):Day(1):Date(2008,4,30));\nts3 = TSFrame(DataFrame(values=rand(length(dates)), Index=dates))\nvcat(ts, ts3) # do the merge","category":"page"},{"location":"user_guide/#Rolling-window-operations","page":"User guide","title":"Rolling window operations","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"The rollapply applies a function over a fixed-size rolling window on the dataset. In the example below, we compute the 10-day average of dataset values on a rolling basis.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"rollapply(ts, mean, 10)","category":"page"},{"location":"user_guide/#Computing-rolling-difference-and-percent-change","page":"User guide","title":"Computing rolling difference and percent change","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Similar to apply and rollapply there are specific methods to compute rolling differences and percent changes of a TSFrame object. The diff method computes mathematical difference of values in adjacent rows, inserting missing in the first row. pctchange computes the percentage change between adjacent rows.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"diff(ts)\npctchange(ts)","category":"page"},{"location":"user_guide/#Computing-log-of-data-values","page":"User guide","title":"Computing log of data values","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"log.(ts)","category":"page"},{"location":"user_guide/#Creating-lagged/leading-series","page":"User guide","title":"Creating lagged/leading series","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"lag() and lead() provide ways to lag or lead a series respectively by a fixed value, inserting missing where required.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"lag(ts, 2)\nlead(ts, 2)","category":"page"},{"location":"user_guide/#Converting-to-Matrix-and-DataFrame","page":"User guide","title":"Converting to Matrix and DataFrame","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"You can easily convert a TSFrame object into a Matrix or fetch the DataFrame for doing operations which are outside of the TSFrames scope.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"ts[:, 1] # convert column 1 to a vector of floats\nMatrix(ts) # convert entire TSFrame into a Matrix\nselect(ts.coredata, :Index, :value, DataFrames.nrow) # use the underlying DataFrame for other operations","category":"page"},{"location":"user_guide/#Writing-TSFrame-into-a-CSV-file","page":"User guide","title":"Writing TSFrame into a CSV file","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Writing a TSFrame object into a CSV file can be done easily by using the underlying coredata property. This DataFrame can be passed to the CSV.write method for writing into a file.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"CSV.write(\"/tmp/demo_ts.csv\", ts)","category":"page"},{"location":"user_guide/#Broadcasting","page":"User guide","title":"Broadcasting","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Broadcasting can be used on a TSFrame object to apply a function to a subset of it's columns.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using TSFrames, DataFrames;\n\njulia> ts = TSFrame(DataFrame(Index = [1, 2, 3, 4, 5], A = [10.1, 12.4, 42.4, 24.1, 242.5], B = [2, 4, 6, 8, 10]))\n(5 x 2) TSFrame with Int64 Index\n\n Index A B \n Int64 Float64 Int64 \n───────────────────────\n 1 10.1 2\n 2 12.4 4\n 3 42.4 6\n 4 24.1 8\n 5 242.5 10\n\njulia> sin_A = sin.(ts[:, [:A]]) # get sin of column A\n(5 x 1) TSFrame with Int64 Index\n\n Index A_sin\n Int64 Float64\n──────────────────\n 1 -0.625071\n 2 -0.165604\n 3 -0.999934\n 4 -0.858707\n 5 -0.562466\n\njulia> log_ts = log.(ts) # take log of all columns\n(5 x 2) TSFrame with Int64 Index\n\n Index A_log B_log\n Int64 Float64 Float64\n──────────────────────────\n 1 2.31254 0.693147\n 2 2.5177 1.38629\n 3 3.74715 1.79176\n 4 3.18221 2.07944\n 5 5.491 2.30259\n\njulia> log_ts = log.(ts[:, [:A, :B]]) # can specify multiple columns\n(5 x 2) TSFrame with Int64 Index\n\n Index A_log B_log\n Int64 Float64 Float64\n──────────────────────────\n 1 2.31254 0.693147\n 2 2.5177 1.38629\n 3 3.74715 1.79176\n 4 3.18221 2.07944\n 5 5.491 2.30259\n","category":"page"},{"location":"user_guide/#[Tables.jl](https://github.com/JuliaData/Tables.jl)-Integration","page":"User guide","title":"Tables.jl Integration","text":"","category":"section"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"TSFrame objects are Tables.jl compatible. This integration enables easy conversion between the TSFrame format and other formats which are Tables.jl compatible.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"As an example, first consider the following code which converts a TSFrame object into a DataFrame, a TimeArray and a CSV file respectively.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using TSFrames, TimeSeries, Dates, DataFrames, CSV;\n\njulia> dates = Date(2018, 1, 1):Day(1):Date(2018, 12, 31)\nDate(\"2018-01-01\"):Day(1):Date(\"2018-12-31\")\n\njulia> ts = TSFrame(DataFrame(Index = dates, x1 = 1:365));\n\n# conversion to DataFrames\njulia> df = DataFrame(ts);\n\n# conversion to TimeArray\njulia> timeArray = TimeArray(ts, timestamp = :Index);\n\n# writing to CSV\njulia> CSV.write(\"ts.csv\", ts);\n","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"Next, here is some code which converts a DataFrame, a TimeArray and a CSV file to a TSFrame object.","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"julia> using TSFrames, DataFrames, CSV, TimeSeries, Dates;\n\n# converting DataFrame to TSFrame\njulia> ts = TSFrame(DataFrame(Index=1:10, x1=1:10));\n\n# converting from TimeArray to TSFrame\njulia> dates = Date(2018, 1, 1):Day(1):Date(2018, 12, 31)\nDate(\"2018-01-01\"):Day(1):Date(\"2018-12-31\")\n\njulia> ta = TimeArray(dates, rand(length(dates)));\n\njulia> ts = TSFrame(ta);\n\n# converting from CSV to TSFrame\njulia> CSV.read(\"ts.csv\", TSFrame);","category":"page"},{"location":"user_guide/","page":"User guide","title":"User guide","text":"note: Note\nThis discussion warrants a note about how we've implemented the Tables.jl interfaces. Since TSFrame objects are nothing but a wrapper around a DataFrame, our implementations of these interfaces just call DataFrames.jl's implementations. Moreover, while constructing TSFrame objects out of other Tables.jl compatible types, our constructor first converts the input table to a DataFrame, and then converts the DataFrame to a TSFrame object.","category":"page"},{"location":"demo_finance/#Basic-demo-of-TSFrames-using-financial-data","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames using financial data","text":"","category":"section"},{"location":"demo_finance/#Create-a-TSFrame-object-for-IBM-historical-data","page":"Basic demo of TSFrames","title":"Create a TSFrame object for IBM historical data","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"To load the IBM historical data, we will use the MarketData.yahoo function from MarketData.jl, which returns the data in the form of a TimeArray. We just simply pass this on to the TSFrame constructor.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"using TSFrames, MarketData, Plots, Statistics, Impute\nibm_ts = TSFrame(MarketData.yahoo(:IBM))","category":"page"},{"location":"demo_finance/#Create-TSFrame-object-for-AAPL","page":"Basic demo of TSFrames","title":"Create TSFrame object for AAPL","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Similarly, we can create a TSFrame object for the AAPL data.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"aapl_ts = TSFrame(MarketData.yahoo(:AAPL))","category":"page"},{"location":"demo_finance/#Create-a-6-month-subset-of-stock-data","page":"Basic demo of TSFrames","title":"Create a 6-month subset of stock data","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"We would like to compare the stock returns for both the stocks for 6 months starting from June 1, 2021 till December 31, 2021. We use TSFrames.subset method to create new objects which contain the specified duration of data.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"date_from = Date(2021, 06, 01);\ndate_to = Date(2021, 12, 31);\n\nibm = TSFrames.subset(ibm_ts, date_from, date_to)","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"aapl = TSFrames.subset(aapl_ts, date_from, date_to)","category":"page"},{"location":"demo_finance/#Combine-adjusted-closing-prices-of-both-stocks-into-one-object","page":"Basic demo of TSFrames","title":"Combine adjusted closing prices of both stocks into one object","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"We now join (cbind) both the stocks' data into a single object for further analysis. We use TSFrames.join to create two columns containing adjusted closing prices of both the stocks. The join happens by comparing the Index values (dates) of the two objects. The resulting object contains two columns with exactly the same dates for which both the objects have data, all the other rows are omitted from the result.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl = TSFrames.join(ibm[:, [\"AdjClose\"]], aapl[:, [\"AdjClose\"]]; jointype=:JoinBoth)\nTSFrames.rename!(ibm_aapl, [:IBM, :AAPL])","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"After the join operation the column names are modified because we merged two same-named columns (AdjClose) so we use TSFrames.rename!() method to rename the columns to easily remembered stock names.","category":"page"},{"location":"demo_finance/#Fill-missing-values","page":"Basic demo of TSFrames","title":"Fill missing values","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl = ibm_aapl |> Impute.locf()","category":"page"},{"location":"demo_finance/#Convert-data-into-weekly-frequency-using-last-values","page":"Basic demo of TSFrames","title":"Convert data into weekly frequency using last values","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Here, we convert daily stock data into weekly frequency by taking the value with which the trading closed on the last day of the week as the week's price.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl_weekly = to_weekly(ibm_aapl)","category":"page"},{"location":"demo_finance/#Compute-weekly-returns-using-the-familiar-log-and-diff-functions","page":"Basic demo of TSFrames","title":"Compute weekly returns using the familiar log and diff functions","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_aapl_weekly_returns = diff(log.(ibm_aapl_weekly))\nTSFrames.rename!(ibm_aapl_weekly_returns, [:IBM, :AAPL])","category":"page"},{"location":"demo_finance/#Compute-standard-deviation-of-weekly-returns","page":"Basic demo of TSFrames","title":"Compute standard deviation of weekly returns","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Computing standard deviation is done using the std function from Statistics package. The skipmissing is used to skip missing values which may have been generated while computing log returns or were already present in the data.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ibm_std = std(skipmissing(ibm_aapl_weekly_returns[:, :IBM]))","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"aapl_std = std(skipmissing(ibm_aapl_weekly_returns[:, :AAPL]))","category":"page"},{"location":"demo_finance/#Scatter-plot-of-AAPL-and-IBM","page":"Basic demo of TSFrames","title":"Scatter plot of AAPL and IBM","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Here, we use the Plots package to create a scatter plot with IBM weekly returns on the x-axis and Apple weekly returns on the y-axis.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"ENV[\"GKSwstype\"] = \"100\" # hide\nplot(ibm_aapl_weekly_returns[:, :AAPL],\n ibm_aapl_weekly_returns[:, :IBM],\n seriestype = :scatter;\n xlabel = \"AAPL\",\n ylabel = \"IBM\",\n legend = false)\nsavefig(\"ts-plot.svg\"); nothing # hide","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"(Image: )","category":"page"},{"location":"demo_finance/#Aggregation-and-rolling-window-operations","page":"Basic demo of TSFrames","title":"Aggregation and rolling window operations","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"Here, we compute realised volatility of returns of both IBM and Apple stock weekly and bi-monthly. Then, we compute daily returns volatility on a rolling basis with a window size of 10.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"daily_returns = diff(log.(ibm_aapl))\nrvol = apply(daily_returns, Week(1), std) # Compute the realised volatility\nrvol = apply(daily_returns, Month(2), std) # Every two months\nrollapply(daily_returns, std, 10) # Compute rolling vols","category":"page"},{"location":"demo_finance/#Rolling-regression-with-a-window-of-10","page":"Basic demo of TSFrames","title":"Rolling regression with a window of 10","text":"","category":"section"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"One of the common finance problems is to run a rolling window regression of firm returns over market returns. For doing this, we will use the lm() function from the GLM package. We will create a separate function regress() which would take in the data as an argument and use pre-defined strings to identify the returns columns, pass them to lm(), and return the results.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"We start by downloading the S&P500 daily data from Yahoo Finance, then performing the same steps as above to come to a joined TSFrame object containing daily returns of S&P500 and IBM stock prices. Then, use rollapply() with bycolumn=false to tell rollapply() to pass in the entire TSFrame to the function in one go for each iteration within the window.","category":"page"},{"location":"demo_finance/","page":"Basic demo of TSFrames","title":"Basic demo of TSFrames","text":"sp500 = TSFrame(MarketData.yahoo(\"^GSPC\"));\nsp500_adjclose = TSFrames.subset(sp500, date_from, date_to)[:, [\"AdjClose\"]]\n\nsp500_ibm = join(sp500_adjclose, ibm_adjclose, jointype=:JoinBoth)\nsp500_ibm_returns = diff(log.(sp500_ibm))\nTSFrames.rename!(sp500_ibm_returns, [\"SP500\", \"IBM\"]);\n\nfunction regress(data)\n ll = lm(@formula(IBM ~ SP500), data)\n co::Real = coef(ll)[coefnames(ll) .== \"IBM\"][1]\n sd::Real = Statistics.std(residuals(ll))\n return (co, sd)\nend\n\nrollapply(sp500_ibm_returns, regress, 10, bycolumn=false)","category":"page"},{"location":"#TSFrames.jl","page":"Introduction","title":"TSFrames.jl","text":"","category":"section"},{"location":"","page":"Introduction","title":"Introduction","text":"TSFrames provides a convenient interface for performing standard manipulations of timeseries data. The package uses DataFrame at it's core to allow powerful data manipulation functions while being lightweight. It is inspired by zoo and xts packages from the R world.","category":"page"},{"location":"","page":"Introduction","title":"Introduction","text":"TSFrames wraps a familiar syntax for timeseries operations over DataFrame type, thereby, providing the user with full set of DataFrame functionalities as well. Integrations with other packages in the Julia ecosystem which are supported by DataFrames.jl come to TSFrames at little cost.","category":"page"},{"location":"","page":"Introduction","title":"Introduction","text":"To start using TSFrames.jl take a look at the basic demo and then head to the User guide.","category":"page"},{"location":"#User-guide","page":"Introduction","title":"User guide","text":"","category":"section"},{"location":"","page":"Introduction","title":"Introduction","text":"Pages = [\"user_guide.md\"]","category":"page"},{"location":"#API-reference","page":"Introduction","title":"API reference","text":"","category":"section"},{"location":"","page":"Introduction","title":"Introduction","text":"Pages = [\"api.md\"]","category":"page"}] } diff --git a/dev/ts-plot.svg b/dev/ts-plot.svg index 8f7f3c7..86415a4 100644 --- a/dev/ts-plot.svg +++ b/dev/ts-plot.svg @@ -1,76 +1,76 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/user_guide/index.html b/dev/user_guide/index.html index 87cf9f1..625dd5f 100644 --- a/dev/user_guide/index.html +++ b/dev/user_guide/index.html @@ -29,24 +29,24 @@ 10 │ 10 10

      The basic TSFrame constructor takes in a Vector of any type and automatically generates an index out of it (the Index column).

      There are many ways to construct a TSFrame object. For real world applications you would want to read in a CSV file or download a dataset as a DataFrame and then operate on it. You can easily convert a DataFrame to a TSFrame object.

      julia> using CSV, DataFrames, TSFrames, Dates
      julia> dates = Date(2007, 1, 1):Day(1):Date(2008, 03, 06)Date("2007-01-01"):Dates.Day(1):Date("2008-03-06")
      julia> ts = TSFrame(DataFrame(Index=dates, value=10*rand(431)))431×1 TSFrame with Date Index Index value Date Float64 -────────────────────── - 2007-01-01 0.387048 - 2007-01-02 1.1515 - 2007-01-03 0.828109 - 2007-01-04 4.2478 - 2007-01-05 4.30876 - 2007-01-06 2.93308 - 2007-01-07 6.29236 - 2007-01-08 6.90237 +───────────────────── + 2007-01-01 4.28905 + 2007-01-02 2.1487 + 2007-01-03 2.73592 + 2007-01-04 4.90115 + 2007-01-05 5.86148 + 2007-01-06 9.61217 + 2007-01-07 1.96545 + 2007-01-08 2.43444 ⋮ ⋮ - 2008-02-29 7.89843 - 2008-03-01 2.87578 - 2008-03-02 4.7969 - 2008-03-03 8.40796 - 2008-03-04 3.32234 - 2008-03-05 0.977815 - 2008-03-06 0.491254 - 416 rows omitted

      In the above example you generate a random DataFrame and convert it into a TSFrame object ts. The top line of the ts object tells you the number of rows (431 here) and the number of columns (1) along with the Type of Index (Dates.Date in the above example).

      You can also fetch the number of rows and columns by using nr(ts), nc(ts), and size(ts) methods. Respectively, they fetch the number of rows, columns, and a Tuple of row and column numbers. A length(::TSFrame) method is also provided for convenience which returns the number of rows of it's argument.

      julia> nr(ts)431
      julia> nc(ts)1
      julia> size(ts)(431, 1)
      julia> length(ts)431

      Names of data columns can be fetched using the names(ts) method which returns a Vector{String} object. The Index column can be fetched as an object of Vector type by using the index(ts) method, it can also be fetched directly using the underlying coredata property of TSFrame: ts.coredata[!, :Index].

      julia> names(ts)1-element Vector{String}:
      + 2008-02-29  5.30936
      + 2008-03-01  5.58126
      + 2008-03-02  4.7507
      + 2008-03-03  9.30229
      + 2008-03-04  9.9353
      + 2008-03-05  8.6329
      + 2008-03-06  4.16549
      +     416 rows omitted

      In the above example you generate a random DataFrame and convert it into a TSFrame object ts. The top line of the ts object tells you the number of rows (431 here) and the number of columns (1) along with the Type of Index (Dates.Date in the above example).

      You can also fetch the number of rows and columns by using nr(ts), nc(ts), and size(ts) methods. Respectively, they fetch the number of rows, columns, and a Tuple of row and column numbers. A length(::TSFrame) method is also provided for convenience which returns the number of rows of it's argument.

      julia> nr(ts)431
      julia> nc(ts)1
      julia> size(ts)(431, 1)
      julia> length(ts)431

      Names of data columns can be fetched using the names(ts) method which returns a Vector{String} object. The Index column can be fetched as an object of Vector type by using the index(ts) method, it can also be fetched directly using the underlying coredata property of TSFrame: ts.coredata[!, :Index].

      julia> names(ts)1-element Vector{String}:
        "value"
      julia> index(ts)431-element Vector{Date}: 2007-01-01 2007-01-02 @@ -70,482 +70,482 @@ 2008-03-06

      Another simpler way to read a CSV is to pass TSFrame as a sink to the CSV.read function.

      julia> ts = CSV.File(filename, TSFrame)

      Indexing and subsetting

      One of the primary features of a timeseries package is to provide ways to index or subset a dataset using convenient interfaces. TSFrames makes it easier to index a TSFrame object by providing multiple intuitive getindex methods which work by just using the regular square parentheses([ ]).

      julia> ts[1] # first row1×1 TSFrame with Date Index
        Index       value
        Date        Float64
      -──────────────────────
      - 2007-01-01  0.387048
      julia> ts[[3, 5], [1]] # third & fifth row, and first column2×1 TSFrame with Date Index +───────────────────── + 2007-01-01 4.28905
      julia> ts[[3, 5], [1]] # third & fifth row, and first column2×1 TSFrame with Date Index Index value Date Float64 -────────────────────── - 2007-01-03 0.828109 - 2007-01-05 4.30876
      julia> ts[1:10, 1] # first 10 rows and the first column as a vector10-element Vector{Float64}: - 0.38704751536183024 - 1.1515045758104459 - 0.8281087840899259 - 4.247799934622658 - 4.30876431094682 - 2.933078445718543 - 6.292362889695227 - 6.90236650635533 - 1.967008854162502 - 0.28452437132264863
      julia> ts[1, [:value]] # using the column name1×1 TSFrame with Date Index +───────────────────── + 2007-01-03 2.73592 + 2007-01-05 5.86148
      julia> ts[1:10, 1] # first 10 rows and the first column as a vector10-element Vector{Float64}: + 4.289054004890143 + 2.148704149266687 + 2.7359239151693737 + 4.901154751688761 + 5.861476763705241 + 9.612169059486801 + 1.9654507410542121 + 2.434442514706905 + 8.380551095450157 + 6.027877004961181
      julia> ts[1, [:value]] # using the column name1×1 TSFrame with Date Index Index value Date Float64 -────────────────────── - 2007-01-01 0.387048

      Apart from integer-based row indexing and integer, name based column indexing, TSFrames provides special subsetting methods for date and time types defined inside the Dates module.

      julia> ts[Date(2007, 1, 10)] # on January 10, 20071×1 TSFrame with Date Index
      +─────────────────────
      + 2007-01-01  4.28905

      Apart from integer-based row indexing and integer, name based column indexing, TSFrames provides special subsetting methods for date and time types defined inside the Dates module.

      julia> ts[Date(2007, 1, 10)] # on January 10, 20071×1 TSFrame with Date Index
        Index       value
        Date        Float64
      -──────────────────────
      - 2007-01-10  0.284524
      julia> ts[[Date(2007, 1, 10), Date(2007, 1, 11)]] # January 10, 112×1 TSFrame with Date Index +───────────────────── + 2007-01-10 6.02788
      julia> ts[[Date(2007, 1, 10), Date(2007, 1, 11)]] # January 10, 112×1 TSFrame with Date Index Index value Date Float64 -────────────────────── - 2007-01-10 0.284524 - 2007-01-11 8.65394
      julia> ts[Year(2007), Month(1)] # entire January 200731×1 TSFrame with Date Index +───────────────────── + 2007-01-10 6.02788 + 2007-01-11 1.96305
      julia> ts[Year(2007), Month(1)] # entire January 200731×1 TSFrame with Date Index Index value Date Float64 -─────────────────────── - 2007-01-01 0.387048 - 2007-01-02 1.1515 - 2007-01-03 0.828109 - 2007-01-04 4.2478 - 2007-01-05 4.30876 - 2007-01-06 2.93308 - 2007-01-07 6.29236 - 2007-01-08 6.90237 - ⋮ ⋮ - 2007-01-25 3.59425 - 2007-01-26 1.98903 - 2007-01-27 3.77675 - 2007-01-28 5.18319 - 2007-01-29 3.6839 - 2007-01-30 1.47898 - 2007-01-31 8.58231 - 16 rows omitted
      julia> ts[Year(2007), Quarter(2)]91×1 TSFrame with Date Index +────────────────────── + 2007-01-01 4.28905 + 2007-01-02 2.1487 + 2007-01-03 2.73592 + 2007-01-04 4.90115 + 2007-01-05 5.86148 + 2007-01-06 9.61217 + 2007-01-07 1.96545 + 2007-01-08 2.43444 + ⋮ ⋮ + 2007-01-25 2.18516 + 2007-01-26 4.19235 + 2007-01-27 3.42971 + 2007-01-28 5.42237 + 2007-01-29 0.930674 + 2007-01-30 1.6782 + 2007-01-31 9.52099 + 16 rows omitted
      julia> ts[Year(2007), Quarter(2)]91×1 TSFrame with Date Index Index value Date Float64 -─────────────────────── - 2007-04-01 9.85869 - 2007-04-02 1.07482 - 2007-04-03 9.03223 - 2007-04-04 7.22205 - 2007-04-05 3.37678 - 2007-04-06 3.19926 - 2007-04-07 6.34568 - 2007-04-08 7.0705 - ⋮ ⋮ - 2007-06-24 6.47057 - 2007-06-25 8.98154 - 2007-06-26 6.72291 - 2007-06-27 8.20424 - 2007-06-28 9.79371 - 2007-06-29 8.12382 - 2007-06-30 8.30455 - 76 rows omitted

      Finally, one can also use the dot notation to get a column as a vector.

      julia> ts.value # get the value column as a vector431-element Vector{Float64}:
      - 0.38704751536183024
      - 1.1515045758104459
      - 0.8281087840899259
      - 4.247799934622658
      - 4.30876431094682
      - 2.933078445718543
      - 6.292362889695227
      - 6.90236650635533
      - 1.967008854162502
      - 0.28452437132264863
      +──────────────────────
      + 2007-04-01  8.2524
      + 2007-04-02  0.326308
      + 2007-04-03  7.41107
      + 2007-04-04  7.82958
      + 2007-04-05  5.46465
      + 2007-04-06  3.86121
      + 2007-04-07  7.80143
      + 2007-04-08  0.325905
      +     ⋮          ⋮
      + 2007-06-24  5.14799
      + 2007-06-25  6.79942
      + 2007-06-26  8.49278
      + 2007-06-27  8.53145
      + 2007-06-28  1.98244
      + 2007-06-29  4.8399
      + 2007-06-30  1.32241
      +       76 rows omitted

      Finally, one can also use the dot notation to get a column as a vector.

      julia> ts.value # get the value column as a vector431-element Vector{Float64}:
      + 4.289054004890143
      + 2.148704149266687
      + 2.7359239151693737
      + 4.901154751688761
      + 5.861476763705241
      + 9.612169059486801
      + 1.9654507410542121
      + 2.434442514706905
      + 8.380551095450157
      + 6.027877004961181
        ⋮
      - 5.104877413986378
      - 9.129228844236119
      - 7.89843168083289
      - 2.875775562463223
      - 4.796904761826152
      - 8.40795630570721
      - 3.322340451987503
      - 0.9778154431116803
      - 0.4912539268878202

      Summary statistics

      The describe() method prints summary statistics of the TSFrame object. The output is a DataFrame which includes the number of missing values, data types of columns along with computed statistical values.

      julia> TSFrames.describe(ts)2×7 DataFrame
      + 2.792200737659307
      + 9.914802960351995
      + 5.309356427971582
      + 5.581264871613396
      + 4.750703622715694
      + 9.30229459918937
      + 9.935303268682393
      + 8.63289556041307
      + 4.165493597143481

      Summary statistics

      The describe() method prints summary statistics of the TSFrame object. The output is a DataFrame which includes the number of missing values, data types of columns along with computed statistical values.

      julia> TSFrames.describe(ts)2×7 DataFrame
        Row │ variable  mean     min         median      max         nmissing  eltype ⋯
            │ Symbol    Union…   Any         Any         Any         Int64     DataTy ⋯
       ─────┼──────────────────────────────────────────────────────────────────────────
          1 │ Index              2007-01-01  2007-08-04  2008-03-06         0  Date   ⋯
      -   2 │ value     4.80712  0.00908461  4.64683     9.97729            0  Float6
      +   2 │ value     4.94035  0.0199865   4.7507      9.97062            0  Float6
                                                                       1 column omitted

      Plotting

      A TSFrame object can be plotted using the plot() function of the Plots package. The plotting functionality is provided by RecipesBase package so all the flexibility and functionality of the Plots package is available for users.

      using Plots
       plot(ts, size=(600,400); legend=false)
      - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +

      Applying a function over a period

      The apply method allows you to aggregate the TSFrame object over a period type (Dates.Period(@ref)) and return the output of applying the function on each period. For example, to convert frequency of daily timeseries to monthly you may use first(), last(), or Statistics.mean() functions and the period as Dates.Month.

      julia> using Statistics
      julia> ts_monthly = apply(ts, Month(1), last) # convert to monthly series using the last value for each month15×1 TSFrame with Date Index Index value_last Date Float64 ──────────────────────── - 2007-01-01 8.58231 - 2007-02-01 5.43155 - 2007-03-01 9.72411 - 2007-04-01 5.56651 - 2007-05-01 8.27571 - 2007-06-01 8.30455 - 2007-07-01 7.43596 - 2007-08-01 9.29006 - 2007-09-01 7.34917 - 2007-10-01 8.43661 - 2007-11-01 4.81665 - 2007-12-01 7.29296 - 2008-01-01 5.89334 - 2008-02-01 7.89843 - 2008-03-01 0.491254
      julia> ts_weekly = apply(ts, Week(1), Statistics.std) # compute weekly standard deviation62×1 TSFrame with Date Index + 2007-01-01 9.52099 + 2007-02-01 7.99039 + 2007-03-01 7.07674 + 2007-04-01 4.27142 + 2007-05-01 1.44256 + 2007-06-01 1.32241 + 2007-07-01 1.61055 + 2007-08-01 7.11451 + 2007-09-01 5.99999 + 2007-10-01 0.555168 + 2007-11-01 8.46257 + 2007-12-01 4.02096 + 2008-01-01 3.75185 + 2008-02-01 5.30936 + 2008-03-01 4.16549
      julia> ts_weekly = apply(ts, Week(1), Statistics.std) # compute weekly standard deviation62×1 TSFrame with Date Index Index value_std Date Float64 ─────────────────────── - 2007-01-01 2.19742 - 2007-01-08 2.89555 - 2007-01-15 3.75153 - 2007-01-22 2.36153 - 2007-01-29 2.63724 - 2007-02-05 2.57961 - 2007-02-12 2.26862 - 2007-02-19 2.22174 + 2007-01-01 2.68508 + 2007-01-08 2.36154 + 2007-01-15 2.98439 + 2007-01-22 1.07398 + 2007-01-29 3.51667 + 2007-02-05 1.68453 + 2007-02-12 2.03187 + 2007-02-19 3.45924 ⋮ ⋮ - 2008-01-21 2.28745 - 2008-01-28 2.31048 - 2008-02-04 3.18292 - 2008-02-11 3.02602 - 2008-02-18 2.69851 - 2008-02-25 3.38693 - 2008-03-03 3.62277 + 2008-01-21 1.82973 + 2008-01-28 2.01686 + 2008-02-04 2.72436 + 2008-02-11 2.01639 + 2008-02-18 2.08255 + 2008-02-25 2.34109 + 2008-03-03 2.61693 47 rows omitted
      julia> apply(ts, Week(1), Statistics.std, last) # same as above but index contains the last date of the week62×1 TSFrame with Date Index Index value_std Date Float64 ─────────────────────── - 2007-01-07 2.19742 - 2007-01-14 2.89555 - 2007-01-21 3.75153 - 2007-01-28 2.36153 - 2007-02-04 2.63724 - 2007-02-11 2.57961 - 2007-02-18 2.26862 - 2007-02-25 2.22174 + 2007-01-07 2.68508 + 2007-01-14 2.36154 + 2007-01-21 2.98439 + 2007-01-28 1.07398 + 2007-02-04 3.51667 + 2007-02-11 1.68453 + 2007-02-18 2.03187 + 2007-02-25 3.45924 ⋮ ⋮ - 2008-01-27 2.28745 - 2008-02-03 2.31048 - 2008-02-10 3.18292 - 2008-02-17 3.02602 - 2008-02-24 2.69851 - 2008-03-02 3.38693 - 2008-03-06 3.62277 + 2008-01-27 1.82973 + 2008-02-03 2.01686 + 2008-02-10 2.72436 + 2008-02-17 2.01639 + 2008-02-24 2.08255 + 2008-03-02 2.34109 + 2008-03-06 2.61693 47 rows omitted
      julia> apply(ts, Week(1), Statistics.std, last, renamecols=false) # do not rename column62×1 TSFrame with Date Index Index value Date Float64 ───────────────────── - 2007-01-07 2.19742 - 2007-01-14 2.89555 - 2007-01-21 3.75153 - 2007-01-28 2.36153 - 2007-02-04 2.63724 - 2007-02-11 2.57961 - 2007-02-18 2.26862 - 2007-02-25 2.22174 + 2007-01-07 2.68508 + 2007-01-14 2.36154 + 2007-01-21 2.98439 + 2007-01-28 1.07398 + 2007-02-04 3.51667 + 2007-02-11 1.68453 + 2007-02-18 2.03187 + 2007-02-25 3.45924 ⋮ ⋮ - 2008-01-27 2.28745 - 2008-02-03 2.31048 - 2008-02-10 3.18292 - 2008-02-17 3.02602 - 2008-02-24 2.69851 - 2008-03-02 3.38693 - 2008-03-06 3.62277 + 2008-01-27 1.82973 + 2008-02-03 2.01686 + 2008-02-10 2.72436 + 2008-02-17 2.01639 + 2008-02-24 2.08255 + 2008-03-02 2.34109 + 2008-03-06 2.61693 47 rows omitted

      Joins: Row and column binding with other objects

      TSFrames provides methods to join two TSFrame objects by columns: join (alias: cbind) or by rows: vcat (alias: rbind). Both the methods provide some basic intelligence while doing the merge.

      join merges two datasets based on the Index values of both objects. Depending on the join strategy employed the final object may only contain index values only from the left object (using jointype=:JoinLeft), the right object (using jointype=:JoinRight), intersection of both objects (using jointype=:JoinBoth), or a union of both objects (jointype=:JoinAll) while inserting missing values where index values are missing from any of the other object.

      julia> dates = collect(Date(2007,1,1):Day(1):Date(2007,1,30));
      julia> ts2 = TSFrame(rand(length(dates)), dates)30×1 TSFrame with Date Index Index x1 Date Float64 ─────────────────────── - 2007-01-01 0.163387 - 2007-01-02 0.912665 - 2007-01-03 0.387569 - 2007-01-04 0.956656 - 2007-01-05 0.553296 - 2007-01-06 0.352498 - 2007-01-07 0.400976 - 2007-01-08 0.337264 + 2007-01-01 0.552759 + 2007-01-02 0.0292577 + 2007-01-03 0.376239 + 2007-01-04 0.119494 + 2007-01-05 0.919888 + 2007-01-06 0.863203 + 2007-01-07 0.640466 + 2007-01-08 0.88285 ⋮ ⋮ - 2007-01-24 0.498155 - 2007-01-25 0.897508 - 2007-01-26 0.9823 - 2007-01-27 0.137462 - 2007-01-28 0.515626 - 2007-01-29 0.9231 - 2007-01-30 0.974959 + 2007-01-24 0.75816 + 2007-01-25 0.853749 + 2007-01-26 0.286011 + 2007-01-27 0.723937 + 2007-01-28 0.0402087 + 2007-01-29 0.86868 + 2007-01-30 0.155191 15 rows omitted
      julia> join(ts, ts2; jointype=:JoinAll) # cbind/join on Index column431×2 TSFrame with Date Index Index value x1 Date Float64? Float64? ─────────────────────────────────────── - 2007-01-01 0.387048 0.163387 - 2007-01-02 1.1515 0.912665 - 2007-01-03 0.828109 0.387569 - 2007-01-04 4.2478 0.956656 - 2007-01-05 4.30876 0.553296 - 2007-01-06 2.93308 0.352498 - 2007-01-07 6.29236 0.400976 - 2007-01-08 6.90237 0.337264 + 2007-01-01 4.28905 0.552759 + 2007-01-02 2.1487 0.0292577 + 2007-01-03 2.73592 0.376239 + 2007-01-04 4.90115 0.119494 + 2007-01-05 5.86148 0.919888 + 2007-01-06 9.61217 0.863203 + 2007-01-07 1.96545 0.640466 + 2007-01-08 2.43444 0.88285 ⋮ ⋮ ⋮ - 2008-02-29 7.89843 missing - 2008-03-01 2.87578 missing - 2008-03-02 4.7969 missing - 2008-03-03 8.40796 missing - 2008-03-04 3.32234 missing - 2008-03-05 0.977815 missing - 2008-03-06 0.491254 missing + 2008-02-29 5.30936 missing + 2008-03-01 5.58126 missing + 2008-03-02 4.7507 missing + 2008-03-03 9.30229 missing + 2008-03-04 9.9353 missing + 2008-03-05 8.6329 missing + 2008-03-06 4.16549 missing 416 rows omitted

      vcat also works similarly but merges two datasets by rows. This method also uses certain strategies provided via colmerge argument to check for certain conditions before doing the merge, throwing an error if the conditions are not satisfied.

      colmerge can be passed setequal which merges only if both objects have same column names, orderequal which merges only if both objects have same column names and columns are in the same order, intersect merges only the columns which are common to both objects, and union which merges even if the columns differ between the two objects, the resulting object has the columns filled with missing, if necessary.

      For vcat, if the values of Index are same in the two objects then all the index values along with values in other columns are kept in the resulting object. So, a vcat operation may result in duplicate Index values and the results from other operations may differ or even throw unknown errors.

      julia> dates = collect(Date(2008,4,1):Day(1):Date(2008,4,30));
      julia> ts3 = TSFrame(DataFrame(values=rand(length(dates)), Index=dates))30×1 TSFrame with Date Index Index values Date Float64 -─────────────────────── - 2008-04-01 0.264262 - 2008-04-02 0.799757 - 2008-04-03 0.228485 - 2008-04-04 0.536086 - 2008-04-05 0.896222 - 2008-04-06 0.941203 - 2008-04-07 0.893276 - 2008-04-08 0.151341 - ⋮ ⋮ - 2008-04-24 0.849827 - 2008-04-25 0.799659 - 2008-04-26 0.103818 - 2008-04-27 0.0153157 - 2008-04-28 0.0130436 - 2008-04-29 0.328759 - 2008-04-30 0.859211 - 15 rows omitted
      julia> vcat(ts, ts3) # do the merge461×2 TSFrame with Date Index - Index value values - Date Float64? Float64? -───────────────────────────────────────────── - 2007-01-01 0.387048 missing - 2007-01-02 1.1515 missing - 2007-01-03 0.828109 missing - 2007-01-04 4.2478 missing - 2007-01-05 4.30876 missing - 2007-01-06 2.93308 missing - 2007-01-07 6.29236 missing - 2007-01-08 6.90237 missing - ⋮ ⋮ ⋮ - 2008-04-24 missing 0.849827 - 2008-04-25 missing 0.799659 - 2008-04-26 missing 0.103818 - 2008-04-27 missing 0.0153157 - 2008-04-28 missing 0.0130436 - 2008-04-29 missing 0.328759 - 2008-04-30 missing 0.859211 - 446 rows omitted

      Rolling window operations

      The rollapply applies a function over a fixed-size rolling window on the dataset. In the example below, we compute the 10-day average of dataset values on a rolling basis.

      julia> rollapply(ts, mean, 10)422×1 TSFrame with Date Index
      +──────────────────────
      + 2008-04-01  0.491721
      + 2008-04-02  0.118138
      + 2008-04-03  0.614601
      + 2008-04-04  0.845782
      + 2008-04-05  0.894973
      + 2008-04-06  0.479697
      + 2008-04-07  0.443616
      + 2008-04-08  0.158663
      +     ⋮          ⋮
      + 2008-04-24  0.485124
      + 2008-04-25  0.342467
      + 2008-04-26  0.541551
      + 2008-04-27  0.835594
      + 2008-04-28  0.32806
      + 2008-04-29  0.259714
      + 2008-04-30  0.883782
      +       15 rows omitted
      julia> vcat(ts, ts3) # do the merge461×2 TSFrame with Date Index + Index value values + Date Float64? Float64? +─────────────────────────────────────────── + 2007-01-01 4.28905 missing + 2007-01-02 2.1487 missing + 2007-01-03 2.73592 missing + 2007-01-04 4.90115 missing + 2007-01-05 5.86148 missing + 2007-01-06 9.61217 missing + 2007-01-07 1.96545 missing + 2007-01-08 2.43444 missing + ⋮ ⋮ ⋮ + 2008-04-24 missing 0.485124 + 2008-04-25 missing 0.342467 + 2008-04-26 missing 0.541551 + 2008-04-27 missing 0.835594 + 2008-04-28 missing 0.32806 + 2008-04-29 missing 0.259714 + 2008-04-30 missing 0.883782 + 446 rows omitted

      Rolling window operations

      The rollapply applies a function over a fixed-size rolling window on the dataset. In the example below, we compute the 10-day average of dataset values on a rolling basis.

      julia> rollapply(ts, mean, 10)422×1 TSFrame with Date Index
        Index       rolling_value_mean
        Date        Float64
       ────────────────────────────────
      - 2007-01-10             2.93026
      - 2007-01-11             3.75695
      - 2007-01-12             4.11437
      - 2007-01-13             4.43992
      - 2007-01-14             4.64245
      - 2007-01-15             4.60143
      - 2007-01-16             5.25857
      - 2007-01-17             4.76573
      + 2007-01-10             4.83568
      + 2007-01-11             4.60308
      + 2007-01-12             4.59771
      + 2007-01-13             4.71258
      + 2007-01-14             4.65091
      + 2007-01-15             4.98152
      + 2007-01-16             4.15141
      + 2007-01-17             4.50707
            ⋮               ⋮
      - 2008-02-29             4.54785
      - 2008-03-01             4.63275
      - 2008-03-02             4.51709
      - 2008-03-03             5.17973
      - 2008-03-04             5.49709
      - 2008-03-05             5.26184
      - 2008-03-06             5.26533
      + 2008-02-29             5.85162
      + 2008-03-01             5.47149
      + 2008-03-02             5.10098
      + 2008-03-03             5.40324
      + 2008-03-04             5.95907
      + 2008-03-05             6.40054
      + 2008-03-06             6.35382
                       407 rows omitted

      Computing rolling difference and percent change

      Similar to apply and rollapply there are specific methods to compute rolling differences and percent changes of a TSFrame object. The diff method computes mathematical difference of values in adjacent rows, inserting missing in the first row. pctchange computes the percentage change between adjacent rows.

      julia> diff(ts)431×1 TSFrame with Date Index
        Index       value
        Date        Float64?
      -─────────────────────────────
      +────────────────────────────
        2007-01-01  missing
      - 2007-01-02        0.764457
      - 2007-01-03       -0.323396
      - 2007-01-04        3.41969
      - 2007-01-05        0.0609644
      - 2007-01-06       -1.37569
      - 2007-01-07        3.35928
      - 2007-01-08        0.610004
      -     ⋮              ⋮
      - 2008-02-29       -1.2308
      - 2008-03-01       -5.02266
      - 2008-03-02        1.92113
      - 2008-03-03        3.61105
      - 2008-03-04       -5.08562
      - 2008-03-05       -2.34453
      - 2008-03-06       -0.486562
      -             416 rows omitted
      julia> pctchange(ts)431×1 TSFrame with Date Index + 2007-01-02 -2.14035 + 2007-01-03 0.58722 + 2007-01-04 2.16523 + 2007-01-05 0.960322 + 2007-01-06 3.75069 + 2007-01-07 -7.64672 + 2007-01-08 0.468992 + ⋮ ⋮ + 2008-02-29 -4.60545 + 2008-03-01 0.271908 + 2008-03-02 -0.830561 + 2008-03-03 4.55159 + 2008-03-04 0.633009 + 2008-03-05 -1.30241 + 2008-03-06 -4.4674 + 416 rows omitted
      julia> pctchange(ts)431×1 TSFrame with Date Index Index value Date Float64? ───────────────────────────── 2007-01-01 missing - 2007-01-02 1.9751 - 2007-01-03 -0.280846 - 2007-01-04 4.12952 - 2007-01-05 0.014352 - 2007-01-06 -0.319276 - 2007-01-07 1.14531 - 2007-01-08 0.0969435 + 2007-01-02 -0.499026 + 2007-01-03 0.27329 + 2007-01-04 0.791408 + 2007-01-05 0.195938 + 2007-01-06 0.639889 + 2007-01-07 -0.795525 + 2007-01-08 0.238618 ⋮ ⋮ - 2008-02-29 -0.134819 - 2008-03-01 -0.635905 - 2008-03-02 0.668039 - 2008-03-03 0.752788 - 2008-03-04 -0.604858 - 2008-03-05 -0.705685 - 2008-03-06 -0.497601 + 2008-02-29 -0.464502 + 2008-03-01 0.0512131 + 2008-03-02 -0.148812 + 2008-03-03 0.958088 + 2008-03-04 0.0680487 + 2008-03-05 -0.131089 + 2008-03-06 -0.517486 416 rows omitted

      Computing log of data values

      julia> log.(ts)431×1 TSFrame with Date Index
        Index       value_log
        Date        Float64
      -────────────────────────
      - 2007-01-01  -0.949208
      - 2007-01-02   0.141069
      - 2007-01-03  -0.188611
      - 2007-01-04   1.4464
      - 2007-01-05   1.46065
      - 2007-01-06   1.07605
      - 2007-01-07   1.83934
      - 2007-01-08   1.93186
      +───────────────────────
      + 2007-01-01   1.45607
      + 2007-01-02   0.764865
      + 2007-01-03   1.00647
      + 2007-01-04   1.58947
      + 2007-01-05   1.7684
      + 2007-01-06   2.26303
      + 2007-01-07   0.675722
      + 2007-01-08   0.889718
            ⋮           ⋮
      - 2008-02-29   2.06666
      - 2008-03-01   1.05632
      - 2008-03-02   1.56797
      - 2008-03-03   2.12918
      - 2008-03-04   1.20067
      - 2008-03-05  -0.0224343
      - 2008-03-06  -0.710794
      -        416 rows omitted

      Creating lagged/leading series

      lag() and lead() provide ways to lag or lead a series respectively by a fixed value, inserting missing where required.

      julia> lag(ts, 2)431×1 TSFrame with Date Index
      + 2008-02-29   1.66947
      + 2008-03-01   1.71942
      + 2008-03-02   1.55829
      + 2008-03-03   2.23026
      + 2008-03-04   2.29609
      + 2008-03-05   2.15558
      + 2008-03-06   1.42683
      +       416 rows omitted

      Creating lagged/leading series

      lag() and lead() provide ways to lag or lead a series respectively by a fixed value, inserting missing where required.

      julia> lag(ts, 2)431×1 TSFrame with Date Index
        Index       value
        Date        Float64?
      -────────────────────────────
      +───────────────────────────
        2007-01-01  missing
        2007-01-02  missing
      - 2007-01-03        0.387048
      - 2007-01-04        1.1515
      - 2007-01-05        0.828109
      - 2007-01-06        4.2478
      - 2007-01-07        4.30876
      - 2007-01-08        2.93308
      + 2007-01-03        4.28905
      + 2007-01-04        2.1487
      + 2007-01-05        2.73592
      + 2007-01-06        4.90115
      + 2007-01-07        5.86148
      + 2007-01-08        9.61217
            ⋮             ⋮
      - 2008-02-29        5.10488
      - 2008-03-01        9.12923
      - 2008-03-02        7.89843
      - 2008-03-03        2.87578
      - 2008-03-04        4.7969
      - 2008-03-05        8.40796
      - 2008-03-06        3.32234
      -            416 rows omitted
      julia> lead(ts, 2)431×1 TSFrame with Date Index + 2008-02-29 2.7922 + 2008-03-01 9.9148 + 2008-03-02 5.30936 + 2008-03-03 5.58126 + 2008-03-04 4.7507 + 2008-03-05 9.30229 + 2008-03-06 9.9353 + 416 rows omitted
      julia> lead(ts, 2)431×1 TSFrame with Date Index Index value Date Float64? -──────────────────────────── - 2007-01-01 0.828109 - 2007-01-02 4.2478 - 2007-01-03 4.30876 - 2007-01-04 2.93308 - 2007-01-05 6.29236 - 2007-01-06 6.90237 - 2007-01-07 1.96701 - 2007-01-08 0.284524 +─────────────────────────── + 2007-01-01 2.73592 + 2007-01-02 4.90115 + 2007-01-03 5.86148 + 2007-01-04 9.61217 + 2007-01-05 1.96545 + 2007-01-06 2.43444 + 2007-01-07 8.38055 + 2007-01-08 6.02788 ⋮ ⋮ - 2008-02-29 4.7969 - 2008-03-01 8.40796 - 2008-03-02 3.32234 - 2008-03-03 0.977815 - 2008-03-04 0.491254 + 2008-02-29 4.7507 + 2008-03-01 9.30229 + 2008-03-02 9.9353 + 2008-03-03 8.6329 + 2008-03-04 4.16549 2008-03-05 missing 2008-03-06 missing - 416 rows omitted

      Converting to Matrix and DataFrame

      You can easily convert a TSFrame object into a Matrix or fetch the DataFrame for doing operations which are outside of the TSFrames scope.

      julia> ts[:, 1] # convert column 1 to a vector of floats431-element Vector{Float64}:
      - 0.38704751536183024
      - 1.1515045758104459
      - 0.8281087840899259
      - 4.247799934622658
      - 4.30876431094682
      - 2.933078445718543
      - 6.292362889695227
      - 6.90236650635533
      - 1.967008854162502
      - 0.28452437132264863
      +           416 rows omitted

      Converting to Matrix and DataFrame

      You can easily convert a TSFrame object into a Matrix or fetch the DataFrame for doing operations which are outside of the TSFrames scope.

      julia> ts[:, 1] # convert column 1 to a vector of floats431-element Vector{Float64}:
      + 4.289054004890143
      + 2.148704149266687
      + 2.7359239151693737
      + 4.901154751688761
      + 5.861476763705241
      + 9.612169059486801
      + 1.9654507410542121
      + 2.434442514706905
      + 8.380551095450157
      + 6.027877004961181
        ⋮
      - 5.104877413986378
      - 9.129228844236119
      - 7.89843168083289
      - 2.875775562463223
      - 4.796904761826152
      - 8.40795630570721
      - 3.322340451987503
      - 0.9778154431116803
      - 0.4912539268878202
      julia> Matrix(ts) # convert entire TSFrame into a Matrix431×1 Matrix{Float64}: - 0.38704751536183024 - 1.1515045758104459 - 0.8281087840899259 - 4.247799934622658 - 4.30876431094682 - 2.933078445718543 - 6.292362889695227 - 6.90236650635533 - 1.967008854162502 - 0.28452437132264863 + 2.792200737659307 + 9.914802960351995 + 5.309356427971582 + 5.581264871613396 + 4.750703622715694 + 9.30229459918937 + 9.935303268682393 + 8.63289556041307 + 4.165493597143481
      julia> Matrix(ts) # convert entire TSFrame into a Matrix431×1 Matrix{Float64}: + 4.289054004890143 + 2.148704149266687 + 2.7359239151693737 + 4.901154751688761 + 5.861476763705241 + 9.612169059486801 + 1.9654507410542121 + 2.434442514706905 + 8.380551095450157 + 6.027877004961181 ⋮ - 5.104877413986378 - 9.129228844236119 - 7.89843168083289 - 2.875775562463223 - 4.796904761826152 - 8.40795630570721 - 3.322340451987503 - 0.9778154431116803 - 0.4912539268878202
      julia> select(ts.coredata, :Index, :value, DataFrames.nrow) # use the underlying DataFrame for other operations431×3 DataFrame - Row │ Index value nrow - │ Date Float64 Int64 -─────┼───────────────────────────── - 1 │ 2007-01-01 0.387048 431 - 2 │ 2007-01-02 1.1515 431 - 3 │ 2007-01-03 0.828109 431 - 4 │ 2007-01-04 4.2478 431 - 5 │ 2007-01-05 4.30876 431 - 6 │ 2007-01-06 2.93308 431 - 7 │ 2007-01-07 6.29236 431 - 8 │ 2007-01-08 6.90237 431 - ⋮ │ ⋮ ⋮ ⋮ - 425 │ 2008-02-29 7.89843 431 - 426 │ 2008-03-01 2.87578 431 - 427 │ 2008-03-02 4.7969 431 - 428 │ 2008-03-03 8.40796 431 - 429 │ 2008-03-04 3.32234 431 - 430 │ 2008-03-05 0.977815 431 - 431 │ 2008-03-06 0.491254 431 - 416 rows omitted

      Writing TSFrame into a CSV file

      Writing a TSFrame object into a CSV file can be done easily by using the underlying coredata property. This DataFrame can be passed to the CSV.write method for writing into a file.

      julia> CSV.write("/tmp/demo_ts.csv", ts)"/tmp/demo_ts.csv"

      Broadcasting

      Broadcasting can be used on a TSFrame object to apply a function to a subset of it's columns.

      julia> using TSFrames, DataFrames;
      + 2.792200737659307
      + 9.914802960351995
      + 5.309356427971582
      + 5.581264871613396
      + 4.750703622715694
      + 9.30229459918937
      + 9.935303268682393
      + 8.63289556041307
      + 4.165493597143481
      julia> select(ts.coredata, :Index, :value, DataFrames.nrow) # use the underlying DataFrame for other operations431×3 DataFrame + Row │ Index value nrow + │ Date Float64 Int64 +─────┼──────────────────────────── + 1 │ 2007-01-01 4.28905 431 + 2 │ 2007-01-02 2.1487 431 + 3 │ 2007-01-03 2.73592 431 + 4 │ 2007-01-04 4.90115 431 + 5 │ 2007-01-05 5.86148 431 + 6 │ 2007-01-06 9.61217 431 + 7 │ 2007-01-07 1.96545 431 + 8 │ 2007-01-08 2.43444 431 + ⋮ │ ⋮ ⋮ ⋮ + 425 │ 2008-02-29 5.30936 431 + 426 │ 2008-03-01 5.58126 431 + 427 │ 2008-03-02 4.7507 431 + 428 │ 2008-03-03 9.30229 431 + 429 │ 2008-03-04 9.9353 431 + 430 │ 2008-03-05 8.6329 431 + 431 │ 2008-03-06 4.16549 431 + 416 rows omitted

      Writing TSFrame into a CSV file

      Writing a TSFrame object into a CSV file can be done easily by using the underlying coredata property. This DataFrame can be passed to the CSV.write method for writing into a file.

      julia> CSV.write("/tmp/demo_ts.csv", ts)"/tmp/demo_ts.csv"

      Broadcasting

      Broadcasting can be used on a TSFrame object to apply a function to a subset of it's columns.

      julia> using TSFrames, DataFrames;
       
       julia> ts = TSFrame(DataFrame(Index = [1, 2, 3, 4, 5], A = [10.1, 12.4, 42.4, 24.1, 242.5], B = [2, 4, 6, 8, 10]))
       (5 x 2) TSFrame with Int64 Index
      @@ -623,4 +623,4 @@ 

      Note

      This discussion warrants a note about how we've implemented the Tables.jl interfaces. Since TSFrame objects are nothing but a wrapper around a DataFrame, our implementations of these interfaces just call DataFrames.jl's implementations. Moreover, while constructing TSFrame objects out of other Tables.jl compatible types, our constructor first converts the input table to a DataFrame, and then converts the DataFrame to a TSFrame object.

      +julia> CSV.read("ts.csv", TSFrame);

      Note

      This discussion warrants a note about how we've implemented the Tables.jl interfaces. Since TSFrame objects are nothing but a wrapper around a DataFrame, our implementations of these interfaces just call DataFrames.jl's implementations. Moreover, while constructing TSFrame objects out of other Tables.jl compatible types, our constructor first converts the input table to a DataFrame, and then converts the DataFrame to a TSFrame object.