| Home | Trees | Indices | Help |
|
|---|
|
|
1 #
2 # report.py
3 #
4 # Generates a html file containing a report based
5 # off a timeseries of funds from a pickle file.
6 #
7 # Drew Bratcher
8 #
9
10 from pylab import *
11 from qstkutil import DataAccess as da
12 from qstkutil import dateutil as du
13 from qstkutil import tsutil as tsu
14 from quicksim import quickSim as qs
15 import converter
16
17 from pandas import *
18 import matplotlib.pyplot as plt
19 import cPickle
20
21
22 if __name__ == '__main__':
23 # Usage
24 #
25 # Normal:
26 # python report.py funds
27 # python report.py 'out.pkl'
28 #
29 # Robust:
30 # python report.py -r fundsmatrix
31 # python report.py -r 'out.pkl'
32 #
33
34 robust=0
35 if(sys.argv[1]=='-r'):
36 robust=1
37
38 if(robust==1):
39 input=open(sys.argv[2],"r")
40 else:
41 input=open(sys.argv[1],"r")
42 funds=cPickle.load(input)
43
44 filename = "report.html"
45 html_file = open(filename,"w")
46
47 #top
48 html_file.write("<HTML>\n")
49 html_file.write("<HEAD>\n")
50 if(robust==1):
51 html_file.write("<TITLE>QSTK Generated Report:"+str(sys.argv[2])+"</TITLE>\n")
52 else:
53 html_file.write("<TITLE>QSTK Generated Report:"+str(sys.argv[1])+"</TITLE>\n")
54 html_file.write("</HEAD>\n\n")
55 html_file.write("<BODY><CENTER>\n\n")
56
57 #fund value graph
58 converter.fundsToPNG(funds,'funds.png')
59 if(robust==1):
60 converter.fundsAnalysisToPNG(funds,'analysis.png')
61 html_file.write("<H2>QSTK Generated Report:"+str(sys.argv[2])+"</H2>\n")
62 else:
63 html_file.write("<H2>QSTK Generated Report:"+str(sys.argv[1])+"</H2>\n")
64 html_file.write("<IMG SRC=\'./funds.png\'/>\n")
65 if(robust==1):
66 html_file.write("<IMG SRC=\'./analysis.png\'/>\n")
67 html_file.write("<BR/>\n\n")
68
69 #montly returns
70 #mrets=tsu.monthly(funds[0])
71 #mrets=[]
72 #html_file.write("<H2>Monthly Returns</H2>\n")
73 #html_file.write("<TABLE CELLPADDING=10>\n")
74 #html_file.write("<TR>\n")
75 #html_file.write("<TH></TH>\n")
76 #month_names=du.getMonthNames()
77 #for name in month_names:
78 # html_file.write("<TH>"+str(name)+"</TH>\n")
79 #html_file.write("</TR>\n")
80 #years=du.getYears(funds[0])
81 years=[]
82 i=0
83 for year in years:
84 html_file.write("<TR>\n")
85 html_file.write("<TH>"+str(year)+"</TH>\n")
86 # months=du.getMonths(funds[0],year)
87 for month in months:
88 html_file.write("<TD>"+str(mrets[i]*100)[:4]+"%</TD>\n")
89 i+=1
90 html_file.write("</TR>\n")
91 html_file.write("</TABLE>\n")
92 html_file.write("<BR/>\n\n")
93
94 #sharpe ratio
95 #ratio=tsu.getRatio(funds[0])
96 ratio=0
97 html_file.write("<H3>Overall Sharpe Ratio: "+str(ratio)+"</H3>\n")
98 html_file.write("<TABLE CELLPADDING=10>\n")
99 html_file.write("<TR><TH></TH>\n")
100 for year in years:
101 html_file.write("<TH>"+str(year)+"</TH>\n")
102 html_file.write("</TR>\n")
103 html_file.write("<TR>\n")
104 html_file.write("<TH>Sharpe Ratio:</TH>\n")
105 for year in years:
106 # ratio=tsu.getYearRatio(funds[0],year)
107 html_file.write("<TD>"+str(ratio)+"</TD>\n")
108 html_file.write("</TR>\n")
109 html_file.write("</TABLE>\n")
110 html_file.write("<BR/>\n\n")
111
112 #end
113 html_file.write("</CENTER></BODY>\n\n")
114 html_file.write("</HTML>")
115
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Mar 5 00:49:16 2012 | http://epydoc.sourceforge.net |