%% \VignetteIndexEntry{Overview of the PMwR package}
\documentclass[a4paper,11pt]{article}
\usepackage[left = 3cm, top = 2cm, bottom = 2cm, right = 4cm]{geometry}
\usepackage[noae,nogin]{Sweave}
\usepackage{libertine}
\usepackage[scaled=0.9]{inconsolata}
% \usepackage[T1]{fontenc}
\renewcommand*\familydefault{\sfdefault}
\usepackage{amsmath,amstext}
\usepackage{hyperref}
\usepackage{natbib}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{fancyvrb}
\usepackage[flushmargin]{footmisc}
\definecolor{grau2}{rgb}{.2,.2,.2}
\definecolor{grau7}{rgb}{.7,.7,.7}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{frame=single,xleftmargin=0em,%
  formatcom=\color{grau2},rulecolor=\color{grau7}}
\DefineVerbatimEnvironment{Scode}{Verbatim}{xleftmargin=2em}
\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
\SweaveOpts{keep.source = TRUE, eps = TRUE}

<<echo=false>>=
options(continue = "  ", digits = 3, width = 60, useFancyQuotes = FALSE)
pv <- packageVersion("PMwR")
pv <- gsub("(.*)[.](.*)", "\\1-\\2", pv)
@

\begin{document}
\title{An Overview of the PMwR Package}
\author{Enrico Schumann\\\url{es@enricoschumann.net}}

{\raggedright{\LARGE An Overview of the PMwR Package}}\hspace*{\fill}
{\footnotesize Package version \Sexpr{pv}}\medskip

\noindent Enrico Schumann\\
\noindent \url{es@enricoschumann.net}\\
\bigskip

<<echo=false,results=hide>>=
library("PMwR")
library("zoo")
@

\noindent \textsc{pm}w\textsc{r} provides a small set of
reliable, efficient and convenient tools that help with
processing and analysing trade and portfolio data.  The
package does not provide a complete application to be used
`as is', but tools for creating such an application.

\noindent \textsc{pm}w\textsc{r} grew out of various pieces of
software that I have written since 2008.%
\footnote{In the unlikely case that you come across a
  really-old version of the package: it was called \textsc{pm}
  before 2012.} %
The interfaces of functions may still not be fully stable
(e.g., argument names might still be made consistent across
functions); in some cases, generic functions might be
introduced.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\footnote{
<<echo=false,results=hide>>=
if (requireNamespace("tinytest")) {
    tinytest.results <- try(suppressMessages(
        suppressWarnings(tinytest::test_package("PMwR"))))
    if (inherits(tinytest.results, "try-error"))
        nt <- "several hundred"
    else
        nt <- length(tinytest.results)
} else
    nt <- "several hundred"
@
Even if \textsc{pm}w\textsc{r} is under development: the
package is to provide well-documented and reliable code.
For all computations, unit tests are included.  As of
package version %
\Sexpr{pv}, \Sexpr{nt} tests are included.  These tests are
stored in subdirectory \texttt{tinytest}.} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The \textbf{recommended practice} is therefore to
\textbf{explicitly name arguments in function calls} and
not pass arguments by position.  Any changes in argument
names will be documented in the \texttt{NEWS} file
(\,\url{http://enricoschumann.net/R/packages/PMwR/NEWS}\,)
and so can be easily followed. More details are in the
ChangeLog
(\,\url{http://enricoschumann.net/R/packages/PMwR/ChangeLog}\,).

The package is on \textsc{cran} and can be installed from
there.  The very latest (i.e. development) version of the
package is available
from \url{http://enricoschumann.net/R/packages/PMwR/}\,. To
install that version from within R, type
<<eval=false, results=hide>>=
install.packages('PMwR',
                 repos = c('http://enricoschumann.net/R',
                           getOption('repos')))
@
within a session.  The package depends on several other
packages, which can be obtained from the same
repository and from \textsc{cran}.  The source code is
also hosted at publicly-available repositories; see the
\texttt{DESCRIPTION} file.


\section*{What the package provides}

There are three main topics for which the package
provides functionality:

\begin{description}
\item[Keeping track of transactions] The package provides
  functions that work with journals (sometimes called
  blotters). See \texttt{?journal} and
  \texttt{?position}.
\item[Computing \textsc{p}\&\textsc{l} and returns] See
  \texttt{?pl}, \texttt{?returns}, \texttt{?rc} and
  \texttt{?unit\_prices}.
\item[Testing strategies] See \texttt{?btest}.
\end{description}

% Several examples will be provided in the next section.
% Other than that, there are a number of helper
% functions.
All details are in the manual:
\begin{center}
\url{http://enricoschumann.net/R/packages/PMwR/manual/PMwR.html}
\end{center}

\noindent I am grateful for comments, suggestions and
corrections.  Please send bug reports directly to the
package maintainer, for instance by using
\texttt{bug.report}.\index{bug reports}
<<eval=false>>=
utils::bug.report("[PMwR] Unexpected behaviour in function <XXX>",
                  maintainer("PMwR"), package = "PMwR")
@

\noindent Applications, as long as they are finance-related, should be
discussed on the \texttt{R-SIG-Finance} mailing list:\smallskip

\url{https://stat.ethz.ch/mailman/listinfo/r-sig-finance}


% \noindent New package releases are announced on the
%  \texttt{PMwR-news} mailing list:\smallskip

% \url{https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/nmof-pmwr}
% \medskip

% \noindent An \textsc{rss} feed of the package \textsc{news} file is
% available at\smallskip

% \url{http://enricoschumann.net/R/packages/PMwR/PMwR_news.xml}\,.

% \medskip




% \section*{Examples}
% <<echo=false,results=hide>>=
% library("PMwR")
% @
% \subsection*{Keeping track of transactions}

% List of transactions can be handled as so-called journals.

% Let us invent a small trading history.

% <<journal>>=
% J <- read.table(text = "
% instrument ,  timestamp , amount ,  price
%       MSFT , 2020-05-04 ,     10 ,  178.0
%       MSFT , 2020-05-04 ,    -10 ,  178.5
%       MSFT , 2020-05-05 ,     20 ,  180.7
%       AMZN , 2020-05-06 ,      5 , 2315.0",
% header = TRUE, sep = ",", strip.white = TRUE)
% J$timestamp <- as.Date(J$timestamp)
% J <- as.journal(J)
% J
% @

% A \texttt{summary} method provides some stats.
% <<summary-journal>>=
% summary(J, by.instrument = TRUE, by.timestamp = TRUE)
% @

% The function \texttt{positions} aggregates the trades to a position.
% <<position>>=
% position(J)
% @
% We may as well specifiy one or more timestamps
% <<position-when>>=
% position(J, when = as.Date("2020-05-04") + 0:2)
% @


% \subsection*{Computing P\&L and Returns, and valuing open positions}

% We continue the previous example.
% <<pl>>=
% pl(J)
% @


% pl(along.timestamp, vprice)

% \subsection*{Testing investment strategies}

% <<>>=
% library("PMwR")
% timestamp <- as.Date(row.names(DAX))
% P <- DAX[[1]]

% signal <- function(k) {
%   av <- sum(Close(n = k))/k
%   if (Close() > av)
%     1
%   else
%     -1
% }

% btest(P, signal, k = 5,
%       b = 5)
% @

% single instrument: moving average

% returns in unit of instrument


% vol targeting
% A trivial strategy




\end{document}
