Diversification
If you want to diversify more or less your portfolio, there are 2 ways to do it with Empyrial:
  • By using min_weights and max_weights:
Let's take this example:
from empyrial import empyrial, Engine
​
portfolio = Engine(
start_date = "2018-01-01",
benchmark = ["SPY"], #SPY is set by default
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
optimizer = "EF"
)
​
empyrial(portfolio)
portfolio.weights

Output

[0.0, 0.0, 0.02258, 0.97742, 0.0]
As you can see the allocation is very clustered around AMD and this is a problem. To solve that, we can do:
from empyrial import empyrial, Engine
​
portfolio = Engine(
start_date = "2018-01-01",
benchmark = ["SPY"], #SPY is set by default
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
optimizer = "EF",
min_weights = 0.05, #invest at least 5% of the capital in every assets
max_weights = 0.35 #don't invest more than 35% in one asset
)
​
empyrial(portfolio)
portfolio.weights

Output

[0.05, 0.05, 0.2, 0.35, 0.35]
So, we can tune these two parameters (min_weights and max_weights) in order to get a better allocation.
  • The second way is by using diversification (works with every optimizer except the Efficient Frontier, "EF"):
diversification's default value is 1.
The higher is this value, the more it diversifies the portfolio and gets closer to equal weighting.
The lower is this value, the less it diversifies the portfolio.
Example:
from empyrial import empyrial, Engine
​
portfolio = Engine(
start_date = "2018-01-01",
benchmark = ["SPY"],
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
optimizer = "MINVAR",
diversification = 1.8
)
​
empyrial(portfolio)
Copy link
On this page