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

7 ビュー (過去 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 Center および File ExchangeFinancial Toolbox についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by