How to solve duration/double Error in yearfrac when forecasting prices?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Cris LaPierre
2021-5-9
编辑:Cris LaPierre
2021-5-9
What do your Price dates represent? Day of year?
What is SimPriceDates supposed to be?
采纳的回答
Cris LaPierre
2021-5-10
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Price and Analyze Financial Instruments 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!