Since you are new, let us show you how Trendy works.

Close-button

Percentage change of several stocks (trailing 90 days)

  • Created by: James Kristoff
  • Latest result: Plot created
  • Created on: 24 Jul 2012

Included from trend description:

This is a trend to track several stocks in which I invest.

It also includes a weighted average line to track the average movement in these stocks.

I have updated the plot to include a cumulative % change in the form of a number being displayed on the plot, as well as a dotted line showing the average % change.

Plot Image
% Stock Tracker
%   time vector is: time1769
%   data vector is: data1769
time1769 = time1769(end-90:end);
data1769 = data1769(end-90:end,:);

% Official colors of The Mathworks
colors = [ 18,  86, 135;...    % Blue
          107, 111,  42;...    % Green
          210, 120,   0;...    % Orange
          120,  20,  20;...    % Red
          250, 250, 250]./255; % White

ryg    = [120,  20,  20;...    % Red
          255, 255,   0;...    % Yellow
            0, 150,   0]./255; % Green


% Create a custom AXES
ha = axes('ColorOrder', colors,...
          'color',     [85,85,85]./255);

time1769_orig = time1769;
time1769 = time1769(~isnan(data1769(:,1)));
data1769 = data1769(~isnan(data1769(:,1)),:);

% plot the data
h = line(time1769-1, data1769,...
        'Parent',    ha,...
        'LineWidth', 1);

set(h, {'Marker'}, {'s', '+', 'o', '*', 'none'}');
set(h(1), 'MarkerFaceColor', colors(1,:));

%h = bar(ha, floor(time1769), data1769);
%colormap(colors);
%set(get(h(1),'baseLine'), 'LineStyle', '--');
%set(ha, 'Color', [85,85,85]./255);

% set the x-axis to show dates
xlim([min(time1769(:))-5 max(time1769(:))+5])
datetick('keeplimits', 'keepticks')

% set the y-axis limits
%ylim([-2.5 3]);
ylim([min(data1769(:))*1.20 max(data1769(:))*1.45])

% label the y-axes
ylabel('%-Change');

% create a legend for the data
legend(h, {'ODVYX';...
           'OAKBX';...
           'MLAIX';...
           'VINIX';...
           'WA'},...
           'Orientation', 'horizontal')

% Gradiant of colors from red to green
%colorGrad = [[255:-11/17:201, 200:-29/85:171, 170:-2:0];...
%             [0:2:170, 171:29/85:200, 201:11/17:255];...
%             zeros(1,256)]/255;

% average value of the weighted average for all history
avg = mean(data1769(:, end));
cumRate = prod(data1769(:,end)./100+1).*100-100;
CoL = 3.5; % cost of living increase

colorInd = sign(avg)+2;

% calculate index in the color gradient matrix
%colorInd = round(((meanRate-3.5)/abs((3.5+meanRate)/2))+1.5)*64;

% plot a dashed line at zero and a dotted line at overall avg
hold on;
line(get(gca,'XLim'), [0, 0], 'LineStyle', '--', 'Color', 'k');
line(get(gca,'XLim'), [avg, avg], 'LineStyle', ':', 'Color', ryg(colorInd,:), 'LineWidth', 1);

% plot Cumulative Rate
colorInd = sign(cumRate - CoL)+2;
arrows = {'\downarrow ','','\uparrow '};
lims = get(gca, 'XLim');
text(lims(1)+diff(lims)*0.05, max(data1769(:))*1.125, [arrows{colorInd}, sprintf('%3.2f%%',cumRate)], 'Color', ryg(colorInd, :), 'FontSize', 12, 'FontWeight', 'bold')

% Plot a vertical line on each payday
vecOfDates = datevec(time1769_orig);
payDayInds = find(vecOfDates(:, 3)==7|vecOfDates(:, 3)==22);

time = [time1769_orig,time1769_orig];
for i = 1:length(payDayInds)
  line(time(payDayInds(i),:), get(gca,'YLim'), 'LineStyle', '--', 'Color', 'k');
end

set(ha, 'XTick', time(payDayInds,1))
set(ha, 'XTickLabel', datestr(time(payDayInds,1), 'mmm-dd'))

hold off;
Tags:

    Add Tags


    0 comments