Revert "Revert "Transfer portfoliocomposition recipe from PlotRecipes""
This commit is contained in:
parent
a2a4e5b350
commit
12309c281b
@ -435,6 +435,24 @@ each line segment or marker in the plot.
|
|||||||
end)]
|
end)]
|
||||||
),
|
),
|
||||||
|
|
||||||
|
PlotExample("Portfolio Composition maps",
|
||||||
|
"""
|
||||||
|
see: http://stackoverflow.com/a/37732384/5075246
|
||||||
|
""",
|
||||||
|
[:(begin
|
||||||
|
using Random
|
||||||
|
Random.seed!(111)
|
||||||
|
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))
|
||||||
|
|
||||||
|
portfoliocomposition(weights, returns, labels = permutedims(tickers))
|
||||||
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Some constants for PlotDocs and PlotReferenceImages
|
# Some constants for PlotDocs and PlotReferenceImages
|
||||||
@ -446,6 +464,8 @@ _backend_skips = Dict(
|
|||||||
:pgfplots => [2, 5, 6, 10, 16, 20, 22, 23, 25, 28, 30],
|
:pgfplots => [2, 5, 6, 10, 16, 20, 22, 23, 25, 28, 30],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
# make and display one plot
|
# make and display one plot
|
||||||
|
|||||||
@ -1131,3 +1131,25 @@ end
|
|||||||
title := string(grad.args[1])
|
title := string(grad.args[1])
|
||||||
z
|
z
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Moved in from PlotRecipes - see: http://stackoverflow.com/a/37732384/5075246
|
||||||
|
@userplot PortfolioComposition
|
||||||
|
|
||||||
|
# this shows the shifting composition of a basket of something over a variable
|
||||||
|
# - "returns" are the dependent variable
|
||||||
|
# - "weights" are a matrix where the ith column is the composition for returns[i]
|
||||||
|
# - since each polygon is its own series, you can assign labels easily
|
||||||
|
@recipe function f(pc::PortfolioComposition)
|
||||||
|
weights, returns = pc.args
|
||||||
|
n = length(returns)
|
||||||
|
weights = cumsum(weights, dims = 2)
|
||||||
|
seriestype := :shape
|
||||||
|
|
||||||
|
# create a filled polygon for each item
|
||||||
|
for c=1:size(weights,2)
|
||||||
|
sx = vcat(weights[:,c], c==1 ? zeros(n) : reverse(weights[:,c-1]))
|
||||||
|
sy = vcat(returns, reverse(returns))
|
||||||
|
@series Plots.isvertical(plotattributes) ? (sx, sy) : (sy, sx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user