[R-SIG-Finance] Calculating ROI correctly and using chart.CumReturns()

david hilton shanabrook davidshanabrook at icloud.com
Sat Mar 7 15:56:44 CET 2015


I am trying to calculate return on investment for stocks. I think this is right, but don’t know how to test for accuracy. The code calculates several things: return on investment: (close to close), buy on close sell next day on open, short sell, short sell day trading. Maybe this will make it clearer:

          library(quantmod)
         library(PerformanceAnalytics)
        getSymbols('F', src='yahoo',from='2015-01-01')
        data <- get('F')
        adjD <- adjustOHLC(data, symbol.name='F')
        
        #calculate normal investment return
        clcl <- Delt(Lag(Cl(adjD)), Cl(adjD), type='log')
        chart.CumReturns(clcl)
        
        #then to calculate returns from previous day close to next day open
        clop <-  Delt(Lag(Cl(adjD)), Op(adjD), type='log')
        chart.CumReturns(clop)
        
        #then to calculate stock short
        clopSh <-  Delt(Cl(adjD), Lag(Cl(adjD)), type='log')
        chart.CumReturns(clopSh)
        
        #then to calculate day trade short, stock open to close
        opclSh <-  Delt(Cl(adjD), Op(adjD), type='log')
        chart.CumReturns(opclSh)

Suggestions? Especially concerned how I am calculating short sell.


	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list