abe*_*ysh 2 matlab plot matlab-figure julia gadfly
我正在优化N超过M预期回报水平的股票投资组合。所以在这样做之后,我得到了权重的时间序列(即一个N x M矩阵,其中每一行是特定预期回报水平的股票权重的组合)。权重加起来为 1。
现在我想绘制一个叫做投资组合构成图的东西(图片上的右图),它是这些股票权重在所有预期回报水平上的图,每个都有不同的颜色和长度(在每个回报水平)与它的重量。
我的问题是如何在 Julia(或 MATLAB)中做到这一点?
小智 5
我遇到了这个,接受的解决方案似乎很复杂。这是我将如何做到的:
using Plots
@userplot PortfolioComposition
@recipe function f(pc::PortfolioComposition)
weights, returns = pc.args
weights = cumsum(weights,dims=2)
seriestype := :shape
for c=1:size(weights,2)
sx = vcat(weights[:,c], c==1 ? zeros(length(returns)) : reverse(weights[:,c-1]))
sy = vcat(returns, reverse(returns))
@series Shape(sx, sy)
end
end
# fake data
tickers = ["IBM", "Google", "Apple", "Intel"]
N = 10
D = length(tickers)
weights = rand(N,D)
weights ./= sum(weights, dims=2)
returns = sort!((1:N) + D*randn(N))
# plot it
portfoliocomposition(weights, returns, labels = tickers)
Run Code Online (Sandbox Code Playgroud)