sect<-c("Healthcare","Basic Materials","Utilities","Financial Services","Technology","Consumer"
"Defensive","Industrials","Communication Services","Energy","Real Estate","Consumer
Cyclical","NULL")
mcap<-c("3 - Large","2 - Mid","1 - Small")
df_total = data.frame()
start <- as.Date("01-01-14",format="%d-%m-%y")
end <- as.Date("18-03-20",format="%d-%m-%y")
theDate <- start
while (theDate <= end){
for (value1 in sect){
for (value2 in mcap){
date=theDate
sector<-value1
marketcap1<-value2
newquery("Select * from table where date='%s' and sector='%s' and marketcap='%s'",date,sector,marketcap1)
topdemo <- sqlQuery(dbhandle,newquery)
df=data.frame(topdemo)
df_total <- rbind(df_total,df)
}
}
theDate <- theDate + 1
}
Instead of the "Select" query, in my program Im doing a few SQL computations. I need this code to run from 2014 to 2020 but it is taking a lot of time to execute it. Is there any way to decrease the execution time? The database has many stock prices for each market-cap and sector.