Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to Plot Stock Returns on a Chart
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ryan  
View profile  
 More options Nov 15 2012, 8:31 am
Newsgroups: comp.soft-sys.matlab
From: "Ryan " <ryanshu...@gmail.com>
Date: Thu, 15 Nov 2012 13:31:19 +0000 (UTC)
Local: Thurs, Nov 15 2012 8:31 am
Subject: How to Plot Stock Returns on a Chart
Hello everyone.  I am trying to get this code working:

% [num,txt] = xlsread('C:\Program Files\MATLAB\R2012a\StockSymbols.xls')
% or another alternive: Browse file location

[f, p] = uigetfile({'*.xls';'*.xlsx'},'Pick StockSymbols file');
filename=fullfile(p,f);
[num,txt] = xlsread(filename);

% Get stocks
DATE = txt(2:end,1); % Date begins from second row

% Sort data in case dates are not in chronological order
[DATE_num,sortIndex] = sort(datenum(DATE,'mm/dd/yy')); % no hour,minute and second in your date data

BA = num(sortIndex,1);
BAC = num(sortIndex,2);
CAT = num(sortIndex,3);
CSCO = num(sortIndex,4);
DIS = num(sortIndex,5);
GE = num(sortIndex,6);
HD = num(sortIndex,7);
IBM = num(sortIndex,8);
JPM = num(sortIndex,9);
KFT = num(sortIndex,10);
KO = num(sortIndex,11);
MMM = num(sortIndex,12);
MSFT = num(sortIndex,13);
PFE = num(sortIndex,14);
PG = num(sortIndex,15);
T = num(sortIndex,16);
VZ = num(sortIndex,17);
XOM = num(sortIndex,18);

% DATE_num = datenum(DATE,'dd/mm/yy'); % no hour,minute and second in your date data
hf=figure('Units','normalized','Position',[0.05 0.05 0.9 0.7]);
plot ( DATE_num , BA , 'r'), hold on, grid on % hold if you want to plot on the same figure, add grid
title('Stock Symbols');
xlabel('Dates');
ylabel('Stock Symbols ($)');

plot ( DATE_num , BAC, 'b')
plot ( DATE_num , CAT ,'k')
plot ( DATE_num , CSCO, 'g')
plot ( DATE_num , DIS, 'm')
plot ( DATE_num , GE, 'c')

% Add legend if wanted
legend('BA','BAC','CAT','CSCO','DIS','GE','Location','Best')

% Set axes labels
 mindate=min(DATE_num);
 maxdate=max(DATE_num);
 ha=get(hf,'CurrentAxes');
 set(ha,'XTickLabelMode','manual','XTickMode','manual','XLimMode','manual',. ..
    'XLim',[mindate-15 maxdate+15],'XTick',linspace(mindate,maxdate,10));
% % %  xticklabels=datestr(get(ha,'XTick'),24); % Will be used to label the X axis, format is dd/mm/yyyy
% % %  set(ha,'XTickLabel',xticklabels);
% % %  
dateaxis('x',1);

All it does not is open a chart, but nothing gets plotted.  I don't get any errors.

Below is a sample file to download and put in the Matlab folder (so you don't have to spend a lot of time creating your another Excel file).
http://www.mediafire.com/view/?gjd29zoo7p4c8kw


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Goddard  
View profile  
 More options Nov 15 2012, 10:10 am
Newsgroups: comp.soft-sys.matlab
From: "Phil Goddard" <p...@goddardconsulting.ca>
Date: Thu, 15 Nov 2012 15:10:19 +0000 (UTC)
Local: Thurs, Nov 15 2012 10:10 am
Subject: Re: How to Plot Stock Returns on a Chart
Your spreadsheet does not have the same format as the format required by the code you show.
Your first column are numbers not dates (yes they represent dates, but they are already numbers).
Hence the txt variable only has one row (the column headers) and
>> DATE = txt(2:end,1);

is empty.
Hence your data variables are empty and there is nothing to plot.

You need to change your initial date/data processing to reflect your actual data file.

Phil.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan  
View profile  
 More options Nov 15 2012, 10:28 pm
Newsgroups: comp.soft-sys.matlab
From: "Ryan " <ryanshu...@gmail.com>
Date: Fri, 16 Nov 2012 03:28:05 +0000 (UTC)
Local: Thurs, Nov 15 2012 10:28 pm
Subject: Re: How to Plot Stock Returns on a Chart
Oh, yeah, you are right.  I thought those dates had to numbers.  Anyway, how did you determine what the problem was.  I was stepping through the code; using Breakpoints and tapped the F11 key so many times...I couldn't figure it out.  How did you figure it out???


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Goddard  
View profile  
 More options Nov 16 2012, 12:40 pm
Newsgroups: comp.soft-sys.matlab
From: "Phil Goddard" <p...@goddardconsulting.ca>
Date: Fri, 16 Nov 2012 17:40:23 +0000 (UTC)
Local: Fri, Nov 16 2012 12:40 pm
Subject: Re: How to Plot Stock Returns on a Chart

I executed

[num,txt] = xlsread('StockSymbols.xls');

and noticed that txt only had one row in it => no dates.
Then I opened the Excel file (in Excel not MATLAB) and confirmed that there are no dates represented as text.

Phil.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan  
View profile  
 More options Nov 16 2012, 10:31 pm
Newsgroups: comp.soft-sys.matlab
From: "Ryan " <ryanshu...@gmail.com>
Date: Sat, 17 Nov 2012 03:31:06 +0000 (UTC)
Local: Fri, Nov 16 2012 10:31 pm
Subject: Re: How to Plot Stock Returns on a Chart
OK!  Thanks for the help with this!!  I really appreciate it!!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »