Sei sulla pagina 1di 19

Patrick Good: 10066896

Data Manipulation and Analysis Project.

The stock I chose to analyse was Dell Inc. (DELL), by choosing Dell I subsequently chose the
S&P500 as my reference Index as Dell was a constituent of this and I felt that this Index would
offer the best chance for accurate results.

Dell Inc. was the world leader in just in time stock control when they realised new ways to keep
manufacturing cost down for PC’s and Laptops. Dell was founded in Texas in 1984 and had
their IPO in 1988 reaching a market cap of $85 million.

Throughout the assignment focus was maintained on returns data from 1990 to 2009. In this
time, Dell experienced massive growth-specifically in the late 90’s and also felt the effects of
the Dot Com burst in the early 00’s. Dell’s share price has been significantly affected by world
events due to their market position and the financial crisis of 2008 also saw the share price
tumble. Dell currently trades at $14.54, a long way off their all-time high of $52.68 from
December 1999.

To allow for greater analysis of the effects of the frequency of returns data, I also chose to
analyse Hewlett Packard. The decision behind this was that HP and Dell are competitors in a
common technology market and are both constituents of the S&P500. By doing this, I believe
that I was better able to analyse the effects of the frequency of returns data on important
historical calculations.
Patrick Good: 10066896

1. Daily, Weekly and Monthly Returns Analysis on Dell Inc.

Figure 1 shows three plots, with the Daily, weekly and Monthly returns data for Dell Inc. over
a period of 20 years. The three plots below directly draw attention to the affect that the data
frequency has on the graphed information. The daily returns plot has the highest frequency of
data and this can be identified by the focus of returns around the 0% line. This is because of
the nature of the market where returns measured in a tight timeline will move about the mean.
A point to note, the mean daily returns for Dell Inc. over the 20 year period was 7.17%, as
shown in table 1. Analysing the daily returns plot, this result would be difficult to induce.

The weekly returns data shows less consistency around 0% returns in comparison to the daily
returns. The mean weekly returns as calculated by Matlab was 32.9% as shown in table 1. The
weekly returns show a more distributed returns profile for the 20 year period and offers a
clearer view of the higher returns available to potential investors.

The monthly returns data has a much lower frequency of data. The distributed plot conveys
less information than the daily and weekly plots. This would be considered a drawback to
analysis’s as the monthly plot would indicate that large returns were available from
investment in dell. The mean monthly returns calculated for Dell Inc. was 110.3%. This
result would have been significantly affected by the huge growth period that Dell Inc.
experienced in the late 90’s and is further discussed in section 2.

The results of the mean returns analysis shows a large variation in the results. Table 1 below
shows the means calculated for Dell Inc. in comparison to HP over the 20 year period. As the
frequency of data changed, we observe large changed in the values for mean return. Most
striking of these figures is the mean monthly returns for both Dell and HP. 110.3% and
90.65% returns over a monthly investment would suggest that investors always secured a
profit from their investment. To take the results of a mean returns analysis on a stock using
monthly data would produce highly skewed results. It is clear that the Dell and HP mean
monthly returns were greatly affected by the boom and other factors.

The weekly mean returns also tell the same story as the monthly returns. The frequency of the
data analysed produces skewed results as the time period of the data reduces the points of
information that need to be assessed to output true and fair results to potential investors.

    Daily Weekly Monthly

2
Patrick Good: 10066896

Mean Returns Dell Inc. 7.17% 32.89% 110.30%


  HP 4.67% 20.18% 90.65%
Table 1: Daily, Weekly and Monthly Returns for Dell Inc. and Hewlett Packard

Overall the daily returns seem to produce a more accurate portrayal of the mean returns
available to investors. Although one point to note that historical returns do not consider the
effect of company growth and periods of global growth as factors to compensate for when
analysing historical figures.

Daily Returns for Dell Inc. Weekly Returns for Dell Inc.
120 120
Daily Returns (%) Weekly Returns (%)

