Joseph Loss
05/24/2021, 7:43 PMstrategies = ['strat1', 'strat2', 'strat3']
for strat in strategies:
strat = [strat]
# this gets the list of applicable accounts
lstAccnts = GetRiskModelAccnts(strategy = strat)
# this gets the tracking error risk on an account level (each account has between 1 and 3 strategies)
dfAccntsTEc, dfAccntsTE, dfAccntsMoments = RiskWrapper(
lstAccnt = lstAccnts,
benchmark = 'SPY',
lstAllowStrats = strat,
AggregationLevel = ['accnt']
)
# this gets the tracking error risk on an account-strategy level
dfAccntsTEc, dfAccntsTE, dfAccntsMoments = RiskWrapper(
lstAccnt = lstAccnts,
benchmark = 'SPY',
lstAllowStrats = strat,
AggregationLevel = ['accnt', 'strategy']
)
You'll notice the aggregation level is also something that is iterated, and there is a third aggregation level ['accnt', 'strategy', 'strategyLevel'] that isn't shown above. I know mapping could be of use here as well but I'm not sure the correct syntax to implement it.Kevin Kho
lstAccnts
so you have a list of lists, flatten
that so you end up with 1 list. map
on that. If you need some sort of traceability with the list of lists, you can have intermediate tasks that go reorganize the list.Joseph Loss
05/24/2021, 8:08 PMwith Flow("load-tblTrackingErrorTicker ParallelExecution") as flow:
strats = Parameter("strats", default=["MII","HEP","OYE","OYENT"])
lstAccnts = GetRiskModelAccnts(mapped(strats))
dfAccntsTEc, dfAccntsTE, dfAccntsMom=RiskWrapper(lstAccnt = mapped(lstAccnts),
strBenchTicker = 'SPY',
lstShowPlots = [False, False],
lstAllowStrats = mapped(strats),
lstAggLevels = ['accnt'],
bDataFields = True)
flow.run_config = LocalRun()
# Use a `LocalDaskExecutor` to run this flow
# This will run tasks in a thread pool, allowing for parallel execution
flow.executor = LocalDaskExecutor()
flow.run()
Kevin Kho
mapped
instead of GetRiskModelAccnts.map()
? I think you so the .map(strats)
. lstAccnts
becomes a list of lists. You can flatten with RiskWrapper(lstAccnt = flatten(lstAccnts))
Kevin Kho
unmapped
for the others parameters, especially string inputs as they get treated as iterables.Kevin Kho
dfAccntsTEc, dfAccntsTE, dfAccntsMom
= . If your task returns 3 things, the output of the mapped task is List[Tuple]
. So you have a list of 3 items each. That tuple unpacking requires Tuple[List]
to do assignment like that so you need an intermediate task to take in the output of RiskWrapper
and reshape it to return the three lists before you can assign it like thatJoseph Loss
05/24/2021, 8:27 PMKevin Kho
Kevin Kho
unmapped
around all thoseJoseph Loss
05/25/2021, 6:44 PM