Skip to content

Instantly share code, notes, and snippets.

macro select(ex::Expr, sym1::Symbol, ex1::Expr, sym2::Symbol, ex3::Expr)
ex.args, sym1, ex1.args, sym2, ex3.args
end
julia> @select open, high, close in ohlcv where close > open when day=Friday
(Any[:open,:high,:(close in ohlcv)],:where,Any[:>,:close,:open],:when,Any[:day,:Friday])
# would be nice to do this instead of a one-liner
@select open, high, close
@milktrader
milktrader / monad
Last active July 28, 2016 15:50
using functions as fields in a type
type Foo
f::Function
end
bar = Foo(x->2x)
bar.f(2)
4
@milktrader
milktrader / BAstock.R
Created April 7, 2015 13:54
troubleshoot stock() call error
# BA.csv
Date,Open,High,Low,Close
2013-12-31,136.16,137.05,135.74,136.49
2013-12-30,137.16,137.37,135.54,135.92
2013-12-27,138.69,138.88,136.79,136.9
2013-12-26,137.18,138.59,137.17,138.27
2013-12-24,136.4,136.98,136.14,136.83
2013-12-23,137.69,138.09,136.32,136.4
2013-12-20,135.49,137.85,135.49,136.67
@milktrader
milktrader / update_asset.jl
Last active August 29, 2015 14:17
Reactive getindex hack
julia> using Grist #brings in Reactive and other experimental packages
julia> res
10-element Array{Timestamps.Timestamp{T},1}:
2000-01-03 | 200 Stock 95.0 $ AAPL
2000-03-15 | -100 Stock 116.25 $ AAPL
2000-05-25 | 100 Stock 87.27 $ AAPL
2000-08-07 | -100 Stock 47.94 $ AAPL
2000-10-17 | 100 Stock 20.12 $ AAPL
2000-12-28 | -100 Stock 14.81 $ AAPL
@milktrader
milktrader / frp.jl
Last active August 29, 2015 14:17
Grist gist
julia> res
10-element Array{Timestamps.Timestamp{T},1}:
2000-01-03 | 100 Stock 111.94 $ AAPL
2000-03-15 | -100 Stock 116.25 $ AAPL
2000-05-25 | 100 Stock 87.27 $ AAPL
2000-08-07 | -100 Stock 47.94 $ AAPL
2000-10-17 | 100 Stock 20.12 $ AAPL
2000-12-28 | -100 Stock 14.81 $ AAPL
2001-03-13 | 100 Stock 19.56 $ AAPL
2001-05-23 | -100 Stock 23.23 $ AAPL
@milktrader
milktrader / types.jl
Created March 6, 2015 18:28
type factories
julia> LIST = ["foo", "bar"]
2-element Array{ASCIIString,1}:
"foo"
"bar"
julia> for L in LIST
@eval begin
type ($L)
end
end
@milktrader
milktrader / bokeh_plot.html
Created February 23, 2015 12:58
Bokeh.jl simple plot code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/Users/Administrator/.julia/v0.4/Bokeh/deps/bokehjs/css/bokeh.min.css" type="text/css" />
<script type="text/javascript" src="/Users/Administrator/.julia/v0.4/Bokeh/deps/bokehjs/js/bokeh.min.js"></script>
<script type="text/javascript">
$(function() {
var modelid = "e4aa998b-b915-4d5c-aa38-4d76437c4fbf";
@milktrader
milktrader / minkowski.jl
Created August 25, 2014 01:00
Minkowski criterion function
julia> function L(c)
sum([abs(xs-c)^2 for xs in x])/length(x)
end
L (generic function with 2 methods)
julia> x=[1,2,3,4,5,6,9,12]
8-element Array{Int64,1}:
1
2
3
@milktrader
milktrader / bit.jl
Created May 24, 2014 17:13
Plotting bitcoin in Julia REPL
julia> using Quandl, TextPlots
julia> bt = quandl("BAVERAGE/USD", rows=1000)
1000x5 TimeArray{Float64,2} 2011-08-25 to 2014-05-23
24h Average Ask Bid Last Total Volume
2011-08-25 | 10.01 NaN NaN NaN 55547.42
2011-08-26 | 8.65 NaN NaN NaN 83026.56
2011-08-27 | 8.63 NaN NaN NaN 22010.04
2011-08-28 | 8.97 NaN NaN NaN 24159.85
@milktrader
milktrader / rfinanceongit.sh
Created April 25, 2014 04:09
R-Finance package list
1 #!/bin/bash
2
3 cd ~/git/quantstrat
4 git svn rebase
5 git push origin master
6
7 cd ~/git/xts
8 git svn rebase
9 git push origin master
10