100 100

80
80

60

Returns (%)
Returns (%)

60
40
40
20

20
0

0 -20

-20 -40
90 92 94 96 98 00 02 04 06 08 10 90 92 94 96 98 00 02 04 06 08 10
Time in Years (1990 - 2009) Time in Years (1990 - 2009)

Monthly Returns for Dell Inc.


120
Monthly Returns (%)
100

80

60
Returns (%)

40

20

-20

-40
90 92 94 96 98 00 02 04 06 08 10
Time in Years (1990 - 2009)

Figure 1: Daily, Weekly and Monthly Returns for Dell Inc.

2. Trading Volume

3
Patrick Good: 10066896

Figure 2 shows the Daily, Weekly and Monthly Trading Volume of Dell Inc. over a 20 year
period. The trading volume plots immediately draw attention to the high volume of trading on
the stock between 1995 and 2000. As mentioned previously, this was a period of rapid growth
for Dell Inc. and subsequently during this period the stock price rose from $1 in January 1996
to $56.24 in March 2000.

The information available from the trading volume of a stock is invaluable when identifying
historical market activity. As shown in Figure 2, the large trading volume represented the
growth period in the life cycle of Dell were rapid expansion was taking place. Conversely,
another time when trading volume above normal in Figure 2 was during the financial crisis of
2008. Evidently, investors in Dell sold during the market collapse which can be verified by
looking at Figure 3 which showed a drop in share price at that time.

8 8
x 10 Trading Volume for Dell Inc. x 10 Weekly Trading Volume for Dell Inc.

8 Trading Volume for Dell Inc.


2.5
7 Increased trading volume
due to the growth
Increased trading volume experienced by Dell Inc.
6 due to the growth 2 between 1993 – 1999.
experienced by Dell Inc.
between 1993 – 1999.
Trading Volume

Trading Volume

5
1.5
4

3 1

2
0.5
1

92 94 96 98 00 02 04 06 08 92 94 96 98 00 02 04 06 08
Time in Years (1990 - 2009) Time in Years (1990 - 2009)

8 Monthly Trading Volume for Dell Inc.


x 10
Figure 2: Daily, Weekly and Monthly Trading Volume
1.8

1.6

1.4
Trading Volume

1.2

0.8

Interestingly to 0.6 note, the highest


recorded trading 0.4
volumes for Dell Inc.
0.2

was during the 92 94 96 98 00 02 04 06 08


early 90’s where the
Time in Years (1990 - 2009)
share price was still below $1. From
1998 – 2000 where the share price for
Dell increased greatly, this might suggest that institutional investors moved into Dell buying

Period of Rapid Growth

4
Patrick Good: 10066896

large quantities of stock once PC’s and Laptops became lucrative and profitable. 1995 marked
a significant point in Dell’s history when they released the first Lithium Ion battery which
made laptops more powerful and longer lasting which moved Dell to the forefront of the
technology world.

Figure 2 draws direct attention to the affect that data frequency has on plotted results.
Ignoring the overall trade volumes on the y axes, the shape of the plot over time holds steady
representing the overall trade volume on Dell Inc. over 20 years. From my analysis of the
different frequencies of the data collected, I believe that the weekly trading volumes would
represent the best plot to display. The Daily trading volume plot loses out as the shear
frequency of the plot results in an interpretation that the average trade each day was much
lower with certain days that had excessive trade volumes. The monthly data displays the
opposite effect where it could be interpreted that the trade volume was always high on the
stock and subsequently mis-read the information. The weekly data in figure 2 captures the
picture of the total trade volume. The plot displays the increased trade volume around Dell’s
growth period (1996 – 2000) and shows the slowdown in trade before the effect of the
financial crisis on the stock returns.

3. Regression Analysis

