Milktrader

Iterating Until Convergence

Wednesday, February 9, 2011

Twos and Tens in Four Lines

To chart the spread between 2-Year treasury yields and 10-Year treasury yields,  please type the simple code listed below into your R console. That is all, carry on as you were.

require(quantmod)

getSymbols(c("DGS10", "DGS2"), src="FRED")

Ten_Two <- DGS10-DGS2

chartSeries(Ten_Two)

7 comments:

  1. What source is FRED? Not familiar with it!

    ReplyDelete
  2. St Louis Federal Reserve. http://research.stlouisfed.org/fred2/

    ReplyDelete
  3. In 3 lines, with 2 fewer excursions to the Shift key. ;-)

    require(quantmod)
    getSymbols("DGS10;DGS2",src="FRED")
    chartSeries(DGS10-DGS2)

    ReplyDelete
  4. @Joshua Excellent refactor! Especially like getting rid of c() for getting multiple symbols on one line. Thanks.

    ReplyDelete
  5. Hey Milk Trader,

    Been following your blog for a while and am also an R user. I've managed to program out a back-testing system that works to test strategies vs. one security showing a list of trades/entries/exits based on rules. My new problem is a) an efficient way to build an equity curve (my profits are calculated using Van Tharp's R Multiple), and b) an efficient way to combine the test for multiple securities and generate a composite equity curve. I wonder if you've found any methods for conducting this kind of test?

    I've been chronicling my study over at http://techsystrader.blogspot.com. I'm fairly novice however my goal is to build a useful backtesting system in R.

    ReplyDelete
  6. @Jason I'll check out your blog. I do know that quantmod has a modeling function but I haven't used it yet. Likewise, I'm interested in using R for all this work instead of going to a proprietary system.

    ReplyDelete