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:
1
from empyrial import empyrial, Engine
2
​
3
portfolio = Engine(
4
start_date = "2018-01-01",
5
benchmark = ["SPY"], #SPY is set by default
6
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
7
optimizer = "EF"
8
)
9
​
10
empyrial(portfolio)
Copied!
1
portfolio.weights
Copied!

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:
1
from empyrial import empyrial, Engine
2
​
3
portfolio = Engine(
4
start_date = "2018-01-01",
5
benchmark = ["SPY"], #SPY is set by default
6
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
7
optimizer = "EF",
8
min_weights = 0.05, #invest at least 5% of the capital in every assets
9
max_weights = 0.35 #don't invest more than 35% in one asset
10
)
11
​
12
empyrial(portfolio)
Copied!
1
portfolio.weights
Copied!

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:
1
from empyrial import empyrial, Engine
2
​
3
portfolio = Engine(
4
start_date = "2018-01-01",
5
benchmark = ["SPY"],
6
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
7
optimizer = "MINVAR",
8
diversification = 1.8
9
)
10
​
11
empyrial(portfolio)
Copied!
Last modified 4mo ago
Copy link