Find the rate of change of data over specific increments of time
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
David Hill
2022년 10월 27일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
