How to solve duration/double Error in yearfrac when forecasting prices?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tobias Poemsl
am 9 Mai 2021
Kommentiert: Tobias Poemsl
am 10 Mai 2021
I'm trying to run a modified Energy Price Simulation shown under https://de.mathworks.com/help/fininst/simulating-electricity-prices-with-mean-reversion-and-jump-diffusion.html#mw_rtc_SimulateElectricityPricesExample_780C89FE
When I want to add back the seasonality as shown in the code snippet to the simulated prices I get the following error message below
I attached the format that is used for the Price dates.
Unable to perform assignment because value of type 'duration' is not convertible to 'double'.
Error in yearfrac (line 96)
YearFraction(Ind) = daysact(Date1(Ind), Date2(Ind)) ./...
Error in Test (line 106)
SimPriceTimes = yearfrac(PriceDates(1), SimPriceDates);
Caused by:
Error using duration/double (line 1075)
Undefined function 'double' for input arguments of type 'duration'. To convert from durations to numeric, use
the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions.
% Add back seasonality.
SimPriceDates = PriceDates(end) + days(0:(nPeriods-1))';
SimPriceTimes = yearfrac(PriceDates(1), SimPriceDates);
CSim = seasonMatrix(SimPriceTimes);
logSimPrices = SimPrices + repmat(CSim*seasonParam,1,nTrials);
2 Kommentare
Cris LaPierre
am 9 Mai 2021
Bearbeitet: Cris LaPierre
am 9 Mai 2021
What do your Price dates represent? Day of year?
What is SimPriceDates supposed to be?
Akzeptierte Antwort
Cris LaPierre
am 10 Mai 2021
My suggestion is to turn your PriceDates into datetimes. The yearfrac function can work with those.
Do you know what year the data is from? Here's an example assuming 2019.
PriceDates = readmatrix("Timeseries_Electricity.xls");
PriceDates = PriceDates + datetime(2019,1,0)
nPeriods = 4;
% Add back seasonality.
SimPriceDates = PriceDates(end) + days(0:(nPeriods-1))'
SimPriceTimes = yearfrac(PriceDates(1), SimPriceDates)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Price and Analyze Financial Instruments 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!