def portfolioAnalysis(posDF, startDate, endDate, notional=10000000., benchmark='000300.zicn', isweight=False): secIDs = posDF['instrumentID'] data = get_equity_eod(instruments=secIDs, start_date=startDate, end_date=endDate) close_data = data['closePrice'] close_data = close_data.fillna(method='pad') close_data.fillna(value=0., inplace=True) columns = close_data.columns for instrument in columns: if isweight and notional: invest_value = posDF[posDF.instrumentID == instrument]['position'].iloc[0] * notional volume = int(invest_value / close_data[instrument].values[0]) else: volume = posDF[posDF.instrumentID == instrument]['position'].iloc[0] close_data[instrument] *= volume prices = close_data.sum(axis=1) perf_metric, perf_df, rollingRisk = createPerformanceTearSheet(prices=prices, benchmark=benchmark) return perf_metric, perf_df, rollingRisk
def outputSummaryStats(self, curve, other_curves, plot): returns = curve['return'] if hasattr(self.dataHandler, "benchmarkData"): benchmarkReturns = self.dataHandler.benchmarkData['return'] benchmarkReturns.name = self.benchmark else: benchmarkReturns = None perf_metric, perf_df, rollingRisk = createPerformanceTearSheet(returns=returns, benchmarkReturns=benchmarkReturns, other_curves=other_curves, plot=plot) if self.portfolioType == PortfolioType.FullNotional: positons = curve.drop(['cash', 'commission', 'total', 'return', 'margin', 'equity_curve', 'pnl'], axis=1) else: positons = curve.drop(['commission', 'total', 'return', 'margin', 'equity_curve', 'pnl'], axis=1) aggregated_positons = createPostionTearSheet(positons, plot=plot) transactions = extractTransactionFromFilledBook(self.filledBook.view()) turnover_rate = createTranscationTearSheet(transactions, positons, plot=plot) if plot: plt.show() return perf_metric, perf_df, rollingRisk, aggregated_positons, transactions, turnover_rate
def outputSummaryStats(self, curve, plot): returns = curve['return'] if hasattr(self.dataHandler, "benchmarkData"): benchmarkReturns = self.dataHandler.benchmarkData['return'] benchmarkReturns.name = self.benchmark else: benchmarkReturns = None perf_metric, perf_df, rollingRisk = createPerformanceTearSheet( returns=returns, benchmarkReturns=benchmarkReturns, plot=plot) if self.portfolioType == PortfolioType.FullNotional: positons = curve.drop([ 'cash', 'commission', 'total', 'return', 'margin', 'equity_curve', 'pnl' ], axis=1) else: positons = curve.drop([ 'commission', 'total', 'return', 'margin', 'equity_curve', 'pnl' ], axis=1) aggregated_positons = createPostionTearSheet(positons, plot=plot) transactions = extractTransactionFromFilledBook(self.filledBook.view()) turnover_rate = createTranscationTearSheet(transactions, positons, plot=plot) if plot: plt.show() return perf_metric, perf_df, rollingRisk, aggregated_positons, transactions, turnover_rate
def portfolioAnalysis(posDF, startDate, endDate, notional=10000000., benchmark='000300.zicn', isweight=False): secIDs = posDF['instrumentID'] data = get_equity_eod(instruments=secIDs, start_date=startDate, end_date=endDate) close_data = data['closePrice'] close_data = close_data.fillna(method='pad') close_data.fillna(value=0., inplace=True) columns = close_data.columns for instrument in columns: if isweight and notional: invest_value = posDF[posDF.instrumentID == instrument]['position'].iloc[0] * notional volume = int(invest_value / close_data[instrument].values[0]) else: volume = posDF[posDF.instrumentID == instrument]['position'].iloc[0] close_data[instrument] *= volume prices = close_data.sum(axis=1) perf_metric, perf_df, rollingRisk = createPerformanceTearSheet( prices=prices, benchmark=benchmark) return perf_metric, perf_df, rollingRisk