Figure 4 shows the Daily, Weekly and Monthly Returns on the S&P500 vs. Dell Inc. The
three plots are placed as such to allow easy comparison of the effects of data frequency on
different information.
5
Patrick Good: 10066896

The plot of the Daily Returns shows a clustered dataset where the returns on the equity and on
the index are all based about 0% with a ±4% variation for the market returns and ±15% peak,
excluding outliers, for Dell Inc.’s returns. The regression analysis implemented on the daily
returns data allowed me to calculate the Beta for the equity with respect to the market
(S&P500). Matlab offered the ability to extrapolate a formula to represent the linear
approximation of the data which gave me the beta for Dell over the last 20 years. The value of
beta calculated was 1.2 for the daily returns data. Similarly though Matlab analysis, the beta
for the daily returns was also calculated. Table 2 shows that the calculated beta was 1.961
which closely correlates to that of the linear approximation, with the difference most likely
coming from rounding errors.

Returns of the S&P500 Vs. Dell Inc. Returns of the S&P500 Vs. Dell Inc.

Returns(%) of the S&P500 Vs. Dell Inc. data 1


linear linear
100 100

80 80
Returns(%) for Dell Inc.
Returns(%) for Dell Inc.

Eqn. of the
60 Regression:
60
y = 1.1*x + 0.42
Eqn of the 40
40 Regression:
y = 1.2*x + 0.09 20
20

0
0
-20

-10 -8 -6 -4 -2 0 2 4 6 8 -10 -5 0 5 10 15 20
Returns(%) for S&P500 Returns(%) for S&P500

Returns of the S&P500 Vs. Dell Inc.

100 data 1
linear

80

60
Returns(%) for Dell Inc.

Eqn. of the
Regression:
y = 1.3*x + 1.6
40

20

-20

-10 -5 0 5 10 15 20
Returns(%) for S&P500

Figure 4: Daily, Weekly and Monthly Returns for the S&P500 Vs. Dell Inc. The Weekly
Returns in Figure
4 again show the returns on the equity vs. the returns on the market are clustered around 0%.
The frequency of the data in comparison to the daily returns has decreased greatly giving a
better perspective of the results plotted. In comparison to the daily returns plot, it is easier to
interpret the results from the plot. A linear regression was carried out on the data and a beta
was extrapolated as 1.1. Using Matlab, a value for beta was also calculated to be 1.0986
which is only a 0.1% error probably down to the rounding of figures to fit the plot.
6
Patrick Good: 10066896

Figure 4 also shows the monthly returns on the S&P500 vs. Dell Inc. The data is a lot more
spread out and the returns begin to form a bias away from the 0% position, unlike the plots
observed for the daily and weekly returns. The beta from the regression analysis was
calculated as 1.3 and the corresponding Matlab calculation was 1.28.

From my analysis of the Daily, Weekly and Monthly Returns on the S&P500 vs. Dell Inc. I
believe that taking weekly data would be the most efficient option. The frequency of the daily
data crowds the plot and it is difficult to fully analyse the information as the cluster extends
from ±4% on the market and ±10% for Dell Inc. The monthly data is very spread out and
offers no real conclusions on the results of the returns also. The monthly returns plotted are
varied and no real trend is developed with a large range of results shown.

The weekly data offers a high enough frequency that a clear picture is portrayed with respect
to the information on the weekly returns of the Market vs. Dell Inc. over 20 years. Figure 4
shows the weekly returns for 20 years and in comparison to the daily returns offers a better
overall picture of the results.

4. Returns Distribution

The distribution of returns shows the percentage of times the returns were at a certain level.
As seen in figure 5, the Daily, Weekly and Monthly distribution functions are graphed. Using
Matlab, I was able to calculate the Skewness and Kurtosis for each set of data. As shown on
the plot below, the values of the Skewness and kurtosis do not change greatly relative to the
data plotted.

The Kurtosis value for the Daily, Weekly and Monthly data varies from 6.5459 – 5.9967. The
value for the monthly data was 0.5 lower that the values of kurtosis for the daily and weekly
7
Patrick Good: 10066896

