1\name{fBasics-package}
2
3
4\alias{fBasics-package}
5\alias{fBasics}
6
7
8\docType{package}
9
10
11\title{Portfolio Modelling, Optimization and Backtesting}
12
13
14\description{
15
16    The Rmetrics "fBasics" package is a collection of functions to
17    explore and to investigate basic properties of financial returns
18    and related quantities.
19
20    The covered fields include techniques of explorative data analysis
21    and the investigation of distributional properties, including
22    parameter estimation and hypothesis testing. Evenmore there are
23    several utility functions for data handling and managemnet.
24
25}
26
27
28\details{
29
30    \preformatted{
31        Package:    \tab fBasics\cr
32        Type:       \tab Package\cr
33        Date:       \tab 2014\cr
34        License:    \tab GPL Version 2 or later\cr
35        Copyright:  \tab (c) 1999-2014 Rmetrics Association\cr
36        Repository: \tab R-FORGE\cr
37        URL:        \tab \url{https://www.rmetrics.org}
38    }
39
40}
41
42
43\section{1 Introduction}{
44
45  The fBasics package contains \emph{basics tools} often required
46  in computational finance and financial engineering. The topics
47  are: basic statistics functions, financial return distributions,
48  hypothesis testing, plotting routines, matrix computations and
49  linear algebra, and some usefule utility functions.
50}
51
52
53
54\section{2 Basic Statistics Functions}{
55
56
57    \emph{Financial Return Statistics}
58
59    % stats-basicStats.R
60    \preformatted{
61    basicStats            Returns a basic statistics summary
62    }
63
64
65    \emph{Distribution Function of Maximum Drawdowns}
66
67    % stats-maxdd.R
68    \preformatted{
69    dmaxdd                Density function of mean Max-Drawdowns
70    pmaxdd                Probability function of mean Max-Drawdowns
71    rmaxdd                Random Variates of mean Max-Drawdowns
72    maxddStats            Expectation of Drawdowns for BM with drift
73    }
74
75
76    \emph{Calculation of Sample Moments}
77
78    % stats-sampleLMoments.R | stats-sampleRobMoments.R
79    \preformatted{
80    sampleLmoments        Computes sample L-moments
81    sampleMED             Returns sample median
82    sampleIQR             returns sample inter quartal range
83    sampleSKEW            returns robust sample skewness
84    sampleKURT            returns robust sample kurtosis
85    }
86
87
88    \emph{Bivariate Interpolation:}
89
90    % stats-interpAkima.R | stats-interpKrige.R | stats-interpLinear.R
91    \preformatted{
92    akimaInterp           Interpolates irregularly spaced points
93    akimaInterpp          Interpolates and smoothes pointwise
94    krigeInterp           Kriges irregularly spaced data points
95    linearInterp          Interpolates irregularly spaced points
96    linearInterpp         Interpolates linearly pointwise
97    }
98
99    \emph{Utility Statistics Functions:}
100
101    \preformatted{
102    colStats              Computes sample statistics by col
103    colSums               Computes sums of values in each col
104    colMeans              Computes means of values in each col
105    colSds                Computes standard deviation of each col
106    colVars               Computes sample variance by col
107    colSkewness           Computes sample skewness by col
108    colKurtosis           Computes sample kurtosis by col
109    colMaxs               Computes maximum values in each col
110    colMins               Computes minimum values in each col
111    colProds              Computes product of values in each col
112    colQuantiles          Computes product of values in each col
113    }
114
115    % stats-rowStats.R
116    \preformatted{
117    rowStats              Computes sample statistics by row
118    rowSums               Computes sums of values in each row
119    rowMeans              Computes means of values in each row
120    rowSds                Computes standard deviation of each row
121    rowVars               Computes sample variance by row
122    rowSkewness           Computes sample skewness by row
123    rowKurtosis           Computes sample kurtosis by row
124    rowMaxs               Computes maximum values in each row
125    rowMins               Computes minimum values in each row
126    rowProds              Computes product of values in each row
127    rowQuantiles          Computes product of values in each row
128    }
129}
130
131
132\section{3 Financial Return Distributions}{
133
134    \emph{Generalized Hyperbolic Distribution:}
135
136    % dist-gh.R | dist-ghFit.R | dist-ghMode.R | dist-ghMoments.R |
137    % dist-ghRobMoments.R
138    \preformatted{
139    dghReturns            Density for the GH distribution
140    pghreturns            Probability for the GH distribution
141    qghreturns            Quantiles for the GH distribution
142    rghreturns            Random variates for the GH distribution
143    ghFitFits             Fits parameters of the GH distribution
144    ghMode                Computes mode of the GH distribution.
145    ghMean                Returns true mean of the GH distribution
146    ghVar                 Returns true variance of the GH distribution
147    ghSkew                Returns true skewness of the GH distribution
148    ghKurt                Returns true kurtosis of the GH distribution
149    ghMoments             Returns true n-th moment of the GH distribution
150    ghMED                 Returns true median of te GH distribution
151    ghIQR                 Returns true inter quartal range of te GH
152    ghSKEW                Returns true robust skewness of te GH
153    ghKURT                Returns true robust kurtosis of te GH
154    }
155
156
157    \emph{Hyperbolic Distribution:}
158
159    % dist-hyp.R | dist-hypFit.R | dist-hypMode.R | dist-hypMoments.R
160    % dist-hypRobMoments.R
161    \preformatted{
162    dhyp                  Returns density for the HYP distribution
163    phyp                  Returns probability for the HYP distribution
164    qhyp                  Returns quantiles for the HYP distribution
165    rhyp                  Returns random variates for the HYP distribution
166    hypFit                Fits parameters of the HYP distribution
167    hypMode               Computes mode of the HYP distribution
168    hypMean               Returns true mean of the HYP distribution
169    hypVar R              Returns true variance of the HYP distribution
170    hypSkew               Returns true skewness of the HYP distribution
171    hypKurt               Returns true kurtosis of the HYP distribution
172    hypMoments            Returns true n-th moment of the HYP distribution
173    hypMED                Returns true median of the HYP distribution
174    hypIQR                Returns true inter quartal range of the HYP
175    hypSKEW               Returns true robust skewness of the HYP
176    hypKURT               Returns true robust kurtosis of the HYP
177    }
178
179
180    \emph{Normal Inverse Gaussian:}
181
182    % dist-nig.R | dist-nigFit.R | dist-nigMode.R | dist-nigMoments.R
183    % dist-nigRobMoments.R
184    \preformatted{
185    dnig                  Returns density for the NIG distribution
186    pnig                  Returns probability for the NIG distribution
187    qnig                  Returns quantiles for the NIG distribution
188    rnig                  Returns random variates for the NIG distribution
189      .pnigC              fast C Implementation of function pnig()
190      .qnigC              fast CImplementation of function qnig()
191    nigFit                Fits parameters of a NIG distribution
192      .nigFit.mle         Uses max Log-likelihood estimation
193      .nigFit.gmm         Uses generalized method of moments
194      .nigFit.mps         Maximum product spacings estimation
195      .nigFit.vmps        Minimum variance mps estimation
196    nigMode               Computes mode of the NIG distribution
197    nigMean               Returns true mean of the NIG distribution
198    nigVar                Returns true variance of the NIG distribution
199    nigSkew               Returns true skewness of the NIG distribution
200    nigKurt               Returns true kurtosis of the NIG distribution
201    nigMoments            Returns true n-th moment of the NIG distribution
202    nigMED                Returns true median of the NIG distribution
203    nigIQR                Returns true inter quartal range of the NIG
204    nigSKEW               Returns true robust skewness of the NIG
205    nigKURT               Returns true robust kurtosis of the NIG
206    }
207
208
209    \emph{Generalized Hyperbolic Student-t Distribution:}
210
211    % dist-ght.R | dist-ghtFit.R | dist-ghtMode.R | dist-ghtMoments.R |
212    % dist-ghtRobMoments.R
213    \preformatted{
214    dght                  Returns density for the GHT distribution
215    pght                  Returns probability for the GHT distribution
216    qght                  Returns quantiles for the GHT distribution
217    rght                  Returns random variates for the GHT distribution
218    ghtFit                Fits parameters of the GHT distribution
219    ghtMode               Computes mode of the GHT distribution
220    ghtMean               Returns true mean of the NIG distribution
221    ghtVar                Returns true variance of the GHT distribution
222    ghtSkew               Returns true skewness of the GHT distribution
223    ghtKurt               Returns true kurtosis of the GHT distribution
224    ghtMoments            Returns true n-th moment of the GHT distribution
225    ghtMED                Returns true median of the GHT distribution
226    ghtIQR                Returns true inter quartal range of the GHT
227    ghtSKEW               Returns true robust skewness of the GHT
228    ghtKURT               Returns true robust kurtosis of the GHT
229    }
230
231
232    \emph{Stable Distribution:}
233
234    % dist-stable.R | dist-stableFit.R | dist-stableMode.R
235    \preformatted{
236    dstable               Returns density for the stable distribution
237    pstable               Returns probability for the stable distribution
238    qstable               Returns quantiles for the stable distribution
239    rstable               Returns random variates for the dtsble distribution
240    stableFit             Fits parameters of a the stable distribution
241      .phiStable          Creates contour table for McCulloch estimators
242      .PhiStable          Contour table created by function .phiStable()
243      .qStableFit         Estimates parameters by McCulloch's approach
244      .mleStableFit       Estimates stable parameters by MLE approach
245      .stablePlot         Plots results of stable parameter estimates
246    stableMode            Computes mode of the stable distribution
247    }
248
249
250    \emph{Generalized Lambda Distribution:}
251
252    % dist-gld.R | dist-gldFit.R | dist-gldMode.R |
253    % dist-gldRobMoments.R
254    \preformatted{
255    dgld                  Returns density for the GLD distribution
256    pgld                  Returns probability for the GLD distribution
257    qgld                  Returns quantiles for the GLD distribution
258    rgld                  Returns random variates for the GLD distribution
259    gldFit                Fits parameters of the GLD distribution
260      .gldFit.mle         fits GLD using maximum log-likelihood
261      .gldFit.mps         fits GLD using maximum product spacings
262      .gldFit.gof         fits GLD using Goodness of Fit statistics
263                          % .ksGLDKolmogorov-Smirnov Statistics
264                          % .cvmGLDCramer-vonMise Statistics
265                          % .adGLDAnderson-Darling Statistics
266      .gldFit.hist        fits GLD using a histogram fit
267      .gldFit.rob         fits GLD using robust moments fit
268    gldMode               Computes mode of the GLD distribution.
269    gldMED                Returns true median of the GLD distribution
270    gldIQR                Returns true inter quartal range of the GLD
271    gldSKEW               Returns true robust skewness of the GLD
272    gldKURT               Returns true robust kurtosis of the GLD
273    }
274
275
276    \emph{Spline Smoothed Distribution:}
277
278    % dist-ssd.R | dist-ssdFit.R
279    \preformatted{
280    dssd                  Returns spline smoothed density function
281    pssd                  Returns spline smoothed probability function
282    qssd                  Returns spline smoothed quantile function
283    rssd                  Returns spline smoothed random variates.
284    ssdFit                Fits parameters for a spline smoothed distribution
285    }
286}
287
288
289\section{4 Hypthesis Testing}{
290
291
292    \emph{One Sample Nornality Tests:}
293
294    % test-normalTest.R
295    \preformatted{
296    ksnormTest            One sample Kolmogorov-Smirnov normality test
297    shapiroTest           Shapiro-Wilk normality test
298    jarqueberaTest        Jarque-Bera normality test
299    normalTest            Normality tests S-Plus compatible call
300    dagoTest              D'Agostino normality test
301    adTest                Anderson-Darling normality test
302    cvmTest               Cramer-von Mises normality test
303    lillieTest            Lilliefors (KS) normality test
304    pchiTest              Pearson chi-square normality test
305    sfTest                Shapiro-Francia normality test
306    jbTest                Finite sample adjusted JB LM and ALM test
307    }
308
309
310    \emph{One Sample Location, Scale and variance Tests:}
311
312    % test-locationTest.R | test-scaleTest.R | test-variance Test.R
313    \preformatted{
314    locationTest          Performs locations tests on two samples
315      .tTest              Unpaired t test for differences in mean
316      .kw2Test            Kruskal-Wallis test for differences in locations
317    scaleTest             Performs scale tests on two samples
318      .ansariTest         Ansari-Bradley test for differences in scale
319      .moodTest           Mood test for differences in scale
320    varianceTest          Performs variance tests on two samples
321      .varfTest           F test for differences in variances
322      .bartlett2Test      Bartlett's test for differences in variances
323      .fligner2Test       Fligner-Killeen test for differences in variances
324    }
325
326
327    \emph{Two Sample Tests:}
328
329    % test-ks2Test.R
330    \preformatted{
331    ks2Test               Performs a two sample Kolmogorov-Smirnov test
332    correlationTest       Performs correlation tests on two samples
333    pearsonTest           Pearson product moment correlation coefficient
334    kendallTest           Kendall's tau correlation test
335    spearmanTest          Spearman's rho correlation test
336    }
337
338
339    \emph{Test Utilities:}
340
341    % test-fHTEST.R
342    \preformatted{
343    'fHTEST'              S4 Class Representation
344    show.fHTEST           S4 Print Method
345      .jbALM              Jarque Bera Augmented Lagrange Multiplier Data
346      .jbLM               Jarque-Bera Lagrange Multiplier Data
347      .jbTable            Finite sample p values for the Jarque Bera test
348      .jbPlot             Plots probabilities
349      .pjb                Returns probabilities for JB given quantiles
350      .qjb                Returns quantiles for JB given probabilities
351    }
352
353}
354
355
356\section{5 Plotting Routines}{
357
358
359    \emph{Financial Time Series Plots:}
360
361    % plot-seriesPlot.R
362    \preformatted{
363    seriesPlot            Dispalys a time series plot
364    cumulatedPlot         Displays cumulated series give returns
365    returnPlot            Displays returns given cumulated series
366    drawdownPlot          Displays drawdown series from returns
367    }
368
369
370    \emph{Correlation Plots:}
371
372    % plot-acfPlot.R
373    \preformatted{
374    acfPlot               Displays tailored ACF plot
375    pacfPlot              Displays tailored partial ACF plot
376    teffectPlot           Displays the Taylor effect
377    lacfPlot              Displays lagged autocorrelations
378    }
379
380
381    \emph{Distribution Plots:}
382
383    % plot-histPlot.R | plot-qqPlot.R plot-boxPlot.R
384    \preformatted{
385    histPlot              Returns tailored histogram plot
386    densityPlot           Returns tailored density plot
387    logDensityPlot        Returns tailored log density plot
388    boxPlot               Returns side-by-side standard box plot
389    boxPercentile         Plotreturns box-percentile plot
390    qqnormPlot            Returns normal quantile-quantile plot
391    qqnigPlot             Returns NIG quantile-quantile plot
392    qqghtPlot             Rreturns  GHT quantile-quantile plot
393    qqgldPlot             Returns GLD quantile-quantile plot
394    }
395
396
397    \emph{ Time Series Aggregation Plots:}
398
399    % plot-scalinglawPlot.R
400    \preformatted{
401    scalinglawPlot        Displays scaling law behavior
402    }
403
404}
405
406
407\section{5. Matrix Computations and Linear Algebra}{
408
409
410    \emph{Elementar Matrix Operation Addons:}
411
412    % matrix-kron.R | matrix-vech.R | matrix-pdl.R | matrix-tslag.R
413    \preformatted{
414    kron                  Returns the Kronecker product
415    vec                   Stacks a matrix as column vector
416    vech                  Stacks a lower triangle matrix
417    pdl                   Returns regressor matrix for polynomial lags
418    tslag                 Returns Lagged/leading vector/matrix
419    }
420
421
422    \emph{Linear Algebra Addons:}
423
424    % matrix-inv.R | matrix-norm.R | matrix-rk.R | matrix-tr.R
425    \preformatted{
426    inv                   Returns the inverse of a matrix
427    norm                  Returns the norm of a matrix
428    rk                    Returns the rank of a matrix
429    tr                    Returns the trace of a matrix
430    }
431
432
433    \emph{General Matrix Utility Addons:}
434
435    % matrix-posDefinite.R | matrix-colVec.R | matrix-gridVector.R |
436    % matrix-triang.R
437    \preformatted{
438    isPositiveDefinite    Checks if a matrix is positive definite
439    makePositiveDefinite  Forces a matrix to be positive definite
440    colVec                Creates a column vector from a data vector
441    rowVec                Creates a row vector from a data vector
442    gridVector            Creates from two vectors rectangular grid
443    triang                Extracs lower tridiagonal part from a matrix
444    Triang                Extracs upper tridiagonal part from a matrix
445    }
446
447
448    \emph{Selected Matrix Examples:}
449
450    % matrix-hilbert.R | matrix-pascal.R
451    \preformatted{
452    hilbert               Creates a Hilbert matrix
453    pascal                Creates a Pascal matrix
454    }
455
456}
457
458
459\section{6 Utility Functions}{
460
461
462    \emph{Color Utilities:}
463
464    % utils-colorLocator.R | utils-colorTable.R | utils-colorPalette.R
465    \preformatted{
466    colorLocator            Plots Rs 657 named colors for selection
467    colorMatrix             Returns matrix of R's color names.
468    colorTable              Table of Color Codes and Plot Colors itself
469    rainbowPalette          Contiguous rainbow color palette
470    heatPalette             Contiguous heat color palette
471    terrainPalette          Contiguous terrain color palette
472    topoPalette             Contiguous topo color palette
473    cmPalette               Contiguous cm color palette
474    greyPalette             R's gamma-corrected gray palette
475    timPalette              Tim's Matlab like color palette
476    rampPalette             Color ramp palettes
477    seqPalette              Sequential color brewer palettes
478    divPalette              Diverging color brewer palettes
479    qualiPalette            Qualified color brewer palettes
480    focusPalette            Red, green blue focus palettes
481    monoPalette             Red, green blue mono palettes
482    }
483
484
485    \emph{Graphics Utilities:}
486
487
488    % utils-symbolTable.R | utils-characterTable.R | utils-decor.R |
489    % utils-interactivePlot.R
490    \preformatted{
491    symbolTable             Shows a table of plot symbols
492    characterTable          Shows a table of character codes
493    decor                   Adds horizontal grid and L shaped box
494    hgrid                   Adds horizontal grid lines
495    vgrid                   Adds vertical grid lines
496    boxL                    Adds L-shaped box
497    box                     Adds unterlined box
498      .xrug                 Adds rugs on x axis
499      .yrug                 Adds rugs on y axis
500    copyright               Adds copyright notice
501    interactivePlot         Plots several graphs interactively
502    }
503
504
505    \emph{Special Function Utilities:}
506
507
508    %  utils-heaviside.R | utils-hessian.R
509    \preformatted{
510    Heaviside               Computes Heaviside unit step function
511    Sign                    Another signum function
512    Delta                   Computes delta function
513    Boxcar                  Computes boxcar function
514    Ramp                    Computes ramp function
515    tsHessian               Computes Two Sided Hessian matrix
516    }
517
518
519    \emph{Other Utilities:}
520
521
522    % utils-unitrootNA.R | utils-getS4.R
523    \preformatted{
524    .unirootNA              Computes zero of a function without error exit
525    getModel                Extracts the model slot from a S4 object
526    getTitle                Extracts the title slot from a S4 object
527    getDescription          Extracts the description slot
528    getSlot                 Extracts a specified slot from a S4 object
529    }
530
531}
532
533
534\section{About Builtin Functions}{
535
536
537    Builtin functions are borrowed from contributed R packages and other
538    sources.
539    There are several reasons why we have modified and copied code from
540    other sources and included in this package.
541
542    * The builtin code is not available on Debian, so that Linux users
543      have no easy acces to this code.
544
545    * The original code conflicts with other code from this package or
546      conflicts with Rmetrics design objectives.
547
548    * We only need a very small piece of functionality from the original
549      package which may depend on other packages which are not needed.
550
551    * The package from which we builtin the code is under current
552      development, so that the functions often change and thus leads
553      to unexpectect behavior in the Rmetrics packages.
554
555    * The package may be incompatible since it uses other time date
556      and time series classes than the 'timDate' and 'timeSeries' objects
557      and methods from Rmetrics.
558
559    We put the code in script files named \emph{builtin-funPackage.R}
560    where "fun" denotes the (optional) major function name, and
561    "Package" the name of the contributed package from which we
562    copied the original code.
563
564    Builtin functions include:
565
566    \preformatted{
567    gelGmm                gll function from gmm package
568    gmmGMM                gmm function from gmm package
569    kweightsSandwhich     kweights from sandwhich package
570    glGld                 gl functions from gld package
571    ssdenGss              ssden from the gss package
572    hypHyperbolicDist     hyp from HyperbolicDist package
573    }
574}
575
576
577\section{Compiled Fortran and C Code:}{
578
579    \preformatted{
580    gld.c                 source code from gld package
581    nig.c                 source code from Kersti Aas
582    gss.f                 source code fromsandwhich package
583    }
584
585}
586
587
588\section{About Rmetrics:}{
589
590    The \code{fBasics} Rmetrics package is written for educational
591    support in teaching "Computational Finance and Financial Engineering"
592    and licensed under the GPL.
593
594}
595
596
597\keyword{package}
598
599