![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/276013/image.png)
cumulative maximum loss code
3 次查看(过去 30 天)
显示 更早的评论
I'm new to Matlab and I'm having trouble with the code for the computation of cumulative maximum loss for a time series. What I need to do is to compute the maximum loss compared to the highest levels of the variable over a period T which is set to 522 days.
Specifically,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/275523/image.png)
Thank you for any help
0 个评论
回答(1 个)
Koushik Vemula
2020-3-9
According to my understanding you have a variable ‘x’ which has ‘n’(say) number of values.
You would like to find the value of
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/276013/image.png)
where the value 522 is ‘T’ value.
You can do it in the following manner
1-(x(t))/max(x(1:T+1))
We have ‘+1’ as matlab index starts from ‘1’
6 个评论
Koushik Vemula
2020-3-16
for i = T+1:length(x)
sol(i)=1-(x(i)/max(x(i-T:i)))
end
Here we are iterating from T+1 (index should be greater than 0) to max of x.
This will give you your desired result
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!