Reputation:
I have a .csv file which contains some data e.g. date(30/10/2013), closePrice(361.08), volume(4500014), openPrice(362.62), highPrice(365), lowPrice(358.65). The file contains data of 2510X6, I want to plot a chandelle-stick chart can someone help me?. This is what i done:
fid = fopen('Amazon.csv');
HDRS = textscan(fid,'%s %s %s %s %s %s',1, 'delimiter',',');
DATA = textscan(fid,'%s %f %f %f %f %f','delimiter',',');
fclose(fid);
outCell = cell(size(DATA{1},1), length(HDRS));
for i = 1:length(HDRS);
if isnumeric(DATA{i});
outCell(:,i) = num2cell(DATA{i});
else
outCell(:,i) = DATA{i};
end
end
candle (outCell{:,5}, outCell{:,6}, outCell{:,2}, outCell{:,4}, 'b', outCell{:,1});
When running the file i get a error saying Error using candle Too many input arguments
. i am using cell of array because i have date and to convert date into vector I decide to use cell of array.
Upvotes: 1
Views: 961
Reputation: 9075
I found the following way to do this:
Firstly, I observed that you need date in the column vector format and not a cell
. Only way to achieve that is to convert date into some numerical representation. That's exactly what datenum
does. Example as follows:
DateString = '11/12/2013';
formatIn = 'mm/dd/yyyy';
datenum(DateString,formatIn)
ans =
735550
Convert all your dates in this format. Next, I feel that if you construct the time series object, it would be much easier to plot as shown here. This needs a financial time series object to work. No problem. It can be constructed as shown here. In this case, I believe it can be constructed as (dummy example):
dates={'11/12/2013';'11/13/2013'}
higPrice=[100;100]
lowPrice=[10;10]
closePrice=[90;80]
openPrice=[80;70]
%construct a financial time series object
tsobj = fints(datenum(dates,formatIn), [higPrice lowPrice closePrice openPrice], {'high','low','close','open'}) %put in correct order
candle(tsobj); %I get the plot
EDIT: I forgot to mention that if I try to give any other names than 'high','low','open','close'
it doesn't work. For example, I tried with 'highPrice','lowPrice','openPrice','closePrice'
. I do not know the reason for this as I am also using candle
for the first time.
Upvotes: 0
Reputation: 15349
Curly-bracket derefencing, as in outCell{:, 5}
in your call to candle
, expands to what Matlab calls a "comma-separated list". Whenever you see curly-bracket dereferencing, you can think of it as being exactly equivalent to typing out the separate elements that are implied, separated by commas---so if size(outCell, 1)
is 3, then this is as if you had typed outCell{1, 5}, outCell{2, 5}, outCell{3, 5}
. That's three input arguments to candle
right there, where you thought you were passing just one.
I'm unfamiliar with candle
itself, but if it wants a single-column cell array as its first argument, then the way to get a single-column cell array out of outCell
is to slice it with ordinary round-bracket dereferencing: outCell(:, 5)
If on the other hand candle
wants a numeric vector rather than a cell array, you can say cell2mat(outCell(:, 5))
. Another way (and this second example is where the power of curly-bracket dereferencing and comma-separated lists becomes apparent) would be to say [outCell{:, 5}]'
- that's a comma-separated list, caught inside square brackets, which means horizontal concatenation of the elements.
Upvotes: 1