Skip to content

Instantly share code, notes, and snippets.

@milktrader
Created March 24, 2014 02:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milktrader/9733018 to your computer and use it in GitHub Desktop.
Save milktrader/9733018 to your computer and use it in GitHub Desktop.
How many golden crosses in SPX since 1950?
julia> @> Cl sma(50) x->merge(x,sma(Cl,200)) x->x["sma50"] .> x["sma200"] discretesignal
65x1 TimeArray{Int64,1} 1950-10-18 to 2012-01-31
signals
1950-10-18 | 1.0
1953-05-11 | 0.0
1953-12-21 | 1.0
1956-10-26 | 0.0
2010-07-02 | 0.0
2010-10-22 | 1.0
2011-08-12 | 0.0
2012-01-31 | 1.0
@milktrader
Copy link
Author

This is actually faster code and much simpler (omitting merge)

julia> @time @> sma(Cl,50) .> sma(Cl,200) discretesignal
elapsed time: 1.529454278 seconds (46937668 bytes allocated)
65x1 TimeArray{Int64,1} 1950-10-18 to 2012-01-31

             signal
1950-10-18 | 1.0
1953-05-11 | 0.0
1953-12-21 | 1.0
1956-10-26 | 0.0

2010-07-02 | 0.0
2010-10-22 | 1.0
2011-08-12 | 0.0
2012-01-31 | 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment