code: def hold_price(self, datetime=None):
          
  
          def weights(x):
              if sum(x['amount']) != 0:
                  return np.average(
                      x['price'],
                      weights=x['amount'],
                      returned=True
                  )
              else:
                  return np.nan
  
          if datetime is None:
              return self.history_table.set_index(
                  'datetime',
                  drop=False
              ).sort_index().groupby('code').apply(weights).dropna()
          else:
              return self.history_table.set_index(
                  'datetime',
                  drop=False
              ).sort_index().loc[:datetime].groupby('code').apply(weights
                                                                 ).dropna()
docs: 计算持仓成本  如果给的是日期,则返回当日开盘前的持仓
  
          Keyword Arguments:
              datetime {[type]} -- [description] (default: {None})
  
          Returns:
              [type] -- [description]