-
Notifications
You must be signed in to change notification settings - Fork 23
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
WIP: Add Indicators.jl functionality with TSFrames #155
base: main
Are you sure you want to change the base?
Changes from 5 commits
50c9a5f
3a443b0
50d85ca
2e8c7f2
69b331d
328fb2e
cd7281d
f7122c6
f0a2154
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module IndicatorsExt | ||
|
||
using TSFrames, Indicators | ||
|
||
# Methods for porting Indicators.jl functions to TSFrame objects from TSFrames.jl package | ||
# See their respective documentation on Indicators.jl | ||
Indicators.runmean(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.runmean(X[:, x]; kwargs...), X[:, :Index]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserving Index. Is there better way to integrate to TSFrame? More optimised way to avoid extra Construction operations? |
||
Indicators.sma(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.sma(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.trima(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.trima(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.wma(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.wma(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.ema(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.ema(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.mma(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.mma(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.dema(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.dema(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.tema(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.tema(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.mama(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.dema(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.hma(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.hma(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.swma(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.swma(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.kama(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.kama(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.alma(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.alma(X[:, x]; kwargs...), X[:, :Index]) | ||
Indicators.zlema(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.zlema(X[:, x]; kwargs...), X[:, :Index]) | ||
# VWMA is defined on Matrix, not Array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still thinking how to adapt methods that work on |
||
# VWAP is defined on Matrix, not Array | ||
Indicators.hama(X::TSFrame, x::Symbol; kwargs...) = TSFrame(Indicators.hama(X[:, x]; kwargs...), X[:, :Index]) | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module TSFrames | ||
|
||
using DataFrames, Dates, ShiftedArrays, RecipesBase, RollingFunctions, Tables | ||
using DataFrames, Dates, ShiftedArrays, RecipesBase, RollingFunctions, Tables # , Indicators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remove comment |
||
|
||
import Base.convert | ||
import Base.diff | ||
|
@@ -76,6 +76,8 @@ export TSFrame, | |
vcat, | ||
DataFrame, | ||
Date | ||
# sma, | ||
# runmean | ||
|
||
include("TSFrame.jl") | ||
include("utils.jl") | ||
|
@@ -97,5 +99,6 @@ include("to_period.jl") | |
include("vcat.jl") | ||
include("broadcasting.jl") | ||
include("tables.jl") | ||
# include("indicators.jl") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm comments |
||
|
||
end # END module TSFrames |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using MarketData | ||
|
||
@testset "indicators_integration" begin | ||
sp500 = TSFrame(MarketData.yahoo("^GSPC")) | ||
date_from = Date(2021, 03, 1) | ||
date_to = Date(2023, 03, 1) | ||
sp500_2y = TSFrames.subset(sp500, date_from, date_to) | ||
@test sma(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make tests more diverse and meaningful, by using kwargs from upstream method |
||
@test runmean(sp500_2y, :Close) |> typeof == TSFrame | ||
@test trima(sp500_2y, :Close) |> typeof == TSFrame | ||
@test wma(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test ema(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test mma(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test dema(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test tema(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test mama(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test hma(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test swma(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test kama(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test alma(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test zlema(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
@test hama(sp500_2y, :AdjClose) |> typeof == TSFrame | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in [weakdeps]