Skip to content

Commit

Permalink
Merge pull request #281 from QuantConnect/feature-add-pdf-support-for…
Browse files Browse the repository at this point in the history
…-reports

Add support for PDF generations for reports
  • Loading branch information
Martin-Molinero authored Feb 14, 2023
2 parents 7bea2a7 + b2537af commit 86be2dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ Options:
--overwrite Overwrite --report-destination if it already contains a file
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
--update Pull the LEAN engine image before running the report creator
--pdf Create a PDF version along with the HTML version of the report
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
--verbose Enable debug logging
--help Show this message and exit.
Expand Down
11 changes: 9 additions & 2 deletions lean/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def _find_project_directory(backtest_file: Path) -> Optional[Path]:
is_flag=True,
default=False,
help="Pull the LEAN engine image before running the report creator")
@option("--pdf",
is_flag=True,
default=False,
help="Create a PDF version along with the HTML version of the report")
def report(backtest_results: Optional[Path],
live_results: Optional[Path],
report_destination: Path,
Expand All @@ -85,7 +89,8 @@ def report(backtest_results: Optional[Path],
strategy_description: Optional[str],
overwrite: bool,
image: Optional[str],
update: bool) -> None:
update: bool,
pdf: bool) -> None:
"""Generate a report of a backtest.
This runs the LEAN Report Creator in Docker to generate a polished, professional-grade report of a backtest.
Expand Down Expand Up @@ -152,7 +157,7 @@ def report(backtest_results: Optional[Path],
"live-data-source-file": "live-data-source-file.json" if live_results is not None else "",
"backtest-data-source-file": "backtest-data-source-file.json",
"report-destination": "/tmp/report.html",

"report-format": "pdf" if pdf else "",
"environment": "report",

"log-handler": "QuantConnect.Logging.CompositeLogHandler",
Expand Down Expand Up @@ -217,6 +222,8 @@ def report(backtest_results: Optional[Path],
}
}

if pdf:
run_options["commands"].append(f'cp /tmp/report.pdf "/Output/{report_destination.name.replace(".html", ".pdf")}"')
if live_results is not None:
run_options["mounts"].append(Mount(target="/Lean/Report/bin/Debug/live-data-source-file.json",
source=str(live_results),
Expand Down

0 comments on commit 86be2dc

Please sign in to comment.