Hi everyone,
I am trying to limit my algo's max drawdown by using less leverage when my account value is low relatively to my account's highest value, and more leverage when my account's value at its highest.
The code would look something like this:
max_leverage = 2
min_leverage = 1
context.highest_account_value = ???
context.current_account_value = context.portfolio.portfolio_value
if context.current_account_value >= context.highest_account_value:
context.leverage = max_leverage
elif context.current_account_value <= context.highest_account_value * (min_leverage/max_leverage):
context.leverage = min_leverage
else:
context.leverage = max_leverage * (context.current_account_value/context.highest_account_value)
The problem is, I have no clue how to record my account's value through time. The best solution would be to use the "history" function provided by quantopian, but it only provides information on equity objects, not account objects.
Does anyone have a way to do this? Big thank you in advance.