% Clear existingclear all; % Load packagespkg load io;pkg load statistics;pkg load financial;% Grab data from Google% format = {Date,   open,   High,   Low,    close, Volume}connection = google;startdate=datenum('Jan 1 2013');enddate=datenum('Aug 27 2013');ticker= { 'AAPL', 'F'};% Grab the number of stocks for the requestn=length(ticker);frequency='d';% fetch returns the data in a matrix with in the columns date, open, high, low, close, adjusted close and volume% Attention: ticker is a cell array so you have to be careful using () vs {}. % Using () gives you a subset of a cell array, effectively another cell array. % On the other hand, using {} returns you the actual content of the cell array.for i=1:ndata=fetch(connection, ticker{i}, startdate, enddate, frequency);temp=data;closeprice(:,i)=temp(:,5);      % A(m,:) ist die m-te Zeile der Matrix A   A(:,n) ist die n-te Spalte der Matrix A.end% Convert the date values in a human readable format - one security is enoughdate(:,1)=temp(:,1);% Google puts the oldest date first so remember to flip the data closeprice=flip(closeprice);date=flip(date);% Convert datenum in a readable formatstartdate=datestr('Aug 1 2013',1);enddate=datestr('Aug 27 2013',1);% convert numerical date values in a human readable formatdate2=datestr(date);q% Berechnung der Tagesrenditenk=length(closeprice);  % Extrahieren der Kursvektoren je Aktie und abspeichern in einen einzelnen Vektorfor i=1:n   eval(sprintf('r%d=closeprice(:,i)',i)); end% k = 165 Values% n = 2 stocksfunction r = simpleRateReturn(r1)r = zeros(size(r1));%start at 2 otherwise loop will go out of boundsfor i = 2:length(r1)r(i)=(r1(i)-r1(i-1))/r1(i-1);end