How to solve duration/double Error in yearfrac when forecasting prices?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tobias Poemsl
le 9 Mai 2021
Commenté : Tobias Poemsl
le 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 commentaires
Cris LaPierre
le 9 Mai 2021
Modifié(e) : Cris LaPierre
le 9 Mai 2021
What do your Price dates represent? Day of year?
What is SimPriceDates supposed to be?
Réponse acceptée
Cris LaPierre
le 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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Price and Analyze Financial Instruments dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!