returns. Because of the close correlation of the results for daily and weekly returns, I believe
that using the monthly data as a reference for the distribution would not give the analyst
appropriate results. The value of Kurtosis for the Daily and weekly returns are closely
correlated. The daily kurtosis is 6.5072 and the weekly kurtosis is 6.5429. In keeping with the
previously analysed data, the weekly returns data offers a smoother and less noisy display of
results.

Normal Distrubution for Dell Inc.


0.09
Daily Returns
0.08 Kurtosis: 6.5072 Weekly Returns
Skewness: 1.7676 Monthly Returns
0.07
Probability of Returns (%)

0.06
Kurtosis: 6.5459
Skewness: 1.793
0.05

0.04
Kurtosis: 5.9967
Skewness: 1.6889
0.03

0.02

0.01

0
-50 -40 -30 -20 -10 0 10 20 30 40 50
Range of Returns (%)

Figure 5: Normal Distribution for Dell measured Daily, Weekly and Monthly

The Skewness values


calculated through matlab ranged from 1.6889 – 1.793. Similarly to the results for kurtosis,
the weekly data was the highest value for Skewness and monthly data was the lowest value.

The overall shape of the three different distributions would lead me to believe that choosing
the weekly data gives the user a better representation of the analysed data. The monthly data
distribution doesn’t offer enough information around the 0% Returns level, for which the
most volume of the returns is based. The Daily returns distribution does not offer any
information for returns past ±15% and subsequently focuses too much on the area of low
returns. The weekly data is a compromise between these two extremes. The data around 0%
give the user enough information to analyse the data without excluding the extreme returns
that occur occasionally.

8
Patrick Good: 10066896

5. Numeric Analysis

Table 2,3,4 and 5 below contain the calculated values from Matlab. The three tables show the
Daily, Weekly and Monthly Data. As an additional comparison, I chose to include Hewlett
Packard (HP) in the analysis versus the S&P500. HP is a competitor of Dell Inc. and is also a
constituent of the S&P.

The first factor calculated was the beta value. This is the relationship between the movements
in the returns relative to the movement of the market. The beta value was calculated in two
ways which gave the same results. The first way was through linear regression of the Returns
of the Market vs. the Returns of Dell Inc. and the second way was using the formula

9
Patrick Good: 10066896

Covariance (Index , Market )


β=
Variance

    Daily Weekly Monthly


Beta Dell Inc. 1.1961 1.0986 1.2834
  HP 1.1578 1.1869 1.5628
Table2: Daily, Weekly and Monthly Beta Calculations

The calculation of beta across Dell and HP shows some distinct differences. In both cases, the
Daily beta was much lower that the monthly betas with different trends occurring with the
weekly data. The differences observed for beta depending on what data set is an unusual
observation. This would suggest that taking the definition for beta, the returns on the equity
vary depending on the historical dataset analysed. Comparing the results of beta for Dell and
HP, there doesn’t seem to be a defined trend in the variation of the beta value. The
randomness of the results would suggest that any analysis of historical data would not offer an
accurate representation of the beta value for a stock as the result will depend on what
frequency the dataset was recorded.

The R2 value is a statistical measure that represents the percentage of the stocks movement
that’s explained by the movement in the market. As a result of this, the calculation of the R 2
value for Dell Inc. and HP shows similarities in their trends as shown in Table 3 below. From
Daily to Monthly frequency, the R2 value increases overall but dips in both cases for the
weekly dataset. The R2 value for Dell is low enough that we could argue rejecting the result
for beta across all the Dell datasets. The R2 value for HP is much higher than that of Dell.
This result would suggest that it is possible to accept the resultant beta that was calculated
from the returns of HP vs. the S&P500, as seen in table 2 above.

    Daily Weekly Monthly


