- I was not very happy with the quality of the results
- The source code was not showing very nicely
- It was difficult to get a nice display, including for pictures and mathematical expressions
- I started to use Python almost exclusively
- R is a nice language, but it is not a general purpose language, some tasks are hard in R compared to Python
- At the other hand, Python has steadily improved in the area of data processing, with pandas providing something equivalent to the R dataframe
Jupyter was originally know as iPython but has evolved to support many programming languages, including R. This allows now to develop a notebook, possibly based on multiple languages, then convert it for posting, while keeping the original notebook available for people that wants a more interactive experience. The development process is much simpler that way that it used to be for earlier posts.
As an example, the rest of this post is this notebook converted to HTML. Note that the notebook contains both R and Python code interacting in an almost seamless way. How to achieve that result will be explained in later posts.
In [1]:
%load_ext rpy2.ipython
In [2]:
%%R -o x -o xik -o n -o pik
# figure 8.1 of Cover "Universal Portfolios"
library(logopt)
data(nyse.cover.1962.1984)
n <- nyse.cover.1962.1984
x <- coredata(nyse.cover.1962.1984)
xik <- x[,c("iroqu","kinar")]
nDays <- dim(xik)[1]
Days <- 1:nDays
pik <- apply(xik,2,cumprod)
plot(Days, pik[,"iroqu"], col="blue", type="l",
ylim=range(pik), main = '"iroqu" and "kinar"', ylab="")
lines(Days, pik[,"kinar"], col="red")
grid()
legend("topright",c('"iroqu"','"kinar"'),
col=c("blue","red"),lty=c(1,1))
In [3]:
print(x)
print(type(x))
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.ion()
plt.figure(figsize=(6,4))
plt.plot(pik)
plt.grid()