From 2d01ddafc6eddd82f236a4a580617d8c24ccd320 Mon Sep 17 00:00:00 2001 From: milktrader Date: Tue, 4 Nov 2014 15:26:16 -0500 Subject: [PATCH 1/2] update to testing framework and indentation fixes --- .travis.yml | 22 ++++++----- README.md | 1 + REQUIRE | 1 - src/MarketTechnicals.jl | 13 ++++++- test/REQUIRE | 2 + test/candlesticks.jl | 10 ++--- test/levels.jl | 46 +++++++++++----------- test/movingaverages.jl | 86 ++++++++++++++++++++--------------------- test/utilities.jl | 6 +-- test/volume.jl | 24 ++++++------ 10 files changed, 112 insertions(+), 99 deletions(-) create mode 100644 test/REQUIRE diff --git a/.travis.yml b/.travis.yml index 547bf26..19c2114 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,20 @@ language: cpp -compiler: - - gcc +compiler: + - clang notifications: email: false +env: + matrix: + - JULIAVERSION="juliareleases" + - JULIAVERSION="julianightlies" before_install: - sudo add-apt-repository ppa:staticfloat/julia-deps -y - - sudo add-apt-repository ppa:staticfloat/julianightlies -y + - sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y - sudo apt-get update -qq -y - sudo apt-get install libpcre3-dev julia -y - - git config --global user.name "Travis User" - - git config --global user.email "travis@example.net" + - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi script: - - julia -e 'versioninfo(); Pkg.init();' - - julia -e 'Pkg.clone("git://github.com/JuliaQuant/MarketTechnicals.jl.git"); Pkg.add("TimeSeries"); Pkg.add("FactCheck"); Pkg.add("MarketData")' - - mkdir -p ~/.julia/MarketTechnicals - - cp -R ./* ~/.julia/MarketTechnicals/ - - julia ./test/runtests.jl + - julia -e 'Pkg.init(); Pkg.clone(pwd())' + - julia -e 'Pkg.test("MarketTechnicals",coverage=true)' +after_success: + - julia -e 'cd(Pkg.dir("MarketTechnicals")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())' diff --git a/README.md b/README.md index 7f7fb57..1bfae01 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/JuliaQuant/MarketTechnicals.jl.png)](https://travis-ci.org/JuliaQuant/MarketTechnicals.jl) [![MarketTechnicals](http://pkg.julialang.org/badges/MarketTechnicals_release.svg)](http://pkg.julialang.org/?pkg=MarketTechnicals&ver=release) +[![Coverage Status](https://coveralls.io/repos/JuliaQuant/MarketTechnicals.jl/badge.png?branch=master)](https://coveralls.io/r/JuliaQuant/MarketTechnicals.jl?branch=master) #### A toolkit for technical analysis of financial time series in Julia diff --git a/REQUIRE b/REQUIRE index e484d22..4248b21 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,3 @@ julia 0.3- TimeSeries StatsBase -Reexport diff --git a/src/MarketTechnicals.jl b/src/MarketTechnicals.jl index 5dcc071..d78cff9 100644 --- a/src/MarketTechnicals.jl +++ b/src/MarketTechnicals.jl @@ -1,7 +1,16 @@ +if VERSION < v"0.4-" + using Dates, StatsBase +else + using Base.Dates, StatsBase +end + module MarketTechnicals -using TimeSeries, StatsBase, Reexport -@reexport using TimeSeries +if VERSION < v"0.4-" + using Dates, StatsBase +else + using Base.Dates, StatsBase +end export sma, ema, bollingerbands, truerange, atr, #keltnerbands, diff --git a/test/REQUIRE b/test/REQUIRE new file mode 100644 index 0000000..223ad61 --- /dev/null +++ b/test/REQUIRE @@ -0,0 +1,2 @@ +FactCheck +MarketData diff --git a/test/candlesticks.jl b/test/candlesticks.jl index a67b10e..1b54cb4 100644 --- a/test/candlesticks.jl +++ b/test/candlesticks.jl @@ -2,9 +2,9 @@ using MarketData facts("Candlesticks") do - context("doji") do - @fact ohlc[findall(doji(ohlc))].timestamp[1] => Date(2000, 5, 30) - @fact ohlc[findall(doji(ohlc))].timestamp[2] => Date(2000, 12, 11) - @fact length(ohlc[findall(doji(ohlc))]) => 5 - end + context("doji") do + @fact ohlc[findall(doji(ohlc))].timestamp[1] => Date(2000, 5, 30) + @fact ohlc[findall(doji(ohlc))].timestamp[2] => Date(2000, 12, 11) + @fact length(ohlc[findall(doji(ohlc))]) => 5 + end end diff --git a/test/levels.jl b/test/levels.jl index 94514ad..8101008 100644 --- a/test/levels.jl +++ b/test/levels.jl @@ -2,27 +2,27 @@ using MarketData facts("Levels") do - context("floor pivots") do - @fact floorpivots(ohlc)["r3"].values[1] => roughly(123.310) # values verified by various website calculators - @fact floorpivots(ohlc)["r2"].values[1] => roughly(119.52) - @fact floorpivots(ohlc)["r1"].values[1] => roughly(115.73) - @fact floorpivots(ohlc)["pivot"].values[1] => roughly(108.71) - @fact floorpivots(ohlc)["s1"].values[1] => roughly(104.92) - @fact floorpivots(ohlc)["s2"].values[1] => roughly(97.900) - @fact floorpivots(ohlc)["s3"].values[1] => roughly(94.110) - @fact floorpivots(ohlc).timestamp[end] => Date(2001,12,31) - end - - context("woodiespivots") do -# # @fact_approx_eq 97.37500000000001 value(wr4)[2] # values NEED to be verified with online calculators -# # @fact_approx_eq 88.62500000000001 value(ws4)[2] - @fact woodiespivots(ohlc)["r3"].values[1] => roughly(124.465) - @fact woodiespivots(ohlc)["r2"].values[1] => roughly(118.480) - @fact woodiespivots(ohlc)["r1"].values[1] => roughly(113.655) - @fact woodiespivots(ohlc)["pivot"].values[1] => roughly(107.670) - @fact woodiespivots(ohlc)["s1"].values[1] => roughly(102.845) - @fact woodiespivots(ohlc)["s2"].values[1] => roughly(96.8625) - @fact woodiespivots(ohlc)["s3"].values[1] => roughly(92.035) - @fact woodiespivots(ohlc).timestamp[end] => Date(2001,12,31) - end + context("floor pivots") do + @fact floorpivots(ohlc)["r3"].values[1] => roughly(123.310) # values verified by various website calculators + @fact floorpivots(ohlc)["r2"].values[1] => roughly(119.52) + @fact floorpivots(ohlc)["r1"].values[1] => roughly(115.73) + @fact floorpivots(ohlc)["pivot"].values[1] => roughly(108.71) + @fact floorpivots(ohlc)["s1"].values[1] => roughly(104.92) + @fact floorpivots(ohlc)["s2"].values[1] => roughly(97.900) + @fact floorpivots(ohlc)["s3"].values[1] => roughly(94.110) + @fact floorpivots(ohlc).timestamp[end] => Date(2001,12,31) + end + + context("woodiespivots") do + # # @fact_approx_eq 97.37500000000001 value(wr4)[2] # values NEED to be verified with online calculators + # # @fact_approx_eq 88.62500000000001 value(ws4)[2] + @fact woodiespivots(ohlc)["r3"].values[1] => roughly(124.465) + @fact woodiespivots(ohlc)["r2"].values[1] => roughly(118.480) + @fact woodiespivots(ohlc)["r1"].values[1] => roughly(113.655) + @fact woodiespivots(ohlc)["pivot"].values[1] => roughly(107.670) + @fact woodiespivots(ohlc)["s1"].values[1] => roughly(102.845) + @fact woodiespivots(ohlc)["s2"].values[1] => roughly(96.8625) + @fact woodiespivots(ohlc)["s3"].values[1] => roughly(92.035) + @fact woodiespivots(ohlc).timestamp[end] => Date(2001,12,31) + end end diff --git a/test/movingaverages.jl b/test/movingaverages.jl index 8d56e30..dda30e5 100644 --- a/test/movingaverages.jl +++ b/test/movingaverages.jl @@ -2,48 +2,48 @@ using MarketData facts("Moving Averages") do - context("sma") do - @fact sma(cl, 10).values[1] => roughly(98.782) # TTR value 98.782 - @fact sma(cl, 10).values[2] => roughly(97.982) # TTR value 97.982 - @fact sma(cl, 10).values[3] => roughly(98.388) # TTR value 98.388 - @fact sma(cl, 10).values[490] => roughly(21.266) # TTR value 21.266 - @fact sma(cl, 10).values[491] => roughly(21.417) # TTR value 21.417 - @fact sma(cl, 10).timestamp[491] => Date(2001,12,31) - end + context("sma") do + @fact sma(cl, 10).values[1] => roughly(98.782) # TTR value 98.782 + @fact sma(cl, 10).values[2] => roughly(97.982) # TTR value 97.982 + @fact sma(cl, 10).values[3] => roughly(98.388) # TTR value 98.388 + @fact sma(cl, 10).values[490] => roughly(21.266) # TTR value 21.266 + @fact sma(cl, 10).values[491] => roughly(21.417) # TTR value 21.417 + @fact sma(cl, 10).timestamp[491] => Date(2001,12,31) + end + + context("ema") do + @fact ema(cl, 10).values[1] => roughly(98.78200) # TTR value 98.78200 + @fact ema(cl, 10).values[2] => roughly(99.71982) # TTR value 99.71982 + @fact ema(cl, 10).values[3] => roughly(100.96349) # TTR value 100.96349 + @fact ema(cl, 10).values[490] => roughly(21.58580) # TTR value 21.58580 + @fact ema(cl, 10).values[491] => roughly(21.64293) # TTR value 21.64293 + @fact ema(cl, 10).timestamp[491] => Date(2001,12,31) + end - context("ema") do - @fact ema(cl, 10).values[1] => roughly(98.78200) # TTR value 98.78200 - @fact ema(cl, 10).values[2] => roughly(99.71982) # TTR value 99.71982 - @fact ema(cl, 10).values[3] => roughly(100.96349) # TTR value 100.96349 - @fact ema(cl, 10).values[490] => roughly(21.58580) # TTR value 21.58580 - @fact ema(cl, 10).values[491] => roughly(21.64293) # TTR value 21.64293 - @fact ema(cl, 10).timestamp[491] => Date(2001,12,31) - end - - context("ema wilder true") do - @fact ema(cl, 10, wilder=true).values[1] => roughly(98.7820) # TTR value 98.7820 - @fact ema(cl, 10, wilder=true).values[2] => roughly(99.2978) # TTR value 99.2978 - @fact ema(cl, 10, wilder=true).values[3] => roughly(100.0240) # TTR value 100.0240 - @fact ema(cl, 10, wilder=true).values[490] => roughly(21.34556) # TTR value 21.34556 - @fact ema(cl, 10, wilder=true).values[491] => roughly(21.40100) # TTR value 21.40100 - @fact ema(cl, 10, wilder=true).timestamp[491] => Date(2001,12,31) - end - - context("Array dispatch is correct too") do - @fact sma(cl.values, 10)[1] => roughly(98.782) # same values as above TimeArray dispatch - @fact sma(cl.values, 10)[2] => roughly(97.982) - @fact sma(cl.values, 10)[3] => roughly(98.388) - @fact sma(cl.values, 10)[490] => roughly(21.266) - @fact sma(cl.values, 10)[491] => roughly(21.417) - @fact ema(cl.values, 10)[1] => roughly(98.78200) - @fact ema(cl.values, 10)[2] => roughly(99.71982) - @fact ema(cl.values, 10)[3] => roughly(100.96349) - @fact ema(cl.values, 10)[490] => roughly(21.58580) - @fact ema(cl.values, 10)[491] => roughly(21.64293) - @fact ema(cl.values, 10, wilder=true)[1] => roughly(98.7820) - @fact ema(cl.values, 10, wilder=true)[2] => roughly(99.2978) - @fact ema(cl.values, 10, wilder=true)[3] => roughly(100.0240) - @fact ema(cl.values, 10, wilder=true)[490] => roughly(21.34556) - @fact ema(cl.values, 10, wilder=true)[491] => roughly(21.40100) - end + context("ema wilder true") do + @fact ema(cl, 10, wilder=true).values[1] => roughly(98.7820) # TTR value 98.7820 + @fact ema(cl, 10, wilder=true).values[2] => roughly(99.2978) # TTR value 99.2978 + @fact ema(cl, 10, wilder=true).values[3] => roughly(100.0240) # TTR value 100.0240 + @fact ema(cl, 10, wilder=true).values[490] => roughly(21.34556) # TTR value 21.34556 + @fact ema(cl, 10, wilder=true).values[491] => roughly(21.40100) # TTR value 21.40100 + @fact ema(cl, 10, wilder=true).timestamp[491] => Date(2001,12,31) + end + + context("Array dispatch is correct too") do + @fact sma(cl.values, 10)[1] => roughly(98.782) # same values as above TimeArray dispatch + @fact sma(cl.values, 10)[2] => roughly(97.982) + @fact sma(cl.values, 10)[3] => roughly(98.388) + @fact sma(cl.values, 10)[490] => roughly(21.266) + @fact sma(cl.values, 10)[491] => roughly(21.417) + @fact ema(cl.values, 10)[1] => roughly(98.78200) + @fact ema(cl.values, 10)[2] => roughly(99.71982) + @fact ema(cl.values, 10)[3] => roughly(100.96349) + @fact ema(cl.values, 10)[490] => roughly(21.58580) + @fact ema(cl.values, 10)[491] => roughly(21.64293) + @fact ema(cl.values, 10, wilder=true)[1] => roughly(98.7820) + @fact ema(cl.values, 10, wilder=true)[2] => roughly(99.2978) + @fact ema(cl.values, 10, wilder=true)[3] => roughly(100.0240) + @fact ema(cl.values, 10, wilder=true)[490] => roughly(21.34556) + @fact ema(cl.values, 10, wilder=true)[491] => roughly(21.40100) + end end diff --git a/test/utilities.jl b/test/utilities.jl index 02c2bc7..8847172 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -1,6 +1,6 @@ facts("Utilities") do - context("Base.abs returns all positive numbers") do - @fact sum((abs(cl .- op) .>= 0).values) => length(cl) - end + context("Base.abs returns all positive numbers") do + @fact sum((abs(cl .- op) .>= 0).values) => length(cl) + end end diff --git a/test/volume.jl b/test/volume.jl index eed8ffc..756febc 100644 --- a/test/volume.jl +++ b/test/volume.jl @@ -2,16 +2,16 @@ using MarketData facts("Volume") do # commented tests that require a volume object not currently available in MarketData - context("obv") do - # @fact obv(ohlc).values[1] => 50480000.00 # TTR value is 50480000 - # @fact obv(ohlc).values[end] => 1145460000.00 # TTR value is 1145460000 - # @fact obv(ohlc).timestamp[end] => Date(2001,12,31) - end - -# commented tests that require a volume object not currently available in MarketData - context("vwap") do - # @fact vwap(ohlc).values[1] => roughly(109.0703) # TTR value 109.0703 - # @fact vwap(ohlc).values[end] => roughly(122.7716) # TTR value 122.7716 - # @fact vwap(ohlc).timestamp[end] => Date(2001,12,31) - end + context("obv") do + # @fact obv(ohlc).values[1] => 50480000.00 # TTR value is 50480000 + # @fact obv(ohlc).values[end] => 1145460000.00 # TTR value is 1145460000 + # @fact obv(ohlc).timestamp[end] => Date(2001,12,31) + end + + # commented tests that require a volume object not currently available in MarketData + context("vwap") do + # @fact vwap(ohlc).values[1] => roughly(109.0703) # TTR value 109.0703 + # @fact vwap(ohlc).values[end] => roughly(122.7716) # TTR value 122.7716 + # @fact vwap(ohlc).timestamp[end] => Date(2001,12,31) + end end From f1f9127aa96eccf59c09d4671ec442f17b289537 Mon Sep 17 00:00:00 2001 From: milktrader Date: Tue, 4 Nov 2014 15:42:06 -0500 Subject: [PATCH 2/2] added TimeSeries to module requirements --- src/MarketTechnicals.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MarketTechnicals.jl b/src/MarketTechnicals.jl index d78cff9..5c25c77 100644 --- a/src/MarketTechnicals.jl +++ b/src/MarketTechnicals.jl @@ -1,15 +1,15 @@ if VERSION < v"0.4-" - using Dates, StatsBase + using Dates, TimeSeries, StatsBase else - using Base.Dates, StatsBase + using Base.Dates, TimeSeries, StatsBase end module MarketTechnicals if VERSION < v"0.4-" - using Dates, StatsBase + using Dates, TimeSeries, StatsBase else - using Base.Dates, StatsBase + using Base.Dates, TimeSeries, StatsBase end export sma, ema,