Giter VIP home page Giter VIP logo

timeframes.jl's Introduction

TimeFrames

Package Evaluator

Build Status

Coverage Status

codecov.io

A Julia library that defines TimeFrames (essentially for resampling TimeSeries).

Install

julia> Pkg.add("TimeFrames")

Usage

julia> using TimeFrames

julia> tf = TimeFrame("5T")
TimeFrames.Minute(5 minutes,Begin::TimeFrames.Boundary = 1)

julia> apply(tf, DateTime(2016, 9, 11, 20, 9))
2016-09-11T20:05:00

julia> apply(TimeFrame("2H"), DateTime(2016, 9, 11, 20, 9))
2016-09-11T20:00:00

This library is used by

timeframes.jl's People

Contributors

femtocleaner[bot] avatar femtotrader avatar iblislin avatar scls19fr avatar staticfloat avatar tkelman avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

timeframes.jl's Issues

tf macro should be named TF instead

Hello,

I don't know if it's a good practice for Julia code but I think
tf macro should be named TF instead.

It have been added by @iblis17
in 378b796

So it should be possible to do:

tf = TF"4H"

Your opinion?

method matching *(::Int64, ::TimeFrame)

method(s) matching *(::Int64, ::TimeFrame) are required

julia> DateTime(2010,1,1) + TimeFrame("MS")
2010-02-01T00:00:00

julia> DateTime(2010,1,1) + TimeFrame("3MS")
2010-04-01T00:00:00

julia> DateTime(2010,1,1) + 3*TimeFrame("MS")
ERROR: MethodError: no method matching *(::Int64, ::TimeFrames.MonthBegin)
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
  *(::Real, ::Complex{Bool}) at complex.jl:254
  *(::Real, ::Complex) at complex.jl:266
  ...

PS: MS = monthly start

UnitRange/StepRange and TimeFrame - colon syntax support - start:step:stop

It should be possible to use StepRange with a TimeFrame.

julia> DateTime(2010,1,1):TimeFrame("5T"):DateTime(2012,1,1)
ERROR: MethodError: no method matching zero(::TimeFrames.TimePeriodFrame{Base.Dates.Minute})
Closest candidates are:
  zero(::Type{Base.LibGit2.Oid}) at libgit2/oid.jl:88
  zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuildItem}) at pkg/resolve/versionweight.jl:80
  zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuild}) at pkg/resolve/versionweight.jl:120
  ...
 in steprange_last(::DateTime, ::TimeFrames.TimePeriodFrame{Base.Dates.Minute}, ::DateTime) at ./range.jl:27
 in colon(::DateTime, ::TimeFrames.TimePeriodFrame{Base.Dates.Minute}, ::DateTime) at ./range.jl:118

TimeFrame shortcut parsing might be case insensitive

tf = TimeFrame("15MIN")
TimeFrames.TimePeriodFrame{Base.Dates.Minute}(15 minutes,Begin::TimeFrames.Boundary = 1)

but

tf = TimeFrame("15Min")

raises

ERROR: Can't parse '15Min' to TimeFrame
 in TimeFrames.TimeFrame(::String) at /Users/femto/.julia/v0.5/TimeFrames/src/TimeFrames.jl:78

Related issue:
#3

A Julia equivalent to Pandas date_range function

JuliaStats/TimeSeries.jl#264
JuliaLang/julia#18024

TimeFrame could be supported
and we could define a range with not regularly spaced events

Example:

In [1]: import pandas as pd
In [2]: from pandas.tseries.frequencies import to_offset
In [3]: from pandas.tseries.offsets import MonthEnd
In [2]: pd.date_range("2010-01-01", "2020-01-01", freq="MS")
Out[2]:
DatetimeIndex(['2010-01-01', '2010-02-01', '2010-03-01', '2010-04-01',
               '2010-05-01', '2010-06-01', '2010-07-01', '2010-08-01',
               '2010-09-01', '2010-10-01',
               ...
               '2019-04-01', '2019-05-01', '2019-06-01', '2019-07-01',
               '2019-08-01', '2019-09-01', '2019-10-01', '2019-11-01',
               '2019-12-01', '2020-01-01'],
              dtype='datetime64[ns]', length=121, freq='MS')

In [3]: pd.date_range("2010-01-01", "2020-01-01", freq="M")
Out[3]:
DatetimeIndex(['2010-01-31', '2010-02-28', '2010-03-31', '2010-04-30',
               '2010-05-31', '2010-06-30', '2010-07-31', '2010-08-31',
               '2010-09-30', '2010-10-31',
               ...
               '2019-03-31', '2019-04-30', '2019-05-31', '2019-06-30',
               '2019-07-31', '2019-08-31', '2019-09-30', '2019-10-31',
               '2019-11-30', '2019-12-31'],
              dtype='datetime64[ns]', length=120, freq='M')