2
R Dell Inc. 0.087 0.0642 0.0849
  HP 0.1637 0.1605 0.1865
Table 3: Daily, Weekly and Monthly R2 Calculations

The covariance is a measures the movement of multiple assets that move together over the
same period of time, and table 4 below shows this. Essentially a portfolio with a high
covariance suggests that the portfolio is not well diversified. The covariance for Dell and HP
with respect to the S&P500 differs greatly as the dataset frequency is reduced. This would
suggest that a stocks daily returns would not move in relation to the markets but as the

10
Patrick Good: 10066896

frequency reduces it would suggest over a longer time period the stocks will tend to follow
the S&P500.

    Daily Weekly Monthly


Covariance Dell Inc. 1.6489 6.2946 25.091
  HP 1.596 6.8006 30.5553
Table 4: Daily, Weekly and Monthly Covariance Calculations

The P Value represents a hypothesis that the variations in returns are a result of the movement
of the market in general. The high P Values as seen in table 5 below would suggest that the
hypothesis that the movement in the market returns affects the returns of Dell and HP can be
rejected. Across the daily, weekly and monthly datasets the high P Value means that the
returns experienced by Dell and HP are not a result of the market movement.

    Daily Weekly Monthly


P Value Dell Inc. 0.2064 0.2126 0.2405
  HP 0.2144 0.2206 0.2191
Table 5: Daily, Weekly and Monthly Covariance Calculations

Table 6 below shows the full range of data collected throughout the assignment comparing
Dell and Hewlett Packard to the S&P500 using Daily, Weekly and Monthly Returns Data.

6. Conclusion

From the analysis of the calculated data and plots of information collected, I believe that the
frequency of collected data is a crucial factor. Historical calculations over the same time
period at different frequencies showed large variations in results. The frequency of the returns
data had the greatest effect on the calculated value of beta, in my opinion. As beta represents
the affect the market returns has on equity returns, one would believe that this would be a
constant independent of the frequency of the data and table 2 showed the variations observed
for Dell Inc. and HP.

Overall I believe that the frequency of the collected data returns is an important factor in
research using the CAPM model. One should ensure that the same frequency of data is used

11
Patrick Good: 10066896

throughout experiments on this area as contamination of the results might lead to a rejection
of the research.

Appendix 1.

HP Vs. DELL Vs. S&P500


       
  Daily Analysis
  DELL Vs. HPQ DELL Vs. S&P500 HPQ Vs. S&P500
Beta 0.2621 1.1961 1.1578
R2 0.0342 0.087 0.1637
Mean Returns (Dell) - 7.17% -
Mean Returns (HP) - - 4.67%
Std Dev - 4.76 3.3594
Historical Volatility - 4.5569 3.0787
Variance 11.2859 1.3785 1.3785
12
Patrick Good: 10066896

Covariance 2.9579 1.6489 1.596


Kurtosis - 6.5072 3.0479
Skewness - 1.7676 0.7638
T Test 0 0 0
P Value 0 0.2064 0.2144
T Stat 0 -1.2635 -1.2417
       
  Weekly Analysis
  DELL Vs. HPQ DELL Vs. S&P500 HPQ Vs. S&P500
Beta 0.2702 1.0986 1.1869
R2 0.0341 0.0642 0.1605
Mean Returns (Dell) - 32.89% -
Mean Returns (HP) - - 20.%18
Std Dev - 10.3774 7.0922
Historical Volatility - 10.0499 6.5198
Variance 50.2988 5.7296 5.7296
Covariance 13.5911 6.2946 6.8006
Kurtosis - 6.6459 3.0805
Skewness - 1.793 0.7763
t test 0 0 0
p value 0 0.2126 0.2206
T Stat 0 -1.2468 -1.2253
       

  Monthly Analysis
  DELL Vs. HPQ DELL Vs. S&P500 HPQ Vs. S&P500
