% \VignetteIndexEntry{An Overview of the NMOF Package}
% \VignetteKeyword{heuristics}
% \VignetteKeyword{optimize}
\documentclass[a4paper,11pt]{article}
\usepackage[left = 2.5cm, top = 2cm, bottom = 3cm, right = 3.5cm]{geometry}
\usepackage[noae]{Sweave}
\usepackage[scaled=0.9]{inconsolata}
\usepackage{mathptmx}
\usepackage{amsmath,amstext}
\usepackage{hyperref}
\usepackage{natbib}

\SweaveOpts{pdf=FALSE}
\usepackage{color}
\definecolor{grau2}{rgb}{.2,.2,.2}
\definecolor{grau7}{rgb}{.7,.7,.7}
% define *Sweave* layout
\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}}
<<echo=false>>=
library("NMOF")
options(continue = "  ", digits = 5, max.print = 20, width = 85)
pv <- packageVersion("NMOF")
pv <- gsub("(.*)[.](.*)", "\\1-\\2", pv)
@
\begin{document}
{\raggedright{\LARGE An Overview of the NMOF Package}}\hspace*{\fill}
{\footnotesize Package version \Sexpr{pv}}\medskip

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

\section{The book and the package}

\subsection{The book}

`Numerical Methods and Optimization in Finance' (\textsc{nmof},
\citealp{Gilli2019}) is about tools for computational finance,
with emphasis on simulation and optimisation.  Many chapters are
organised as case studies, covering topics such as portfolio insurance
or the valuation of financial derivatives.  In particular, several
chapters explain optimisation heuristics and show in detail how to use
these methods for portfolio selection or the calibration of option
pricing models.  Some highlights:

\begin{itemize}
\item Simulation: how to create random variates under specified
  marginal distributions; how to induce cross-sectional correlation
  (beyond Cholesky for Gaussian variates) and serial dependencies;
  examples for copul\ae; resampling, bootstrapping data sets.

\item Option pricing: binomial trees, finite differences and Monte
  Carlo simulation; but also integration methods for pricing with the
  characteristic function (eg, Heston, Bates,
  Variance-Gamma). Calibration of surfaces under such models.

\item Portfolio optimisation: methods to optimise portfolio under any
  objective function (eg, drawdown, partial moments) and constraints
  (eg, cardinality constraints). Sample programs for classical
  mean-variance analysis are also included.

\item Backtesting: testing trading and investment
  strategies: overfitting, data preparation, and the
  effects of randomness.  Software for backtesting;
  running backtests in parallel; sensitivity and
  robustness checks.

\item Yield-curve calibration: various strategies how to calibrate a
  yield-curve model: through fitting to bootstrapped yields, to bond
  prices or to yields-to-maturity.
\end{itemize}

\subsection{The package}

\noindent The \textsc{nmof} package provides many of the code examples
and data sets used in \cite{Gilli2019}; it also contains several
functions that have not been described in the book.  Notably, the
package provides implementations of a number of optimisation
heuristics, among them Differential Evolution and Genetic Algorithms.
There are also functions for valuing financial instruments, such as
bonds and options, and helper functions for stochastic simulations.



\section{What's in the package}

\subsection{Optimisation}

There are functions for Differential Evolution
(\texttt{DEopt}), Genetic Algorithms (\texttt{GAopt}),
(Stochastic) Local Search (\texttt{LSopt}), Particle
Swarm (\texttt{PSopt}), Simulated Annealing
(\texttt{SAopt}), Threshold Accepting (\texttt{TAopt})
and grid search~(\texttt{gridSearch}).

\subsection{Pricing financial instruments}

For options, see \texttt{{vanillaOptionEuropean}},
\texttt{{vanillaOptionAmerican}}, \texttt{{putCallParity}}.  For
pricing methods that use the characteristic function, see
\texttt{{callCF}}.  For bond/bond-futures pricing, see \texttt{vanillaBond},
\texttt{bundFuture} and \texttt{xtContractValue}.

\subsection{Simulation}

See \texttt{{resampleC}}, \texttt{{mc}} and \texttt{repairMatrix}.

\subsection{Datasets}

See \texttt{{bundData}}, \texttt{{fundData}} and
\texttt{{optionData}}.

\subsection{Code examples from the book}

All \textsf{R} code examples in the book can be displayed (and used)
via the function \texttt{showExample}.  Call it without any argument
to see all examples.
<<>>=
showExample()
@

\subsection{Vignettes}

The package comes with a number of tutorials, written as vignettes.
See \texttt{?vignette} for how to extract the code from these
documents.
<<eval=false>>=
vignette(package = "NMOF")  ## display vignette titles
@
<<echo=false>>=
x <- vignette(package = "NMOF")
cat(paste(strwrap(x$results[,"Title"], exdent = 2), collapse = "\n"))
@



\section{Other resources}

\subsection{Websites}

\noindent The book's website: \url{http://nmof.net} \smallskip

\noindent The package's website:
\url{http://enricoschumann.net/NMOF}\medskip

\noindent The stable version is available from \textsc{cran}. The
development version is available from

\url{http://enricoschumann.net/R/packages/NMOF/index.htm}\medskip

\noindent To install the development version from an R session, type:
<<eval=false>>=
install.packages("NMOF",
                 repos = c("http://enricoschumann.net/R",
                           getOption("repos")))
@

\noindent The package source code is also available in
the GitHub repository

\url{https://github.com/enricoschumann/NMOF}.\smallskip

The book's source code examples are available from GitLab:

\url{https://gitlab.com/NMOF}.\smallskip

\subsection{Manual}

A manual is available from
\url{http://enricoschumann.net/NMOF.htm#NMOFmanual}\,, though it is
still work in process.  The code examples from the manual are also
available from that site.

\subsection{Tests}

A goal for the \textsc{nmof} package is to provide reliable code.
Thus, a large number of test cases is included.
<<echo=false,eval=false>>=
test.rep <- readLines(system.file("unitTests/test_results.txt",
                                  package = "NMOF"))
nt <- gsub(".*\\(([0-9]+) checks?\\).*", "\\1",
           test.rep[grep("\\(\\d+ checks?\\)", test.rep)])
cat("Package version  ", gsub("(.*)[.]([0-9]+)$", "\\1-\\2",
                            packageVersion("NMOF")), "\n",
    "Number of tests: ", sum(as.numeric(nt)), sep = "")
@
These tests are stored in subdirectory \texttt{unitTests}.

\subsection{News, feedback and discussion}

\noindent New package releases and other news related to the book or
the package are announced on the \texttt{NMOF-news} mailing list:\smallskip

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

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

\url{http://enricoschumann.net/R/packages/NMOF/NMOF_news.xml}\,.

\medskip

\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}

\medskip

\noindent Please send bug reports or suggestions directly to the
package maintainer, for instance by using \texttt{bug.report}.
<<eval=false>>=
library("utils")
bug.report("[NMOF] Unexpected behaviour in function XXX",
            maintainer("NMOF"), package = "NMOF")
@


\nocite{Gilli2019}
\bibliographystyle{plainnat}
\bibliography{NMOF}
\end{document}
