-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnitRange/StepRange and TimeFrame - colon syntax support - start:step:stop #6
Comments
WIP using TimeFrames
using TimeFrames: AbstractPeriodFrame
Base.zero(tf::AbstractPeriodFrame) = zero(tf.time_period)
Base.isless(tf::AbstractPeriodFrame, period::Dates.Period) = isless(tf.time_period, period)
Base.isless(period::Dates.Period, tf::AbstractPeriodFrame) = isless(period, tf.time_period)
Base.abs(tf::AbstractPeriodFrame) = abs(tf.time_period)
Dates.toms(tf::AbstractPeriodFrame) = Dates.toms(tf.time_period)
import Base: *, +
*(tf::AbstractPeriodFrame, N::Integer) = tf.time_period * N
+(N::Integer, tf::AbstractPeriodFrame) = N + tf.time_period but julia> collect(DateTime(2010,1,1):TimeFrame("5T"):DateTime(2012,1,1))
ERROR: MethodError: no method matching +(::Int64, ::Base.Dates.Minute)
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:138
+(::Base.Dates.CompoundPeriod, ::Base.Dates.Period) at dates/periods.jl:312
+(::DateTime, ::Base.Dates.Period) at dates/arithmetic.jl:64
...
in vcat(::StepRange{DateTime,TimeFrames.Minute}) at ./range.jl:824
in collect(::StepRange{DateTime,TimeFrames.Minute}) at ./range.jl:832 maybe Base.convert(::Type{Dates.Period}, tf::TimeFrame) = tf.time_period could help |
julia> collect(1:10)
10-element Array{Int64,1}:
1
2
3
4
5
6
7
8
9
10
julia> typeof(1:10)
UnitRange{Int64}
julia> collect(1:2:10)
5-element Array{Int64,1}:
1
3
5
7
9
julia> typeof(1:2:10)
StepRange{Int64,Int64} See https://github.com/JuliaLang/julia/blob/f383276c5b91d4d111f628c2eaa6b2db2f496421/base/range.jl#L19 colon |
femtotrader
changed the title
StepRange and TimeFrame
UnitRange/StepRange and TimeFrame - two points syntax support - start:step:stop
Nov 28, 2017
femtotrader
changed the title
UnitRange/StepRange and TimeFrame - two points syntax support - start:step:stop
UnitRange/StepRange and TimeFrame - colon syntax support - start:step:stop
Nov 28, 2017
DateTime(2017, 12, 1, 2,30):TimeFrame("1T"):DateTime(2018, 1, 1, 2, 30)
ERROR: MethodError: no method matching zero(::TimeFrames.Minute)
Closest candidates are:
zero(::Type{Base.LibGit2.GitHash}) at libgit2/oid.jl:106
zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuildItem}) at pkg/resolve/versionweight.jl:82
zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuild}) at pkg/resolve/versionweight.jl:124
...
Stacktrace:
[1] steprange_last(::DateTime, ::TimeFrames.Minute, ::DateTime) at ./range.jl:102
[2] colon(::DateTime, ::TimeFrames.Minute, ::DateTime) at ./range.jl:46 |
zero(tf::AbstractPeriodFrame) = zero(tf.period)
isless(td::Dates.Period, tf::AbstractPeriodFrame) = isless(td, tf.period)
abs(tf::AbstractPeriodFrame) = abs(tf.period)
toms(tf::AbstractPeriodFrame) = toms(tf.period) should help and some tests @testset "zero" begin
@testset "TimePeriodFrame" begin
tf = tf"2H"
@test zero(tf) == Dates.Hour(0)
tf = tf"7D"
@test zero(tf) == Dates.Day(0)
end
@testset "DatePeriodFrame" begin
tf = tf"M"
@test zero(tf) == Dates.Month(0)
end
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should be possible to use StepRange with a TimeFrame.
The text was updated successfully, but these errors were encountered: