... And, once you have understood the idea of moving "something", it's easy to see that:
20 >./\ Prices - moving maximum 20 <./\ Prices - moving minimum 20 +/\ Prices - moving total 20 spread\ Prices - moving spread, where spread=: >./ - <.\ etc. Using words like "sum", "maximum", "minimum", etc. is not as good in this regard; in using words the concept and power of adverbs are not as evident. On Mon, Feb 17, 2014 at 6:57 PM, Roger Hui <[email protected]>wrote: > 20%~ each +/"1 each _20 <\ Prices > > This is not moving average as I understand it, because the windows don't > overlap. You have to use 20 instead of _20. But a better way is: > > avg=: +/ % # > 20 avg\ Prices > > That is, you don't have to box everything up and then apply f to each; you > can give the verb to the adverb, the way verbs and adverbs are meant to > work together. > > > > > > On Mon, Feb 17, 2014 at 6:36 PM, Joe Bogner <[email protected]> wrote: > >> I thought it might be fun to post a J vs R side-by-side comparison. The >> character counts aren't meant to be exact... The solutions are fairly >> similar up until the moving averages. It wasn't meant as a code golf >> exercise. >> >> http://jsbin.com/ihunin/337 >> >> After reading R code for years, I actually think the J version is more >> pleasant to look at >> >> I'd like to add an example where J really shines over R. The data.table >> package in R makes it much more succint than normal R code. The most stark >> example I came up with so far is the moving average. Are there any other >> ideas? >> >> There's probably a more concise way to express this too: >> plot > 20%~ each +/"1 each _20 <\ Prices >> >> I thought I could get atop or something to work but I gave up after about >> 10 minutes. >> >> >> >> >> >> >> On Mon, Feb 17, 2014 at 12:59 PM, Joe Bogner <[email protected]> wrote: >> >> > Here is the code: >> > >> > NB. retrieve stock prices from yahoo and do some graphing >> > load 'web/gethttp' >> > load 'tables/csv' >> > load 'plot' >> > >> > URL=:'http://ichart.finance.yahoo.com/table.csv?s=' >> > >> > quote=: 3 : 'fixcsv gethttp URL,y' >> > >> > Quotes=: quote each 'DAL';'UAL' >> > >> > 'DAL UAL'=:Quotes >> > >> > DALd =: |. }. DAL >> > >> > Prices=: > ". each 4{"1 DALd >> > plot Prices >> > >> > MaxPrice=: >./ Prices >> > >> > plotPrices =: 3 : 0 >> > pd (i. # y);(|. ,> y) >> > ) >> > >> > plotTickers =: 3 : 0 >> > Tickers=.y >> > pd 'reset' >> > pd 'key',(, > ' '&, each Tickers) >> > Quotes=.quote each Tickers >> > AllPrices=. ". each > }. each 4{"1 each Quotes >> > plotPrices"1 AllPrices >> > pd 'show' >> > ) >> > plotTickers 'UAL';'DAL';'JBLU' >> > >> > Years=. 4 {. each 0{"1 DALd >> > groupBy=: 4 : '(((~.y) i. y)) ,/. x' >> > YearGroups=:Prices groupBy Year >> > MaxPricePerYear =: >. /"1 YearGroups >> > ]YearKeys=: ". > ~. Year >> > plot YearKeys;MaxPerYear >> > >> > >> > >> > >> > >> > On Mon, Feb 17, 2014 at 12:49 PM, Joe Bogner <[email protected]> >> wrote: >> > >> >> This is a continuation of this thread: >> >> http://jsoftware.com/pipermail/programming/2014-February/035222.htmlbut >> >> moved to chat. >> >> >> >> I posted a video http://www.youtube.com/watch?v=qXFpgYvbogw with the >> >> intent of showing some of J's capabilities. >> >> >> >> I would be happy to hear any feedback on the video. >> >> >> >> Looking back at it, I wish I bumped up the font size. It's best viewed >> >> full screen. >> >> >> >> I tried to flip through things pretty quickly to fit in as much as >> >> possible. I probably unnecessarily explained things in a few cases. I >> >> still need to practice using the right term for the operations too. >> >> >> >> In terms of my examples, I would like to know if I could put dates >> >> somehow on on X-axis. >> >> >> >> I also worked up an example that used a secondary axis with % change, >> but >> >> I haven't recorded it yet. That might be a continuation. Plotting on a >> >> secondary axis is something that J's plot does real easily compared to >> R. >> >> >> >> Thanks for any feedback >> >> >> > >> > >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
