Fmincon with Nested Optimization

1 回表示 (過去 30 日間)
motleyfool
motleyfool 2018 年 9 月 12 日
コメント済み: motleyfool 2018 年 9 月 13 日
I have to maximize the sharpe ratio, but my weights are given by an equation. I am not knowing how to connect that with fmincon
function [y] = w2(a) %function for weight
global avrcc avrco avroc avroo avrrvp avrtvl rcc rco roc roo tvl rvp i j n
y = a(1)*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(2)*(roo(i,j)-avroo(i))./n...
+ a(3)*(roc(i-1,j)-avroc(i-1))./n ...
+ a(4)*(rco(i,j)-avrco(i))./n...
+ a(5)*(tvl(i-1,j)/avrtvl(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(6)*(tvl(i-1,j)/avrtvl(i-1, j))*(roo(i,j)-avroo(i))./n...
+ a(7)*(tvl(i-1,j)/avrtvl(i-1,j))*(roc(i,j)-avroc(i-1))./n...
+ a(8)*(tvl(i-1,j)/avrtvl(i-1,j))*(rco(i,j)-avrco(i))./n...
+ a(9)*(rvp(i-1,j)/avrrvp(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(10)*(rvp(i-1,j)/avrrvp(i-1,j))*(roo(i,j)-avroo(i))./n...
+ a(11)*(rvp(i-1,j)/avrrvp(i-1,j))*(roc(i-1,j)-avroc(i-1))./n...
+ a(12)*(rvp(i-1,j)/avrrvp(i-1,j))*(rco(i,j)-avrco(i))./n;
end
My function for sharpe ratio is as follows
function [y] = msharper(mu,Q,rf)
y = mu-rf/sqrt(w2(a)'*Q*w2(a));
end
I do not know how to apply fmincon such a way that I find the values of a vector.
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 12 日
It is not clear which variable you are optimizing over? Is it a ? If so then it should be an input to msharper()
motleyfool
motleyfool 2018 年 9 月 12 日
Thank you for your response Walter, I am need to find values of a(1) through a(12). Such that that long equation is what I must plug-in for my weights in the second function.

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

採用された回答

Matt J
Matt J 2018 年 9 月 12 日
編集済み: Matt J 2018 年 9 月 12 日
My approach would be to modify the functions as follows, taking into account Walter's remarks and also getting rid of the global variables,
function [y] = w2(a, avrcc, avrco, avroc, avroo, avrrvp,...
avrtvl, rcc, rco, roc, roo, tvl, rvp, i, j, n)
y = a(1)*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(2)*(roo(i,j)-avroo(i))./n...
+ a(3)*(roc(i-1,j)-avroc(i-1))./n ...
+ a(4)*(rco(i,j)-avrco(i))./n...
+ a(5)*(tvl(i-1,j)/avrtvl(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(6)*(tvl(i-1,j)/avrtvl(i-1, j))*(roo(i,j)-avroo(i))./n...
+ a(7)*(tvl(i-1,j)/avrtvl(i-1,j))*(roc(i,j)-avroc(i-1))./n...
+ a(8)*(tvl(i-1,j)/avrtvl(i-1,j))*(rco(i,j)-avrco(i))./n...
+ a(9)*(rvp(i-1,j)/avrrvp(i-1,j))*(rcc(i-1,j)-avrcc(i-1))./n...
+ a(10)*(rvp(i-1,j)/avrrvp(i-1,j))*(roo(i,j)-avroo(i))./n...
+ a(11)*(rvp(i-1,j)/avrrvp(i-1,j))*(roc(i-1,j)-avroc(i-1))./n...
+ a(12)*(rvp(i-1,j)/avrrvp(i-1,j))*(rco(i,j)-avrco(i))./n;
end
function [y] = msharper(a, mu,Q,rf,weightfun)
y = mu-rf/sqrt(weightfun(a)'*Q*weightfun(a));
end
and then in the main workspace,
weightfun=@(a) w2(a, avrcc, avrco, avroc, avroo, avrrvp,...
avrtvl, rcc, rco, roc, roo, tvl, rvp, i, j, n);
a_opt = fmincon @(a) msharper(a, mu,Q,rf,weightfun), __________ );
  1 件のコメント
motleyfool
motleyfool 2018 年 9 月 13 日
Made a few mods, but the idea of eliminating the global variables helped for sure! Thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by