# Correct way of making sharpe optimized portfolio?

I have monthly returns of about 977 securities of past 10 years.

If I keep the returns as it is i.e. I do not multiply by 100 and keep the returns as 0.1, 0.2 , -0.3, 1.2

then I get different results in the securities shortlisted if I have used returns that are multiplied by 100 i.e. 10, 20, -30, 120

If I used 100x multiplied returns I get more than 290 securities out of 977 shortlisted and if I use without the 100x multiple I get only 4 securities.

Not sure what is the correct method to apply sharpe optimization model. I was expecting not to concentrated and not to diversified portfolio.

Code:

library(RCurl)
library(lubridate)
library(quantmod)
library(dplyr)
library(reshape2)
library(zoo)
library(data.table)
library(xlsx)
library(plotly)

stocksDataPath <- "Monthly_All_Stocks"

totalPer = 100

#Rf = 100 * 0.00027      #Daily
#Rf = 100 * 0.001302     #Weekly
#Rf = 100 * 0.07   #Yearly
Rf =100 * 0.005654 #Monthly

stocksList[nrow(stocksList)+1,1] = "^NSEI"

#market index (nifty 50)
n50 <- read.csv(paste(stocksDataPath,   "\\^NSEI.csv", sep = "" ))

n50$$Ret <- 100 *n50$$Ret

inds <- 1
stocksRetData <- list()

for (i in 1:nrow(stocksList)){

d <- read.csv(paste(stocksDataPath, "\\", stocksList[i,1] , ".csv", sep="") )

d$$Ret <- 100 * d$$Ret

if (nrow(d)>=totalPer){

d$Name = stocksList[i,1] d <- tail(d,totalPer) stocksRetData[[inds]] <- d inds <- inds + 1 } } RM <- tail(n50$Ret, totalPer)

CALCData <- data.frame(
StockName = as.character(),
AriMean = as.numeric(),
Beta = as.numeric(),
Alpha = as.numeric(),
Variance = as.numeric(),
StdDev = as.numeric(),
SysRisk = as.numeric(),
UnSysRisk = as.numeric(),
stringsAsFactors = FALSE
)

for (i in 1:length(stocksRetData)){

betaVal = cov(RM,stocksRetData[[i]]$$Ret)/var(RM) Ri = mean(stocksRetData[[i]]$$Ret)

CALCData <- rbind(CALCData,

data.frame(
StockName = stocksRetData[[i]]$$Name[1], AriMean = Ri, Beta = betaVal, Alpha = Ri - (mean(RM)*betaVal), Variance = var(stocksRetData[[i]]$$Ret),
StdDev =StdDev(stocksRetData[[i]]$$Ret), SysRisk = StdDev(RM) * betaVal, UnSysRisk = StdDev(stocksRetData[[i]]$$Ret) - (StdDev(RM) * betaVal)
)

)

}

#---------------------------------------------------------------------------

CALCData$$MarketRiskPremium = CALCData$$AriMean - Rf
CALCData$$TreynorRatio = CALCData$$MarketRiskPremium/CALCData$Beta # Sort by Tryenor ratio in descending order CALCData <-CALCData[order(-CALCData$$TreynorRatio),] CALCData$$CVal = (CALCData$$MarketRiskPremium * CALCData$$Beta) / CALCData$UnSysRisk

CALCData$$CUMSUMCVal <- cumsum(CALCData$$CVal)

CALCData$$BetaSqrVar = (CALCData$$Beta ^2) / CALCData$$UnSysRisk CALCData$$CUMSUMBetaSqrVal = cumsum(CALCData$BetaSqrVar) CALCData$$Cutoff = ( var(RM)*CALCData$$CUMSUMCVal ) / (1 + var(RM) + CALCData$CUMSUMBetaSqrVal )

CALCData$$Diff =CALCData$$Cutoff- lag(CALCData$$Cutoff,1) CALCData$$Diff[is.na(CALCData$Diff)] <- 0 CALCData <- subset(CALCData,CALCData$Diff > 0)

CVal = tail(CALCData$Cutoff, 1) #Z=(C5/D5)*((E5/C5)-$$K$$1) CALCData$$ZVal = (CALCData$$Beta / CALCData$$UnSysRisk)/ ( (CALCData$$MarketRiskPremium / CALCData$Beta) - CVal)

sumofZVal = sum(CALCData$ZVal) CALCData$$InvProportion = 100 * round(CALCData$$ZVal /sum(CALCData$ZVal),3)

#write.csv(CALCData,paste("CALCData_", stocksDataPath ,"_", totalPer, "_Period_", "_", gsub(":","", Sys.time()),".csv", sep=""), row.names = FALSE)

• Are you solving your portfolio scheme numerically? Or are you applying a closed-form solution? Could you please provide some code related to your problem? :-) – Pleb Jun 12 at 8:28
• @Pleb added code for reference – Stupid_Intern Jun 12 at 8:33
• If you change the units for the stock returns, you must change the units for the Risk Free rate also. Then the solution should be exactly the same. – noob2 Jun 12 at 14:04
• @noob2 I did change it – Stupid_Intern Jun 12 at 14:09