Skip to content

Commit

Permalink
Merge pull request #306 from danilogalisteu/patch-1
Browse files Browse the repository at this point in the history
Allow different target volatilities for each asset
  • Loading branch information
timkpaine committed May 15, 2021
2 parents b416ccf + 3fc29d4 commit abf3269
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions bt/algos.py
Expand Up @@ -1539,17 +1539,16 @@ def __call__(self, target):
* self.annualization_factor
)

# vol is too high
if vol > self.target_volatility:
mult = self.target_volatility / vol
# vol is too low
elif vol < self.target_volatility:
mult = self.target_volatility / vol
else:
mult = 1
if isinstance(self.target_volatility, (float, int)):
self.target_volatility = {
k: self.target_volatility for k in target.temp["weights"].keys()
}

for k in target.temp["weights"].keys():
target.temp["weights"][k] = target.temp["weights"][k] * mult
if k in self.target_volatility.keys():
target.temp["weights"][k] = (
target.temp["weights"][k] * self.target_volatility[k] / vol
)

return True

Expand Down

0 comments on commit abf3269

Please sign in to comment.