Find the rate of change of data over specific increments of time

조회 수: 6 (최근 30일)
Lukyan
Lukyan 2022년 10월 27일
답변: David Hill 2022년 10월 27일
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
Lukyan
Lukyan 2022년 10월 27일
That was my initial thought, but how do I create a vector as such? I'm very new to matlab so I am having trouble making a function that takes the difference of the first and last day and does it for all the available data.
Lukyan
Lukyan 2022년 10월 27일
I want my final graph to look like the graph of ROC from this website, using that formula.

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2022년 10월 27일
data = readtable('TSLA_STOCK.csv');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
idx=find(diff(month(data.Date)));
monthlyClose=data.Close(idx);
ROV=diff(monthlyClose)./monthlyClose(1:end-1)*100;
plot(ROV)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by