How to solve duration/double Error in yearfrac when forecasting prices?
3 views (last 30 days)
Show older comments
Tobias Poemsl
on 9 May 2021
Commented: Tobias Poemsl
on 10 May 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 Comments
Cris LaPierre
on 9 May 2021
Edited: Cris LaPierre
on 9 May 2021
What do your Price dates represent? Day of year?
What is SimPriceDates supposed to be?
Accepted Answer
Cris LaPierre
on 10 May 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)
More Answers (0)
See Also
Categories
Find more on Price and Analyze Financial Instruments in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!