def save_portfolio(self, datetime, portfolio, perf_tracker, recorded_vars): ''' Store in Rethinkdb a zipline.Portfolio object ''' if perf_tracker.progress != 0.0 and self.table: metrics = perf_tracker.to_dict() metrics.update({ 'date': datetime, 'recorded': recorded_vars, 'portfolio': dbutils.portfolio_to_dict(portfolio) }) log.debug('Saving metrics in database') log.debug(rdb.table(self.table).insert(metrics).run(self.session))
def save_portfolio(self, datetime, portfolio): ''' Store in Rethinkdb a zipline.Portfolio object ''' log.debug('Saving portfolio in database') pf = dbutils.portfolio_to_dict(portfolio) pf.pop('positions') data = [{ "name": self.name, "time": datetime.strftime("%Y-%m-%d %H:%M"), "columns": pf.keys(), "points": [pf.values()]}] # Timestamp type is not json serializable data[0]['points'][0][-1] = pf['start_date'].__str__() self.session.write_points(data)
def save_portfolio(self, datetime, portfolio): ''' Store in Rethinkdb a zipline.Portfolio object ''' log.debug('Saving portfolio in database') pf = dbutils.portfolio_to_dict(portfolio) pf.pop('positions') data = [{ "name": self.name, "time": datetime.strftime("%Y-%m-%d %H:%M"), "columns": pf.keys(), "points": [pf.values()] }] # Timestamp type is not json serializable data[0]['points'][0][-1] = pf['start_date'].__str__() self.session.write_points(data)
def save_portfolio(self, datetime, portfolio, perf_tracker, recorded_vars): ''' Store in Rethinkdb a zipline.Portfolio object ''' if perf_tracker.progress != 0.0 and self.table: metrics = perf_tracker.to_dict() metrics.update({ 'date': datetime, 'recorded': recorded_vars, 'portfolio': dbutils.portfolio_to_dict(portfolio) }) log.debug('Saving metrics in database') log.debug( rdb.table(self.table) .insert(metrics) .run(self.session) )