Find the rate of change of data over specific increments of time
6 views (last 30 days)
Show older comments
I am working on a project where I need to analyze stock data. I decided to create a graph of the change of stock prices over time. I want the graph to be the rate of change of tesla close prices over one month time intervals. However, I am having trouble creating the rate of change vector as I do not know how to make the intervals work. My data is day by day but I want the vector to be the difference from the currMonth to currMonth-1. I don't have much so far, but if I only had the rate of change vector, plotting everything else would be simple. Basically, I want to graph the first derivative of the close prices in one month increments and display that data of a 10 year range.
Thank you so much.
clear
clc
clf
%import data set TSLA.csv
data = readtable("TSLA_STOCK.csv");
%get vector of tesla close prices
closePrices = data.Close;
%Convert dates into durations
data.MONTH = month(data.Date);
%rate_of_change_of_close_price = diff(closePrices)./diff(data.MONTH)
% create plot with axis labels, title, and grid
%plot(tslaStock.Date, rate_of_change_of_close_price, "-")
%xlim([datetime(2012,11,24,8,40,59)...
% datetime(2019,4,19,16,40,59)])
%ylim([3 536])
%xlabel('Year')
%ylabel('TSLA Price')
%title('TSLA price per share vs Time')
%grid on
3 Comments
Accepted Answer
David Hill
on 27 Oct 2022
data = readtable('TSLA_STOCK.csv');
idx=find(diff(month(data.Date)));
monthlyClose=data.Close(idx);
ROV=diff(monthlyClose)./monthlyClose(1:end-1)*100;
plot(ROV)
0 Comments
More Answers (0)
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!