How to create a time serie with daily data
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Job1003
am 17 Jan. 2025
Beantwortet: Seth Furman
am 17 Jan. 2025
Please i am trying to make a time series with daily financial datas.
The datas are observed daily except on weekends.
My main concern is that i am trying to set a moving starting (02 of january 2017) date with the function dattetime but i am having an error message. Please could you tell me what i did wrong?
M

Also , can you tell me how i can account for the weekly two days break in the time series.

Regards
1 Kommentar
Sandeep Mishra
am 17 Jan. 2025
Hi @Job1003
Can you also attach the missing variable/function 'txt' and 'ts' for better debugging?
Akzeptierte Antwort
Seth Furman
am 17 Jan. 2025
Use isweekend to remove weekends from your datetime series.
You'll also want to make sure you use caldays (calendar days) instead of days (fixed-length days) when constructing your datetime series.
% Create datetime series
startDate = datetime(2017,1,2,Format="eeee uuuu-MM-dd")
dt = (startDate:caldays(1):startDate+caldays(30))'
% Remove weekends from datetime series
dt(isweekend(dt)) = []
% Same result displayed in French
string(dt,"eeee uuuu-MM-dd","fr_FR")
Aside: Creating datetimes from localized text timestamps
I noticed that your comment says % start='02-janv-2017'. It's also worth noting that you can create datetimes from localized text timestamps. It's a good idea to specify the Locale Name-Value pair when doing this, so that your code will run on machines running MATLAB in different locales.
datetime("02-janv-2017",Locale="fr_FR")
0 Kommentare
Weitere Antworten (1)
Sandeep Mishra
am 17 Jan. 2025
Hi Job1003,
I noticed that you are encountering an error message related to the use of the 'strrep' function in MATLAB
The root cause of the issue arises from passing an incorrect input for the 'str' parameter in the 'strrep' MATLAB function, which must be a character array.
You can refer to the following example code snippet using ‘strrep’ MATLAB function:
% Correct input - Willn't thorw any error
data = {'123', 'hello', '456', 'world'};
strrep(data, 'o', 'a')
% Wrong input - Will throw the same error
data = {123, 'hello', 456, 'world'};
strrep(data, 'o', 'a')
Refer to the following MATLAB Documentation to learn more about ‘strrep’ function: https://www.mathworks.com/help/releases/R2024b/matlab/ref/strrep.html
I hope this helps you!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time 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!