femtotrader / TimeFrames.jl

A Julia library that defines TimeFrame (essentially for resampling TimeSeries)
Other
4 stars 3 forks source link

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

Open femtotrader opened 8 years ago

femtotrader commented 8 years ago
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 https://github.com/femtotrader/TimeSeriesResampler.jl/issues/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')
femtotrader commented 8 years ago

Same for H (instead of 1H) ... Y should be A (or AS) ...