How to solve duration/double Error in yearfrac when forecasting prices?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tobias Poemsl
el 9 de Mayo de 2021
Comentada: Tobias Poemsl
el 10 de Mayo de 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 comentarios
Cris LaPierre
el 9 de Mayo de 2021
Editada: Cris LaPierre
el 9 de Mayo de 2021
What do your Price dates represent? Day of year?
What is SimPriceDates supposed to be?
Respuesta aceptada
Cris LaPierre
el 10 de Mayo de 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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Price and Analyze Financial Instruments en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!