dysonance / Strategems.jl

Quantitative systematic trading strategy development and backtesting in Julia
Other
163 stars 39 forks source link

LoadError: UndefVarError: @signal not defined while loading /Users/balupton/Projects/trading/JuliaTrading.jl/strat.jl, in expression starting on line 30 #13

Closed balupton closed 6 years ago

balupton commented 6 years ago

Hi there,

So I'm using the IDE from Julia Pro 0.6.1.1.

I've created a new directory called JuliaTrading.jl. I've placed the mama.jl file inside of it, but called it strat.jl.

I use the IDE's console to run Pkg.add("Strategems") which works successfully.

Then I use the IDE's "Julia -> Run File" feature, which returns:

LoadError: UndefVarError: @signal not defined
while loading /Users/balupton/Projects/trading/JuliaTrading.jl/strat.jl, in expression starting on line 30
include_string(::String, ::String) at loading.jl:522
include_string(::Module, ::String, ::String) at Compat.jl:464
(::Atom.##57#60{String,String})() at eval.jl:74
withpath(::Atom.##57#60{String,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
macro expansion at eval.jl:72 [inlined]
(::Atom.##56#59{Dict{String,Any}})() at task.jl:80

It also happens when installing the package via Pkg.clone("https://github.com/dysonance/Strategems.jl")

strat.jl is:

using Strategems, Temporal, Indicators, Base.Dates
using Base.Test

# define universe and gather data
assets = ["CHRIS/CME_CL1", "CHRIS/CME_RB1"]
universe = Universe(assets)
function datasource(asset::String; save_downloads::Bool=true)::TS
    savedata_path = Pkg.dir("Strategems", "data/$asset.csv")
    if isfile(savedata_path)
        return Temporal.tsread(savedata_path)
    else
        X = quandl(asset)
        if save_downloads
            Temporal.tswrite(X, savedata_path)
        end
        return X
    end
end
gather!(universe, source=datasource)

# define indicators and parameter space
arg_names = [:fastlimit, :slowlimit]
arg_defaults = [0.5, 0.05]
arg_ranges = [0.01:0.01:0.99, 0.01:0.01:0.99]
paramset = ParameterSet(arg_names, arg_defaults, arg_ranges)
f(x; args...) = Indicators.mama(x; args...)
indicator = Indicator(f, paramset)

# define signals that will trigger trading decisions
siglong = @signal MAMA ↑ FAMA
sigshort = @signal MAMA ↓ FAMA
sigexit = @signal MAMA .== FAMA

# define the trading rules
longrule = @rule siglong → long 100
shortrule = @rule sigshort → short 100
exitrule = @rule sigexit → liquidate 1.0
rules = (longrule, shortrule, exitrule)

# run strategy
strat = Strategy(universe, indicator, rules)
backtest!(strat)
optimize!(strat, samples=10)
balupton commented 6 years ago

Ok, got a dialog inside the IDE saying the IDE extensions are outdated. Updated the extensions, restarted the IDE, and it all works fine!