---
title: "Portfolio Performance Report"
output: html_document
date: "`r format(Sys.time(), '%d %B, %Y')`"
params:
  summary_df1: NA
  summary_df2: NA
  plots_fixed: NA
  plots_relative: NA
---

<style type="text/css">
h1.title { font-size: 28px; color: DarkOrange;}
h1 { font-size: 24px;}
h2 { font-size: 20px;}
h3 { font-size: 18px;}
body { font-size: 16px;}
</style>

```{r echo = FALSE, message = FALSE}
# Some global stuff
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(knitr))
#params <- readRDS("params.RDS")
```

The following Portfolio Report was automatically generated by the *lares* library:

## All time performance

```{r fig.width = 8, fig.height = 5, echo = FALSE}
ggplot2:::plot.ggplot(params$plots_fixed$`Positions`)
```

## Dynamic time periods report {.tabset}

```{r, results = 'asis', fig.width = 10, fig.height = 5, echo = FALSE}
ts <- gsub("plots_", "", names(params$plots_relative))
plot_names <- names(params$plots_relative[[1]])
for (p in seq_along(plot_names)){
  cat(paste0("### ", plot_names[p], "{.tabset}\n"))
  for (i in seq_along(ts)){
      cat("####", ts[i], '<br>', '\n')
      ggplot2:::plot.ggplot(params$plots_relative[[i]][[p]])
      cat('\n', '<br>', '\n\n')
  }
  cat('\n', '<br>', '\n\n')
}
```

## Tabulated data {.tabset}

```{r, results = 'asis', fig.width = 8, fig.height = 5, echo = FALSE}
tables <- list(
  "Stocks Summary" = kable(params$summary_df1, align = "lrcrrrr", row.names = TRUE, digits = c(0, 2, 0, 2, 0, 0, 1), format.args = list(big.mark = ",")),
  "Portfolio Summary" = kable(params$summary_df2, align = "lcc", row.names = FALSE))
for (i in seq_along(tables)){
  cat("###", names(tables)[i], '<br>', '\n')
  print(tables[[i]])
  cat('\n', '<br>', '\n\n')
}
```

## Overall portfolio information {.tabset}

```{r, results = 'asis', fig.width = 8, fig.height = 5, echo = FALSE}
other <- names(params$plots_fixed)
# Exclude summary which has already been plotted
for (i in seq_along(other)[-1]){
  p <- params$plots_fixed[[i]]
  if (!is.null(p)) {
    cat("###", other[i], '<br>', '\n')
    ggplot2:::plot.ggplot(p)
    cat('\n', '<br>', '\n\n')
  }
}
```

> Report generated timestamp: `r Sys.time()`
