Skip to content

Commit 6b5fe4e

Browse files
committed
Fix 0.4 deprecation warnings
1 parent a7fa544 commit 6b5fe4e

12 files changed

+307
-473
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ An attempt at a unified framework in Julia language for both event-driven backte
44

55
The main objective is to be able to backtest and place real-time orders using the same trading strategy functions.
66

7+
NOTE: The current `master`-branch code requires `Julia >=0.4.0`. See the `julia03` branch for the last version tested with Julia 0.3 before [0.4.0 final release](https://github.com/JuliaLang/julia/releases).
8+
79
[Documentation](http://tradinglogicjl.readthedocs.org/en/latest/)

REQUIRE

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
julia 0.3-
2-
Dates
1+
julia 0.4
32
Match
43
Reactive
54
TimeSeries

docs/api.md

+100-181
Large diffs are not rendered by default.

docs/source/api.rst

+172-255
Large diffs are not rendered by default.

src/TradingLogic.jl

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
if VERSION < v"0.4-"
2-
using Dates
3-
else
4-
using Base.Dates
5-
end
1+
VERSION >= v"0.4.0" && __precompile__(true)
62

7-
using Reactive, Match, TimeSeries, Compat
3+
using Base.Dates, Reactive, Match, TimeSeries, Compat
84

95
module TradingLogic
106

11-
if VERSION < v"0.4-"
12-
using Dates
13-
else
14-
using Base.Dates
15-
end
16-
17-
using Reactive, Match, TimeSeries, Compat
7+
using Base.Dates, Reactive, Match, TimeSeries, Compat
188

199
export runtrading!, runbacktest, runbacktesttarg
2010
export emptyblotter, printblotter, writeblotter
@@ -76,8 +66,10 @@ function runtrading!(blotter::Blotter,
7666
position_actual_mut = [position_initial]
7767

7868
# target signal: strategy-specific
79-
s_target = apply(targetfun, tuple(s_ohlc, ohlc_inds,
80-
position_actual_mut, strategy_args...))
69+
##s_target = apply(targetfun, tuple(s_ohlc, ohlc_inds,
70+
## position_actual_mut, strategy_args...))
71+
s_target = targetfun(tuple(s_ohlc, ohlc_inds,
72+
position_actual_mut, strategy_args...)...)
8173

8274
# current time signal from OHLC timestamp
8375
s_tnow = Reactive.lift(s -> s[1], s_ohlc, typ=DateTime)
@@ -121,8 +113,10 @@ function runtrading!(blotter::Blotter,
121113
position_actual_mut = [position_initial]
122114

123115
# target signal: strategy-specific
124-
s_target = apply(targetfun, tuple(s_ohlc, ohlc_inds,
125-
position_actual_mut, strategy_args...))
116+
##s_target = apply(targetfun, tuple(s_ohlc, ohlc_inds,
117+
## position_actual_mut, strategy_args...))
118+
s_target = targetfun(tuple(s_ohlc, ohlc_inds,
119+
position_actual_mut, strategy_args...)...)
126120

127121
# current time signal from OHLC timestamp
128122
s_tnow = Reactive.lift(s -> s[1], s_ohlc, typ=DateTime)
@@ -173,7 +167,7 @@ optimization objective function to improve performance.
173167
"""
174168
function runbacktest{M}(ohlc_ta::TimeSeries.TimeArray{Float64,2,M},
175169
ohlc_inds::Dict{Symbol,Int64},
176-
fileout::Union(Nothing,String),
170+
fileout::Union{Void,AbstractString},
177171
dtformat_out,
178172
pfill::Symbol,
179173
position_initial::Int64,
@@ -220,7 +214,7 @@ determine the latest timestep actions.
220214
"""
221215
function runbacktesttarg{M}(ohlc_ta::TimeSeries.TimeArray{Float64,2,M},
222216
ohlc_inds::Dict{Symbol,Int64},
223-
fileout::Union(Nothing,String),
217+
fileout::Union{Void,AbstractString},
224218
dtformat_out,
225219
pfill::Symbol,
226220
position_initial::Int64,
@@ -262,7 +256,7 @@ function runbacktestcore{M}(ohlc_ta::TimeSeries.TimeArray{Float64,2,M},
262256
s_ohlc::Input{OHLC},
263257
s_status::Signal{@compat(Tuple{Bool, Float64})},
264258
s_perf::Signal{@compat(Tuple{Float64, Float64})},
265-
fileout::Union(Nothing,String),
259+
fileout::Union{Void,AbstractString},
266260
dtformat_out)
267261
nt = length(ohlc_ta)
268262
vequity = zeros(nt)
@@ -273,7 +267,7 @@ function runbacktestcore{M}(ohlc_ta::TimeSeries.TimeArray{Float64,2,M},
273267
# prepare file to write to at each timestep
274268
fout = open(fileout, "w")
275269
separator = ','; quotemark = '"'
276-
rescols = ["Timestamp", ohlc_ta.colnames, "CumPnL", "DDown"]
270+
rescols = ["Timestamp"; ohlc_ta.colnames; "CumPnL"; "DDown"]
277271
printvecstring(fout, rescols, separator, quotemark)
278272
writeout = true
279273
end

src/performance.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040

4141
"Print blotter transactions. Resembles DataFrames.printtable."
4242
function printblotter(io::IO, blotter::Blotter;
43-
dtformat::String = "yyyy-mm-ddTHH:MM:SS",
43+
dtformat::AbstractString = "yyyy-mm-ddTHH:MM:SS",
4444
separator::Char = ',', quotemark::Char = '"')
4545
# ordered timestamps
4646
vt = vtblotter(blotter)
@@ -69,8 +69,8 @@ function printblotter(io::IO, blotter::Blotter;
6969
end
7070

7171
"Write blotter transactions to file."
72-
function writeblotter(filename::String, blotter::Blotter;
73-
dtformat::String = "yyy-mm-ddTHH:MM:SS",
72+
function writeblotter(filename::AbstractString, blotter::Blotter;
73+
dtformat::AbstractString = "yyy-mm-ddTHH:MM:SS",
7474
separator::Char = ',', quotemark::Char = '"')
7575
open(filename, "w") do io
7676
printblotter(io, blotter,

src/sigutils.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ end
4040
Initialization of `nbuff`-size float-elements buffer
4141
with NaNs and last element `xinit`.
4242
"""
43-
initbuff(nbuff::Int64, xinit::Float64) = [fill(NaN, nbuff-1), xinit]
43+
initbuff(nbuff::Int64, xinit::Float64) = [fill(NaN, nbuff-1); xinit]

test/backtest.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rel(path::String) = joinpath(splitdir(@__FILE__)[1], path)
1+
rel(path::AbstractString) = joinpath(splitdir(@__FILE__)[1], path)
22

33
facts("OHLC backtest with timearray input") do
44
# using quantstrat goldencross test
@@ -74,7 +74,7 @@ facts("OHLC backtest with timearray input") do
7474
run(`rm $fileout`)
7575
@fact length(taf) --> length(ohlc_ta)
7676
@fact taf.timestamp --> ohlc_ta.timestamp
77-
@fact taf.colnames --> [ohlc_ta.colnames, "CumPnL", "DDown"]
77+
@fact taf.colnames --> [ohlc_ta.colnames; "CumPnL"; "DDown"]
7878
@fact taf.values[:,1:end-2] --> roughly(ohlc_ta.values)
7979
@fact taf["CumPnL"].values[1] --> roughly(0.0)
8080
@fact taf["DDown"].values[1] --> roughly(0.0)

test/perfmetrics.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ facts("Trading metrics from transactions blotter") do
3131
@fact rcsv[1,2] --> "Amount"
3232
@fact rcsv[2,1] --> Dates.format(tlong, dtfmt)
3333
@fact rcsv[4,1] --> Dates.format(texit, dtfmt)
34-
@fact int(rcsv[3,2]) --> -(along + ashort)
34+
##@fact int(rcsv[3,2]) --> -(along + ashort)
35+
@fact round(Int64, rcsv[3,2]) --> -(along + ashort)
3536
@fact float(rcsv[4,3]) --> roughly(p3)
3637
end
3738
context("Long enter with partial fill") do

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using FactCheck
22
using MarketData
33
using DataFrames
4+
using Base.Dates
5+
using Compat
46

57
include("signals.jl")
68
include("orders.jl")

test/teststrategy_goldencross.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ facts("Goldencross trading logic") do
1717
# up, zero position
1818
@fact ft(:trendup, 0) --> (tq, stlim)
1919
# up, position less than target (e.g. partial fill)
20-
p = int(tq/2)
20+
p = round(Int64, tq/2)
2121
@fact ft(:trendup, p) --> (tq - p, stlim)
2222

2323
# down: sell
@@ -83,7 +83,7 @@ facts("Goldencross strategy backtesting") do
8383

8484
s_ohlc = Reactive.Input((Dates.DateTime(ohlc_test.timestamp[1]),
8585
vec(ohlc_test.values[1,:])))
86-
ohlc_inds = (Symbol => Int64)[]
86+
ohlc_inds = Dict{Symbol,Int64}()
8787
ohlc_inds[:open] = 1
8888
ohlc_inds[:close] = 4
8989

test/teststrategy_luxor.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ facts("Luxor trading logic") do
1717
# enter long
1818
@fact ft(:trendup, 0) --> (tq, [165.0, 155.0])
1919
# enter long partial fill
20-
p = int(tq/2)
20+
p = round(Int64, tq/2)
2121
@fact ft(:trendup, p) --> (tq - p, [165.0, 155.0])
2222

2323
# enter short
2424
@fact ft(:trenddown, 0) --> (-tq, [140.0, 150.0])
2525
# enter short partial fill
26-
p = -int(tq/2)
26+
p = -round(Int64, tq/2)
2727
@fact ft(:trenddown, p) --> (-abs(tq-p), [140.0, 150.0])
2828

2929
# hold position in line with the market state
@@ -32,12 +32,12 @@ facts("Luxor trading logic") do
3232

3333
# exit long position
3434
@fact ft(:trenddown, tq) --> (-tq, stlim)
35-
p = int(tq/2)
35+
p = round(Int64, tq/2)
3636
@fact ft(:trenddown, p) --> (-p, stlim)
3737

3838
# exit short position
3939
@fact ft(:trendup, -tq) --> (tq, stlim)
40-
p = -int(tq/2)
40+
p = -round(Int64, tq/2)
4141
@fact ft(:trendup, p) --> (abs(p), stlim)
4242

4343
# undefined: wait
@@ -57,7 +57,7 @@ facts("Luxor strategy backtesting") do
5757
### TODO change data input
5858
s_ohlc = Reactive.Input((Dates.DateTime(ohlc.timestamp[1]),
5959
vec(ohlc.values[1,:])))
60-
ohlc_inds = (Symbol => Int64)[]
60+
ohlc_inds = Dict{Symbol,Int64}()
6161
ohlc_inds[:open] = 1
6262
ohlc_inds[:high] = 2
6363
ohlc_inds[:low] = 3

0 commit comments

Comments
 (0)