Compute operation with different index (part II)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Attilio Pittelli
am 27 Sep. 2021
Beantwortet: Walter Roberson
am 27 Sep. 2021
Good morning,
i've this table and i would like to build a function, where i could insert the time series as input and another input, an integer "n", that has a function of a loockback period.
example: Adj_Close(today) - Adj_Close(lookback) and i would like to apply to the all time series
example data in the attchment
2 Kommentare
Image Analyst
am 27 Sep. 2021
Give a small example with actual data and show what the output should look like.
Akzeptierte Antwort
Walter Roberson
am 27 Sep. 2021
It would be easier if you would switch over to table or timetable instead of using timeseries .
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/750909/AAPL.csv';
t = readtable(filename, 'VariableNamingRule', 'preserve');
tt = table2timetable(t);
ts = timeseries(tt);
ts
n = randi(10)
result = a_function(ts, n);
result
function result = a_function(ts, n)
T = ts.Time(n+1:end);
adj = ts.Data.('Adj Close');
result = timeseries(adj(n+1:end) - adj(1:end-n), T);
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!