pysystemtrade icon indicating copy to clipboard operation
pysystemtrade copied to clipboard

Reporting: Have you considered generating HTML instead of PDF, or as a preliminary to

Open robcarver17 opened this issue 2 years ago • 0 comments

  Have you considered generating HTML instead of PDF, or as a preliminary to

it?

One benefit of HTML is that you could include charts in the emailed reports, and mixing text and images is of course not a problem. You could always email a PDF file, but an email with images seems nicer.

Github.com can also display html files.

There are libraries available to convert HTML to PDF if you still want PDF for some reason (although I know you don't like adding dependencies).

On Tue, Jul 12, 2022 at 7:30 AM Robert Carver @.***> wrote:

It would be nice to have the option to output reports into a .pdf file. That way, figures can be plotted. The use case I'm thinking of is issue #653 https://github.com/robcarver17/pysystemtrade/issues/653 but clearly one could use this for accounting p&l as well.

A quick check reveals that github.com can render .pdf so that is good.

The following code fragment seems the easiest way of generating .pdf files consisting of multiple plots (from https://datatofish.com/export-matplotlib-pdf/)

from matplotlib.backends.backend_pdf import PdfPages Data1 = {'Unemployment_Rate': [6.1,5.8,5.7,5.7,5.8,5.6,5.5,5.3,5.2,5.2], 'Stock_Index_Price': [1500,1520,1525,1523,1515,1540,1545,1560,1555,1565] } df1 = DataFrame(Data1,columns=['Unemployment_Rate','Stock_Index_Price'])

with PdfPages(r'C:\Users\Ron\Desktop\Charts.pdf') as export_pdf:

plt.scatter(df1['Unemployment_Rate'], df1['Stock_Index_Price'], color='green')
plt.title('Unemployment Rate Vs Stock Index Price', fontsize=10)
plt.xlabel('Unemployment Rate', fontsize=8)
plt.ylabel('Stock Index Price', fontsize=8)
plt.grid(True)
export_pdf.savefig()
plt.close()

It also works on a headless terminal (checked).

It would be nice to include text as well, but let's park that for the moment (can always be a seperate file).

Now, this does not fit well into the paradigm used by the reporting code in psystemtrade. Remember, we generate a list of special objects (headers, body_text, table) which is then 'parsed' into a single text string, which we then email or dump to file etc.

MORE TBC

— Reply to this email directly, view it on GitHub https://github.com/robcarver17/pysystemtrade/discussions/680, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3JWKVKH5NKN5EXDNF3XT3VTV6RPANCNFSM53LH7BPQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Originally posted by @tgibson11 in https://github.com/robcarver17/pysystemtrade/discussions/680#discussioncomment-3847186

robcarver17 avatar Oct 11 '22 09:10 robcarver17