In [4]: pd.date_range("2010-01-01 20:00:00", "2010-01-04 00:00:00", freq="D")
Out[4]:
DatetimeIndex(['2010-01-01 20:00:00', '2010-01-02 20:00:00',
               '2010-01-03 20:00:00'],
              dtype='datetime64[ns]', freq='D')

In [5]: pd.date_range("2010-01-01", "2010-01-04", freq="D")
Out[5]: DatetimeIndex(['2010-01-01', '2010-01-02', '2010-01-03', '2010-01-04'], dtype='datetime64[ns]', freq='D')

TimeFrame apply doesn't work as expected when boundary is End

julia> using TimeFrames
julia> using TimeFrames: Begin, End

this is correct:

julia> apply(Monthly(boundary=Begin), Date(2010, 2, 20))
2010-02-01

but

julia> apply(Monthly(boundary=End), Date(2010, 2, 20))
2010-03-01

we should get 2010-02-28

With

apply(Monthly(boundary=End), DateTime(2010, 2, 20))

we should get 2010-02-28T23:59:59.999

Julia 1.0

This package is currently tested against Julia 0.7 version.
It shouldn't be a problem with 1.0... but it should be done

Adding a timeframe with boundary End to a DateTime doesn't work as expected

M TimeFrame shortcut means monthly (end of month)

julia> TimeFrame("M")
TimeFrames.MonthEnd(1 month, End::TimeFrames.Boundary = 2)

julia> DateTime(2010,1,1) + TimeFrame("M")
2010-02-01T00:00:00

We should expect

julia> DateTime(2010,1,1) + TimeFrame("M")
2010-01-31T23:59:59.999

(considering that smallest resolution of a DateTime is 1 millisecond)

Same issue with adding timeframe with boundary End to a Date

julia> Date(2010,1,1) + TimeFrame("M")
2010-02-01

but we should expect

julia> Date(2010,1,1) + TimeFrame("M")
2010-01-31

(considering that smallest resolution of a Date is one day

TimeFrame comparison is buggy

julia> using TimeFrames

julia> using TimeFrames: End, Begin

julia> Yearly(boundary=End) == Yearly(boundary=Begin)
true

it should be false

Breaking! range doesn't respect Base signature

range docstring is

  range(start, [step], length)

  Construct a range by length, given a starting value and optional step (defaults to 1).

TimeFrames range is using stop as third parameter not length...

So this is not consistent with Base

Related issue #5 #6

Some shortcuts for TimeFrame doesn't work like Pandas DateOffsets shortcuts

TimeFrame("1W")

works as expected but

TimeFrame("W")

raises

ERROR: ArgumentError: invalid base: base must be 2 ≤ base ≤ 62, got 0
 in tryparse_internal(::Type{Int64}, ::SubString{String}, ::Int64, ::Int64, ::Int64, ::Bool) at ./parse.jl:66
 in parse(::Type{Int64}, ::SubString{String}) at ./parse.jl:152
 in parse(::Type{Int64}, ::SubString{String}) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in TimeFrames.TimeFrame(::String) at /Users/femto/.julia/v0.5/TimeFrames/src/TimeFrames.jl:7

see femtotrader/TimeSeriesResampler.jl#3

PS:
see also Python Pandas

In [1]: from pandas.tseries.frequencies import to_offset
In [2]: from pandas.tseries.offsets import YearBegin, YearEnd, Hour

In [3]: YearBegin().apply(datetime.datetime(2016, 7, 20, 13, 14, 35, 245))
Out[3]: Timestamp('2017-01-01 13:14:35.000245')

In [4]: YearEnd().apply(datetime.datetime(2016, 7, 20, 13, 14, 35, 245))
Out[4]: Timestamp('2016-12-31 13:14:35.000245')

In [5]: to_offset('AS').apply(datetime.datetime(2016, 7, 20, 13, 14, 35, 245))
Out[5]: Timestamp('2017-01-01 13:14:35.000245')

In [6]: to_offset('A').apply(datetime.datetime(2016, 7, 20, 13, 14, 35, 245))
Out[6]: Timestamp('2016-12-31 13:14:35.000245')

tonext is buggy

dt = DateTime(2010, 1, 1, 0, 0)
tonext(TimeFrame("2H"), dt)

returns

2010-01-01T00:00:00

it should return

2010-01-01T02:00:00

fix range depreciation warning

┌ Warning: `range(start, step, length)` is deprecated, use `range(start, step=step, length=length)` instead.
│   caller = range(::DateTime, ::DatePeriodFrame{Day}, ::Int64) at TimeFrames.jl:270
└ @ TimeFrames ~/build/femtotrader/TimeFrames.jl/src/TimeFrames.jl:270
┌ Warning: `range(start, step, length)` is deprecated, use `range(start, step=step, length=length)` instead.
│   caller = range(::DatePeriodFrame{Day}, ::DateTime, ::Int64) at TimeFrames.jl:274

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.