Thursday, February 28, 2013

Shading and Points with xtsExtra plot.xts

For some reason, I feel like have much better control with plot.xts function from the xtsExtra package described here over some of the other more refined R graphical packages. Maybe, it is just my simple mind, but recently I wanted to shade holding periods with points for buy and sale dates. With plot.xts from xtsExtra I was able to quickly and easily generate the following plot. I did have to slightly amend the original plot.xts function as seen here, but it seemed more natural and like much less of a struggle.

plot of chunk unnamed-chunk-1

I also enjoyed writing this post almost entirely in R markdown.

R code from Github:

Thursday, February 21, 2013

Additional Plots on French Breakpoints as Valuation

I feel like there might be some merit in Slightly Different Measure of Valuation using Ken French’s Market(ME) to Book(BE) Breakpoints by percentile to offer an additional valuation metric for US stocks.  I thought some additional plots might help me flesh out the concept.  This plot struck me as particularly helpful.

From TimelyPortfolio

In the next iteration, I hope to add a look at prospective drawdown or returns.  However, I struggle since the last 30 years all have basically exhibited historical overvaluation.  Since 1926, no period of overvaluation has lasted longer than 14 years except the last 30.

Thanks to the post from http://timotheepoisot.fr/2013/02/17/stacked-barcharts/ which helped me use much more appealing colors than the default lattice set.


R code from GIST:

Wednesday, February 20, 2013

Another Way to Look at Vanguard and Pimco

I like the results of the analysis shown in my post Applying Tradeblotter’s Nice Work Across Manager Rather than Time, but I was not satisfied that the plot allowed a quick summary comparison of the two massive fund complexes.  I am much more pleased with this Ecdf plot from the HMisc package.

From TimelyPortfolio

R code at GIST:

Tuesday, February 19, 2013

Onepager Now with knitR

Since at some point I had trouble with a conflict between knitr and the latex package textpos, I used the lesser Sweave in Another Experiment with R and Sweave.  I ran the Sweave2knitr command and discovered that textpos and knitr play well together now.  Here is the result using knitr (go to https://www.box.com/s/4nftk6qpa0cugapmncsn if the embed does not show below):

.rnw source file from Gist

Tuesday, February 12, 2013

Another Experiment with R and Sweave

The R package PApages is a great start towards addressing the very common problem of internal and external reporting in the money management industry.  Advent's APX, Axys, and Black Diamond and the up and coming extremely well-connected and well-funded Addepar provide basic and acceptable reporting but generally don’t provide the full set of risk and return metrics that I would expect.  Since the very successful GSOC projects with PerformanceAnalytics …Now With More Bacon (2008)! and New Attribution Functions for PortfolioAnalytics, we have a comprehensive and robust set of risk, return, and attribution measures in R.  Combined with the near limitless graphical abilities of R with xtsExtra, ggplot, lattice, and base graphics, R seems to offer one of the best platforms for reporting, so I’ve committed myself to continue my series http://timelyportfolio.blogspot.com/search/label/reporting exploring various reporting options in R.

This is a fairly crude sketch of something we can accomplish easily with R, Sweave, and PerformanceAnalytics.  I hope to itergreat to something a little more compelling.  If the embedded pdf does not work below, please see at https://www.box.com/s/xpfn3rjwwmv8aftmkbyi.

R Sweave file from GIST:

Sunday, February 3, 2013

Japanese Government Bonds (JGB) Total Return Series

In a follow up to Yen and JGBs Short-Term vs Long Term and a series of posts on Japan, I thought the Bloomberg article "Japan Pension Fund’s Bonds Too Many If Abe Succeeds, Mitani Says" was particularly interesting.  It is difficult to find a total return series for the JGBS, so here is an example of how we might construct it in R with the JGB 9 year. Using the 9 year gets us about a decade more data than the 10 year.  The calculation is not perfect but it gets us very close.

The Japanese Pension Fund (GPIF) has been spoiled by a very pleasant ride with their JGBs.

From TimelyPortfolio

R code from GIST:

Friday, February 1, 2013

Yen and JGBs Short-Term vs Long Term

I have read some articles arguing that the recent move in the Japanese Yen is overdone.  However, considering the short-term without regard to the long-term context is naïve and potentially dangerous.  Although I do not have significant proof, I believe long-term mean reversion can completely dominate short-term mean reversion hopes.  Just to provide some longer-term context, I thought I would offer some graphical aids.

From TimelyPortfolio

In my mind, the Yen selloff is only in its infancy.  For the move to truly engage, I think we need Japanese Government Bond (JGB) yields to move higher also, and if it does we are in a different paradigm than the last 20 years.  But, what do I know?

R code from GIST:

Wednesday, January 30, 2013

Approaching the Zero Bound - Bonds

As bonds approach the artificial zero bound, where do we go next especially after the record setting +30% in 2011?  The rolling 250-day total return has rarely gone negative since the inception of the Vanguard Funds VBMFX and VUSTX.  I am intentionally an ex-bond fund manager, so I am very interested.

From TimelyPortfolio
From TimelyPortfolio

R code in GIST:

Monday, January 28, 2013

Applying Tradeblotter’s Nice Work Across Manager Rather than Time

Ever since I saw the very helpful distribution page first presented in Download and parse EDHEC hedge fund indexes, I have used it liberally.  Now that it is has been functionalized (Visually Comparing Return Distributions), I thought I would amend it slightly to compare distributions of returns across managers rather than time.  As a simple example, I compared the mutual funds offered by Vanguard and Pimco.  This amended function might be very helpful for internal performance monitoring of separately managed accounts across external or internal money managers.  Also, for the purposes of composite dispersion, this might be a good beginning summary look.

I like what I did in Pretty Correlation Map of PIMCO Funds, but this time I wanted to get the performance data directly in a table rather than calculating performance from multiple calls to the getSymbols function.  R can easily load these tables, but I got lazy and imported the tables into Excel https://docs.google.com/file/d/0ByeeEIaS0AOsRE1OeWk2VmFFVUU/edit and then cleaned them up with some old fashioned pivot tables.  When finished data munging, I copied and pasted into a data sheet to save as .csv (could have used R again to get the data directly from Excel), so I could publish through Google Docs for anyone that wanted to replicate what I have done.

Pimco and Vanguard Mutual Funds 1 Year Performance
From TimelyPortfolio
Pimco and Vanguard Mutual Funds YTD 2013 Performance
From TimelyPortfolio

Now, I’d like to incorporate another fine piece of work Tracking Number of Historical Clusters into this analysis, but I’ll save that for another post.

Code from Gist:

Wednesday, January 16, 2013

Slightly Different Measure of Valuation

I grow tired of the tried and true standard measures of valuation, and from time to time I try to think of alternate methods.  One thought was to analyze Ken French’s Market(ME) to Book(BE) Breakpoints by percentile.  We can see by year at what level is a stock considered cheap relative to the universe.  As these breakpoints move higher, the market is willing to pay a higher price.  In reverse, as these breakpoints move lower, stocks fetch a lower price or can be considered cheaper.  Since there are 20 fifth percentiles, a horizon plot can provide a good overall look at this measure of valuation.

Here is a horizon plot of absolute ME/BE valuation by fifth percentile since 1926.

From TimelyPortfolio

For a more representative look, let's plot a horizon chart of the ME-BE / historical mean - 1.

From TimelyPortfolio

For one more non-horizon look, we can use an xyplot.

From TimelyPortfolio

In theory, I think this could provide yet another gauge of the cheapness of stocks, but of course, there is lots of research to be done.

R Code from Gist: