I would like to use the initial capital base for the backtest or live execution as the max exposure in the algorithm (long or short) without having to change the starting cash in the algorithm and match that to my code.
def initialize(context):
context.MAX_NOTIONAL = context.portfolio.starting_cash
context.MIN_NOTIONAL = -context.portfolio.starting_cash
context.MAX_SHARES = 100
But, this gives me a Build error:
19 Error Runtime exception: KeyError: 'portfolio'