Rolling window using optimProbelm

4 ビュー (過去 30 日間)
Karoline Bax
Karoline Bax 2022 年 5 月 11 日
回答済み: Nipun 2023 年 11 月 2 日
Hello,
I am trying to set a portfolio in an optimization problem as a rolling window. Bascially I am trying to recereate the following portfolios on this website but in a rolling window fashion:
diverseProb = optimproblem('ObjectiveSense','minimize');
My problem is that I cannot create many diverseProb = optimproblem(.....); in a loop. I tried it with indexing
for i=1: T-WindowSize
diverseProb(i) = optimproblem('ObjectiveSense','minimize');
end
However, it does not work - as I have many wndows I do not want to do it manually, Is there a way to " stack thee OptimizationProblem objects?
Thank you.
  1 件のコメント
dleal
dleal 2022 年 5 月 15 日
Have you tried using a cell array?
diverseProbs = cell(1,T-WindowSize);
for i=1:T-WindowSize
diverseProb{1,i} = optimproblem('ObjectiveSense','minimize');
end

サインインしてコメントする。

回答 (1 件)

Nipun
Nipun 2023 年 11 月 2 日
Hi Karoline,
I understand that you are trying to pre-allocate the Optimization Problem objects for latter deployment in your code. I assume you have created a list of the required size that you wish to pre-allocate.
I suggest using a cell array for preallocation. I am attaching a reference code below that might help with allocating the optimization objects.
diverseProb = cell(T-WindowSize,1)
for i=1:T-WindowSize
diverseProb{i,1} = optimproblem('ObjectiveSense','minimize');
end
Note that I have created a column vector as MATLAB stores elements column-first in memory. This way, it can leverage fast retrieval from memory when called. Hope this helps.
Regards,
Nipun

カテゴリ

Help Center および File ExchangePortfolio Optimization and Asset Allocation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by