Skip to content

Instantly share code, notes, and snippets.

@milktrader
Created January 15, 2014 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milktrader/8443408 to your computer and use it in GitHub Desktop.
Save milktrader/8443408 to your computer and use it in GitHub Desktop.
Simple return for first six weeks of 1999 for SPX
julia> using Series, MarketData, Lazy
julia> d1 = date(1999,1,1);
julia> d2 = date(1999,2,15);
julia> @> Op percentchange x->x[[d1:d2]] value sum expm1
0.017947448312809502
@milktrader
Copy link
Author

I should note that Op is imported via the MarketData package, an unregistered package that provides some constants mostly useful in testing.

The cool-looking @> is a piping operator from the registered Lazy package. (check it out)

I've made percentchange default to returning log returns after much debate (with myself mostly) ... (only with myself, actually)

The rest should be self-explanatory. Note that value is called to separate each SeriesPair's value from its index, at which point it becomes a Float64 array. Then, it's standard boilerplate sum log returns and expm1 them to get total return in simple terms.

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