Multi factor model
The multi factor model can be used to decompose returns and calculate risk. The factors are constructed using pricing, fundamental, and analyst estimates data. I will use Systematic Investor Toolbox for this section.
The gzcon()
function creates a connection and reads data in compressed format. Once we create a connection, we also have to close the connection.
The following commands explain this:
> con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb')) > source(con) > close(con)
The following function is used to fetch Dow Jones components data from http://money.cnn.com and join()
is taken from Systematic Investor Toolbox:
>dow.jones.components<- function(){ url = 'http://money.cnn.com/data/dow30/' txt = join(readLines(url)) temp = gsub(pattern = '">', replacement = '<td>', txt, perl = TRUE) temp = gsub(pattern = '</a>', replacement = '</td>', temp, perl = TRUE) temp = extract.table.from.webpage(temp, 'Volume...