from daily returns to weekly, monthly or annual ones
//////////////////////////////////////
Let us convert WMT daily returns to monthly ones as an example. 

 Step 1: collect daily data
         >x=getDailyPrice("wmt")
         >saveYan(x,"c:/temp/wmt.csv")
            [1] "Your saved file is ==>c:/temp/wmt.csv"
             
 Step 2: Retrieving the data set into Excel
         
 Step 3: estimate daily log return by applying =ln(Pt/pt-1)
         where pt   is the price at day t
               pt-1 is the price at day t-1

 Step 3: Generate a YYYYMM column by applying the following formula

           =year(date)*100 + month(date)

          where date is the date cell

 Step 4: Click "Insert" on the menu bar, then "PivotTable"

         chose YYYYMM as Row Labels
               LOG ret as Values

 Step 5: for Values, choose sum  
         [summation of all daily log return is the log monthly return]

 Step 6: we could convert log return into percentage return
        R(%) = exp(logRet)-1
//////////////////////////////////////

Portfolio optimization 
//////////////////////////////////////
require(fPortfolio)
require(tseries) 
d<-SMALLCAP.RET[,c("BKE","GG","GYMB","KRON")] 
k<-portfolio.optim(d) 

print(k[1])
print(sum(unlist(k[1])))

# another example 
library(fPortfolio)
begdate<-as.Date('1978-01-01')
enddate<-as.Date('2009-12-01')

stock1<-.monthlyRetTickerAsRet('IBM') 
stock2<-.monthlyRetTickerAsRet('WMT')
sp500 <-.monthlyRetTickerAsRet('^GSPC') 

d<-merge(stock1,stock2) 
d2<-subset(d,d[,1]>=begdate & d[,1]<=enddate) 
d3<-merge(d2,sp500)

data<-d3[,2:4] 
data<-as.matrix(d3[,2:4])
k<-portfolio.optim(data) 

print(k[1])
//////////////////////////////////////

A minimum-variance portfolio 
//////////////////////////////////////
library(fPortfolio)
d<-SMALLCAP.RET
d2<-d[, c("BKE","GG","GYMB","KRON")] 
f<-portfolioFrontier(d2) 

frontierPlot(f,pch=19,xlim=c(0,0.25), ylim=c(0,0.035)) 
grid() 
abline(h = 0, col = "grey") 
abline(v = 0, col = "grey") 
minvariancePoints(f,pch=19,col="red")

//////////////////////////////////////