def generate_robust_report(fund_matrix, out_file): """ @summary generates a report using robust backtesting @param fund_matrix: a pandas matrix of fund time series @param out_file: filename where to print report """ html_file = open(out_file,"w") print_header(html_file, out_file) converter.fundsToPNG(fund_matrix,'funds.png') html_file.write("<H2>QSTK Generated Report:" + out_file + "</H2>\n") html_file.write("<IMG SRC = \'./funds.png\'/>\n") html_file.write("<IMG SRC = \'./analysis.png\'/>\n") html_file.write("<BR/>\n\n") print_stats(fund_matrix, "robust funds", html_file) print_footer(html_file)
def generate_robust_report(fund_matrix, out_file): """ @summary generates a report using robust backtesting @param fund_matrix: a pandas matrix of fund time series @param out_file: filename where to print report """ html_file = open(out_file, "w") print_header(html_file, out_file) converter.fundsToPNG(fund_matrix, 'funds.png') html_file.write("<H2>QSTK Generated Report:" + out_file + "</H2>\n") html_file.write("<IMG SRC = \'./funds.png\'/>\n") html_file.write("<IMG SRC = \'./analysis.png\'/>\n") html_file.write("<BR/>\n\n") print_stats(fund_matrix, "robust funds", html_file) print_footer(html_file)
def reportFunctionality(funds, symbols, filename=sys.stdout): if (len(symbols) != 0): funds2 = runOther(funds, symbols) arg2 = 1 else: arg2 = 0 if (filename == sys.stdout): html_file = sys.stdout else: html_file = open(filename, "w") #top html_file.write("<HTML>\n") html_file.write("<HEAD>\n") html_file.write("<TITLE>QSTK Generated Report from " + readableDate(funds.index[0]) + " to " + readableDate(funds.index[-1]) + "</TITLE>\n") html_file.write("</HEAD>\n\n") html_file.write("<BODY><CENTER>\n\n") years = du.getYears(funds) html_file.write("<H2>Performance Summary for " + sys.argv[1] + "</H2>\n") html_file.write("For the dates " + readableDate(funds.index[0]) + " to " + readableDate(funds.index[-1]) + "\n") html_file.write("<H3>Yearly Performance Metrics</H3>\n") html_file.write("<TABLE CELLPADDING=10>\n") html_file.write("<TR><TH></TH>\n") for year in years: html_file.write("<TH>" + str(year) + "</TH>\n") html_file.write("</TR>\n") #yearly return html_file.write("<TR>\n") html_file.write("<TH>Annualized Return:</TH>\n") for year in years: retur = getYearReturn(funds, year) html_file.write("<TD>\n") print >> html_file, "%.2f\n" % (retur * 100) html_file.write("%</TD>\n") html_file.write("</TR>\n") #yearly winning days html_file.write("<TR>\n") html_file.write("<TH>Winning Days:</TH>\n") for year in years: # change to compare to inputs - ratio=tsu.getYearRatio(funds,year) if (arg2 != 0): win = getWinningDays(funds, funds2, year) html_file.write("<TD>\n") print >> html_file, "%.2f\n" % (win * 100) html_file.write("%</TD>\n") else: html_file.write("<TD>No comparison.</TD>\n") html_file.write("</TR>\n") #max draw down html_file.write("<TR>\n") html_file.write("<TH>Max Draw Down:</TH>\n") for year in years: drop = getYearMaxDrop(funds, year) html_file.write("<TD>\n") print >> html_file, "%.2f" % (drop * 100) html_file.write("%</TD>\n") html_file.write("</TR>\n") #yearly sharpe ratio using daily rets html_file.write("<TR>\n") html_file.write("<TH>Daily Sharpe Ratio:</TH>\n") for year in years: ratio = tsu.getYearRatio(funds, year) html_file.write("<TD>\n") print >> html_file, "%.2f\n" % ratio html_file.write("</TD>\n") html_file.write("</TR>\n") #yearly sharpe ratio using monthly rets html_file.write("<TR>\n") html_file.write("<TH>Monthly Sharpe Ratio:</TH>\n") for year in years: ratio = getYearRatioUsingMonth(funds, year) html_file.write("<TD>\n") print >> html_file, "%.2f\n" % ratio html_file.write("</TD>\n") html_file.write("</TR>\n") html_file.write("</TABLE>\n") html_file.write("<BR/>\n\n") vals = funds.values vals2 = np.append(vals, funds2.values, 2) df = DataMatrix(index=funds.index, data=funds.values, columns=['fund']) df2 = DataMatrix(index=funds2.index, data=funds2.values, columns=['other']) df['other'] = df2['other'] corrcoef = numpy.corrcoef(funds.values[0:-1], funds2.values) html_file.write("<H3>Correlation=") print >> html_file, "%.2f\n" % corrcoef[0][1] html_file.write("<H3>\n") html_file.write("<BR/>\n\n") #montly returns mrets = tsu.monthly(funds) html_file.write("<H2>Monthly Returns</H2>\n") html_file.write("<TABLE CELLPADDING=10>\n") html_file.write("<TR>\n") html_file.write("<TH></TH>\n") month_names = du.getMonthNames() for name in month_names: html_file.write("<TH>" + str(name) + "</TH>\n") html_file.write("</TR>\n") i = 0 for year in years: html_file.write("<TR>\n") html_file.write("<TH>" + str(year) + "</TH>\n") months = du.getMonths(funds, year) for month in months: html_file.write("<TD>\n") print >> html_file, "%.2f\n" % (mrets[i] * 100) html_file.write("%</TD>\n") i += 1 html_file.write("</TR>\n") html_file.write("</TABLE>\n") html_file.write("<BR/>\n\n") #fund value graph fundlist = [] fundlist.append(funds) fundlist.append(funds2) converter.fundsToPNG(fundlist, 'funds.png') html_file.write("<IMG SRC=\'./funds.png\'/>\n") html_file.write("<BR/>\n\n") #end html_file.write("</CENTER></BODY>\n\n") html_file.write("</HTML>")
def reportFunctionality(funds, symbols,filename=sys.stdout): if(len(symbols)!=0): funds2=runOther(funds,symbols) arg2=1 else: arg2=0 if(filename==sys.stdout): html_file=sys.stdout else: html_file = open(filename,"w") #top html_file.write("<HTML>\n") html_file.write("<HEAD>\n") html_file.write("<TITLE>QSTK Generated Report from "+readableDate(funds.index[0])+" to "+readableDate(funds.index[-1])+"</TITLE>\n") html_file.write("</HEAD>\n\n") html_file.write("<BODY><CENTER>\n\n") years=du.getYears(funds) html_file.write("<H2>Performance Summary for "+sys.argv[1]+"</H2>\n") html_file.write("For the dates "+readableDate(funds.index[0])+" to "+readableDate(funds.index[-1])+"\n") html_file.write("<H3>Yearly Performance Metrics</H3>\n") html_file.write("<TABLE CELLPADDING=10>\n") html_file.write("<TR><TH></TH>\n") for year in years: html_file.write("<TH>"+str(year)+"</TH>\n") html_file.write("</TR>\n") #yearly return html_file.write("<TR>\n") html_file.write("<TH>Annualized Return:</TH>\n") for year in years: retur=getYearReturn(funds,year) html_file.write("<TD>\n") print >>html_file, "%.2f\n" % (retur*100) html_file.write("%</TD>\n") html_file.write("</TR>\n") #yearly winning days html_file.write("<TR>\n") html_file.write("<TH>Winning Days:</TH>\n") for year in years: # change to compare to inputs - ratio=tsu.getYearRatio(funds,year) if(arg2!=0): win=getWinningDays(funds,funds2,year) html_file.write("<TD>\n") print >>html_file, "%.2f\n" % (win*100) html_file.write("%</TD>\n") else: html_file.write("<TD>No comparison.</TD>\n") html_file.write("</TR>\n") #max draw down html_file.write("<TR>\n") html_file.write("<TH>Max Draw Down:</TH>\n") for year in years: drop=getYearMaxDrop(funds,year) html_file.write("<TD>\n") print >>html_file, "%.2f" % (drop*100) html_file.write("%</TD>\n") html_file.write("</TR>\n") #yearly sharpe ratio using daily rets html_file.write("<TR>\n") html_file.write("<TH>Daily Sharpe Ratio:</TH>\n") for year in years: ratio=tsu.getYearRatio(funds,year) html_file.write("<TD>\n") print >>html_file, "%.2f\n" % ratio html_file.write("</TD>\n") html_file.write("</TR>\n") #yearly sharpe ratio using monthly rets html_file.write("<TR>\n") html_file.write("<TH>Monthly Sharpe Ratio:</TH>\n") for year in years: ratio=getYearRatioUsingMonth(funds,year) html_file.write("<TD>\n") print >>html_file, "%.2f\n" % ratio html_file.write("</TD>\n") html_file.write("</TR>\n") html_file.write("</TABLE>\n") html_file.write("<BR/>\n\n") vals=funds.values; vals2=np.append(vals,funds2.values,2) df=DataMatrix(index=funds.index,data=funds.values, columns=['fund']) df2=DataMatrix(index=funds2.index,data=funds2.values,columns=['other']) df['other']=df2['other'] corrcoef=numpy.corrcoef(funds.values[0:-1],funds2.values) html_file.write("<H3>Correlation=") print >>html_file, "%.2f\n" % corrcoef[0][1] html_file.write("<H3>\n") html_file.write("<BR/>\n\n") #montly returns mrets=tsu.monthly(funds) html_file.write("<H2>Monthly Returns</H2>\n") html_file.write("<TABLE CELLPADDING=10>\n") html_file.write("<TR>\n") html_file.write("<TH></TH>\n") month_names=du.getMonthNames() for name in month_names: html_file.write("<TH>"+str(name)+"</TH>\n") html_file.write("</TR>\n") i=0 for year in years: html_file.write("<TR>\n") html_file.write("<TH>"+str(year)+"</TH>\n") months=du.getMonths(funds,year) for month in months: html_file.write("<TD>\n") print >>html_file, "%.2f\n" % (mrets[i]*100) html_file.write("%</TD>\n") i+=1 html_file.write("</TR>\n") html_file.write("</TABLE>\n") html_file.write("<BR/>\n\n") #fund value graph fundlist=[]; fundlist.append(funds) fundlist.append(funds2) converter.fundsToPNG(fundlist,'funds.png') html_file.write("<IMG SRC=\'./funds.png\'/>\n") html_file.write("<BR/>\n\n") #end html_file.write("</CENTER></BODY>\n\n") html_file.write("</HTML>")