SCM

SCM Repository

[rmetrics] Annotation of /pkg/fPortfolio/test/runit1A.R
ViewVC logotype

Annotation of /pkg/fPortfolio/test/runit1A.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1602 - (view) (download)

1 : wuertz 1448
2 :     # This library is free software; you can redistribute it and/or
3 :     # modify it under the terms of the GNU Library General Public
4 :     # License as published by the Free Software Foundation; either
5 :     # version 2 of the License, or (at your option) any later version.
6 :     #
7 :     # This library is distributed in the hope that it will be useful,
8 :     # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 :     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 :     # GNU Library General Public License for more details.
11 :     #
12 :     # You should have received a copy of the GNU Library General
13 :     # Public License along with this library; if not, write to the
14 :     # Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
15 :     # MA 02111-1307 USA
16 :    
17 :     # Copyrights (C)
18 :     # for this R-port:
19 :     # 1999 - 2007, Diethelm Wuertz, GPL
20 :     # Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
21 :     # info@rmetrics.org
22 :     # www.rmetrics.org
23 :     # for the code accessed (or partly included) from other R-ports:
24 :     # see R's copyright and license files
25 :     # for the code accessed (or partly included) from contributed R-ports
26 :     # and other sources
27 :     # see Rmetrics's copyright file
28 :    
29 :    
30 :     ################################################################################
31 :     # FUNCTION: SIMULATION AND PARAMETER ESTIMATION:
32 :     # 'fASSETS' Class representation for "fASSETS" Objects
33 :     # assetsSim Simulates a set of artificial assets
34 :     # assetsFit Estimates the parameters of set of assets
35 :     # method = "norm" assuming a multivariate Normal distribution
36 :     # method = "snorm" assuming a multivariate skew-Normal distribution
37 :     # method = "st" assuming a multivariate skew-Student-t
38 :     # FUNCTION: PRINT, PLOT AND SUMMARY METHOD:
39 : wuertz 1461 # show.fASSETS S4: Print method for an object of class fASSETS
40 : wuertz 1448 # plot.fASSETS S3: Plot method for an object of class fASSETS
41 :     # summary.fASSETS S3: Summary method for an object of class fASSETS
42 :     # FUNCTION: REQUIRED UTILITY FUNCTION:
43 :     # .msn.quantities Function from R package sn [part of fMultivar]
44 :     ################################################################################
45 :    
46 :    
47 :     test.aaa =
48 :     function()
49 :     {
50 :     # Help File:
51 :     helpFile = function() {
52 : wuertz 1461 example(AssetsModelling, ask = FALSE)
53 : wuertz 1448 return()
54 :     }
55 :     checkIdentical(
56 :     target = class(try(helpFile())),
57 :     current = "NULL")
58 :    
59 :     # Return Value:
60 :     return()
61 :     }
62 :    
63 :    
64 :     # ------------------------------------------------------------------------------
65 :    
66 :    
67 : wuertz 1461 test.assetsSim =
68 : wuertz 1448 function()
69 :     {
70 : wuertz 1461 # assetsSim(n, dim=2, model =
71 :     # list(mu=rep(0, dim), Omega=diag(dim), alpha=rep(0, dim), df=Inf),
72 :     # assetNames = NULL)
73 :    
74 :     # Normel Assets:
75 :     assetsSim(n = 10, dim = 3)
76 :     assetsSim(n = 10, dim = 3,
77 :     list(mu=rep(0, 3), Omega=diag(3), alpha=rep(0, 3), df=Inf))
78 :    
79 :     # Skew Normal Assets:
80 :     assetsSim(n = 10, dim = 3, model =
81 :     list(mu=rep(0, 3), Omega=diag(3), alpha=rep(0.1, 3), df=Inf))
82 :    
83 :     # Student-t Assets:
84 :     assetsSim(n = 10, dim = 3, model =
85 :     list(mu=rep(0, 3), Omega=diag(3), alpha=rep(0, 3), df=4))
86 :    
87 :     # Skew Student-t Assets:
88 :     assetsSim(n = 10, dim = 3, model =
89 :     list(mu=rep(0, 3), Omega=diag(3), alpha=rep(0.1, 3), df=4))
90 :    
91 :     # Add Asset Names:
92 :     assetsSim(n = 10, dim = 3, assetNames = c("A", "B", "C"))
93 : wuertz 1448
94 :     # Return Value:
95 :     return()
96 :     }
97 :    
98 :    
99 :     # ------------------------------------------------------------------------------
100 :    
101 :    
102 : wuertz 1461 test.assetsFit =
103 : wuertz 1448 function()
104 :     {
105 : wuertz 1461 # function (x, method = c("st", "snorm", "norm"), title = NULL,
106 :     # description = NULL, fixed.df = NA, ...)
107 : wuertz 1448
108 : wuertz 1461 # Normal Assets:
109 :     x = assetsSim(n = 1000, dim = 3)
110 :     fit = assetsFit(x, "norm")
111 :     fit
112 :    
113 :     # Skew Normal Assets:
114 :     x = assetsSim(n = 1000, dim = 3, model =
115 :     list(mu=rep(0, 3), Omega=diag(3), alpha=c(-0.5, 0 , 0.5), df=Inf))
116 :     fit = assetsFit(x, "snorm")
117 :     fit
118 :    
119 :     # Student-t Assets:
120 :     x = assetsSim(n = 1000, dim = 3, model =
121 :     list(mu=rep(0, 3), Omega=diag(3), alpha=rep(0, 3), df=4))
122 :     fit = assetsFit(x, "st")
123 :     fit
124 :    
125 :     # Student-t Assets - Fixed df:
126 :     x = assetsSim(n = 1000, dim = 3, model =
127 :     list(mu=rep(0, 3), Omega=diag(3), alpha=rep(0, 3), df=4))
128 :     fit = assetsFit(x, "st", fixed.df = 4)
129 :     fit
130 :    
131 : wuertz 1602 par(ask = FALSE)
132 : wuertz 1461 class(fit)
133 :     print(fit)
134 :     plot(fit) # CHECK X-Label
135 :     summary(fit, doplot = FALSE) # CHECK - add doplot
136 :    
137 : wuertz 1448 # Return Value:
138 :     return()
139 :     }
140 :    
141 :    
142 :     # ------------------------------------------------------------------------------
143 :    
144 :    
145 :     if (FALSE) {
146 :     require(RUnit)
147 :     testResult <- runTestFile("C:/Rmetrics/SVN/trunk/fPortfolio/test/runit1A.R",
148 :     rngKind = "Marsaglia-Multicarry", rngNormalKind = "Inversion")
149 :     printTextProtocol(testResult)
150 :     }
151 :    
152 :    
153 :     ################################################################################
154 :    

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge