Hi Junpeng,
Thanks for your suggestion. But the thing here is that all the aggregations are related to the prior parameters, so it cannot be moved out of the context. for example the first row:
xxdat['ad'] = (xxdat['pde_norm'].values) * (lam[xxdat['chnl_cd'].values-1]**(xxdat['gap_nrx_promo'].values))
it generate the new column ad by using parameter lam, and then this column will be used into the groupby function in the next row.
I am also feel like too many aggregations within the pm.model context can definitely lower the speed but could not find a better way to solve this 