Beta 0.1367 1.2834 1.5628
R2 0.0277 0.0849 0.1865
Mean Returns (Dell) - 110.3% -
Mean Returns (HP) - - 90.65%
Std Dev - 19.477 16.0014
Historical Volatility - 18.7358 14.7048
Variance 379.3547 19.551 19.551
Covariance 51.8465 25.091 30.5553
Kurtosis - 5.9967 2.8789
Skewness - 1.6889 0.7167
t test 0 0 0
p value 0 0.2405 0.2191
T Stat 0 -1.1752 -1.2305
Table 6 – Table of the numeric results of the assignment from Matlab

13
Patrick Good: 10066896

Appendix 2.

%this code allows a user to analyse three sources (Daily, Weekly % and
%Monthly) of date specifically from Microsoft Excel. The code will %output
the important numerical results
%and also plot Normal Distribution and the Returns.

Equity_Select_Daily = uigetfile('*.csv;*.xls;*.xlsb;*.xlsm;*.xlsx','Select
the Daily Equity File');
Equity_Select_Weekly = uigetfile('*.csv;*.xls;*.xlsb;*.xlsm;*.xlsx','Select
the Weekly Equity File');
Equity_Select_Monthly =
uigetfile('*.csv;*.xls;*.xlsb;*.xlsm;*.xlsx','Select the Monthly Equity
File');

Equity_Load_Daily = xlsread(Equity_Select_Daily);
Equity_Load_Weekly = xlsread(Equity_Select_Weekly);
Equity_Load_Monthly = xlsread(Equity_Select_Monthly);

Length_Daily=length(Equity_Load_Daily);
Length_Weekly=length(Equity_Load_Weekly);
Length_Monthly=length(Equity_Load_Monthly);

Date_Convs_Daily = x2mdate(Equity_Load_Daily(:,1));
%%Excel date convention to matlab convention.
Date_Convs_Weekly = x2mdate(Equity_Load_Weekly(:,1));

14
Patrick Good: 10066896

Date_Convs_Monthly = x2mdate(Equity_Load_Monthly(:,1));

for i=2:Length_Daily;
Equity_Returns_Daily(i) = (((Equity_Load_Daily(i,5))-
(Equity_Load_Daily(i-1,5)))/(Equity_Load_Daily(i-1,5)))*100;
end

for i=2:Length_Weekly;
Equity_Returns_Weekly(i) = (((Equity_Load_Weekly(i,5))-
(Equity_Load_Weekly(i-1,5)))/(Equity_Load_Weekly(i-1,5)))*100;
end

for i=2:Length_Monthly;
Equity_Returns_Monthly(i) = (((Equity_Load_Monthly(i,5))-
(Equity_Load_Monthly(i-1,5)))/(Equity_Load_Monthly(i-1,5)))*100;
end

Mean_Index_Daily = mean(Equity_Returns_Daily);
Std_dev_Daily = std(Equity_Returns_Daily);

Mean_Index_Weekly = mean(Equity_Returns_Weekly);
Std_dev_Weekly = std(Equity_Returns_Weekly);

Mean_Index_Monthly = mean(Equity_Returns_Monthly);
Std_dev_Monthly = std(Equity_Returns_Monthly);

Skewness_Daily = skewness(Equity_Load_Daily(1:Length_Daily,5));
Kurtosis_Daily = kurtosis(Equity_Load_Daily(1:Length_Daily,5));

Skewness_Weekly = skewness(Equity_Load_Weekly(1:Length_Weekly,5));
Kurtosis_Weekly = kurtosis(Equity_Load_Weekly(1:Length_Weekly,5));

Skewness_Monthly = skewness(Equity_Load_Monthly(1:Length_Monthly,5));
Kurtosis_Monthly = kurtosis(Equity_Load_Monthly(1:Length_Monthly,5));

%This section plots the Normal Distribution of the Daily, Weekly and
%Monthly Returns of the chosen Equity. The 'hold on' function allows me to
%overlay the distributions for a clear display.
x = -50:1:50;
pdfNormal_Daily = normpdf(x, Mean_Index_Daily, Std_dev_Daily ); %
%Calculates the Probability Density Function
plot(x,pdfNormal_Daily,'--'); %
%necessary to graph the Normal Distribution.
title('Normal Distrubution for Dell Inc.')
xlabel('Range of Returns (%)')
ylabel('Probability of Returns (%)')
grid on
hold on

x = -50:1:50;
pdfNormal_Weekly = normpdf(x, Mean_Index_Weekly, Std_dev_Weekly); %
%Calculates the Probability Density Function
plot(x,pdfNormal_Weekly,'o'); %
%necessary to graph the Normal Distribution.
title('Normal Distrubution for Dell Inc.')
xlabel('Range of Returns (%)')
ylabel('Probability of Returns (%)')
grid on
hold on

15
Patrick Good: 10066896

x = -50:1:50;
pdfNormal_Monthly = normpdf(x, Mean_Index_Monthly, Std_dev_Monthly); %
%Calculates the Probability Density Function
plot(x,pdfNormal_Monthly,':'); %
%necessary to graph the Normal Distribution.
title('Normal Distrubution for Dell Inc.')
xlabel('Range of Returns (%)')
ylabel('Probability of Returns (%)')
legend('Daily Returns','Weekly Returns','Monthly Returns')
grid on
pause
hold off

% This section plots the Daily, Weekly and Monthly Returns of the chosen
% Equity. The 'hold on' function allows me to
% overlay the plots for a clear display.
plot(Date_Convs_Daily(1:Length_Daily),Equity_Returns_Daily,'r');
title('Equity Returns for Dell Inc.')
ylabel('Returns (%)')
xlabel('Time in Years (1990 - 2009)')
datetick('x',11)
grid on
axis tight
hold on

plot(Date_Convs_Weekly(1:Length_Weekly),Equity_Returns_Weekly,'g');
title('Equity Returns for Dell Inc.')
ylabel('Returns (%)')
xlabel('Time in Years (1990 - 2009)')
datetick('x',11)
grid on
axis tight
hold on

plot(Date_Convs_Monthly(1:Length_Monthly),Equity_Returns_Monthly,'b');
title('Equity Returns for Dell Inc.')
ylabel('Returns (%)')
xlabel('Time in Years (1990 - 2009)')
datetick('x',11)
grid on
axis tight
legend('Daily Returns (%)','Weekly Returns (%)','Monthly Returns (%)')
hold on

16
Patrick Good: 10066896

Appendix 2.

%This code is used to analyse the numeric values of an Equity Vs. a Related
%Index of the users choice. A GUI pops up to allow the user select the
%desired files with minimum effort. The program will plot the Returns and
%the trading volume.

Index_Select = uigetfile('*.csv;*.xls;*.xlsb;*.xlsm;*.xlsx','Select the


Index File');
Equity_Select = uigetfile('*.csv;*.xls;*.xlsb;*.xlsm;*.xlsx','Select the
Equity File');

Equity_Load = xlsread(Equity_Select);
Index_Load = xlsread(Index_Select);

Date_Range = Index_Load(3,1);

Length=length(Equity_Load);
%%Finds the length of the excel sheet to be analysed to give the loop the
appropiate termination point.

Equity_Date_Convs = x2mdate(Equity_Load(:,1));
%%Excel date convention to matlab convention.
Index_Date_Convs = x2mdate(Index_Load(:,1));

Index_Close = Index_Load(1:Length, 5);


Equity_Close = Equity_Load(1:Length, 5);

Equity_Trading_Volume = Equity_Load(1:Length, 6);


Index_Trading_Volume = Index_Load(1:Length, 6);

Equity_Returns = zeros(Length,1);

17
Patrick Good: 10066896

%%Establishes a matrix of zeros to speed up the iteration process by


allowing matlab to modify an existing matrix rather than creating the
matrix at the beginning of each iteration.
Index_Returns = zeros(Length,1);
for i=2:Length;
Equity_Returns(i) =
(((Equity_Load(i,5))-(Equity_Load(i-1,5)))/(Equity_Load(i-1,5)))*100;
Index_Returns(i) =
(((Index_Load(i,5))-(Index_Load(i-1,5)))/(Index_Load(i-1,5)))*100;
Difference_Squared(i) = (Equity_Returns(i) - Index_Returns(i))^2;
end

Mean_Return_Equity = mean(Equity_Returns);
Std_dev_Equity = std(Equity_Returns);
%%Equivalent to the Volatility of the Returns.
Std_dev_Index = std(Index_Returns);

Covar = cov(Index_Returns,Equity_Returns);
%%Matlab returns a 2x2 matrix from this function including the variance and
the covariance.
%%(1,1) is the Variance of the Stock Market Returns Vs. The Index Returns
Variance = Covar(1,1);
Covariance = Covar(1,2);
Beta = Covariance/Variance;
%%Measure of the sensitivity of rates of return on a portfolio or a given
stock compared with rates of return on the market as a whole

RSquared = Covariance/((Std_dev_Index)*(Std_dev_Equity));
%%example, an r-squared of 0.08 shows that 80% of a security's return is
the result of changes in the market --
%%specifically that 80% of its gains are due to market gains and 80% of its
losses are due to market losses.
%%The other 20% are the result of factors particular to the security
itself.
x1 = Index_Returns;
X = [ones(size(x1)) x1];
[b,bint,r,rint,stats] = regress(Equity_Returns,X);
%%b Represents a vector that estimates for a multilinear
%%regression of the responses in y on the predictors in X.
%%bint is a 2x2 matrix that represents the conficence levels
%%The first column contains lower bounds and the second column
%%contains the upper confidence bounds.
%%r is the residuals
%%rint returns a matrix that can be used to diagnose outliers.
%%stats returns a 1-by-4 vector stats that contains, in order, the R2
statistic,
%%the F statistic and its p-value, and an estimate of the error variance.
Sum_Diff = sum(Difference_Squared);
Historical_Volatility_Equity = (sqrt(Sum_Diff/(Length-1)));
%%The historical volatility (HV) is the
%%average variance from the mean the standard deviation.

t_test = ttest2(Index_Returns,Equity_Returns);

plot(Equity_Date_Convs,Equity_Returns,'g')
title('Returns of the S&P500 Vs. Dell Inc.')
xlabel('Time in Years (1990 - 2009)')
ylabel('Returns(%)')
datetick('x',11)
grid on

18
Patrick Good: 10066896

axis tight
hold on

plot(Equity_Date_Convs,Index_Returns,'r')
title('Returns of the S&P500 Vs. Dell Inc.')
xlabel('Time in Years (1990 - 2009)')
ylabel('Returns(%)')
datetick('x',11)
grid on
axis tight
legend('Returns(%) on Dell Inc.','Returns(%) on the S&P500')
pause
hold off

Trading_Volume = Equity_Load(1:Length, 6);


plot(Equity_Date_Convs,Trading_Volume)
title('Trading Volume for Dell Inc.')
xlabel('Time in Years (1990 - 2009)')
ylabel('Trading Volume')
datetick('x',11)
grid on
axis tight
legend('Trading Volume for Dell Inc.')
pause

Returns_Scatter = plot(Index_Returns,Equity_Returns,'.');
%%Scatter Plot of the returns of the Index Vs. Equity.
title('Returns of the S&P500 Vs. Dell Inc.')
xlabel('Returns(%) for S&P500')
ylabel('Returns(%) for Dell Inc.')
grid on
legend('Returns(%) of the S&P500 Vs. Dell Inc.')
axis tight

19

Potrebbero piacerti anche