~ubuntu-branches/ubuntu/trusty/fportfolio/trusty

« back to all changes in this revision

Viewing changes to inst/unitTests/runit.tangencyPortfolio.R

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2008-12-04 11:36:54 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081204113654-gr832nfs44blp5ph
Tags: 280.74-1
* New upstream release
* Finally uploading as r-cran-rglpk is out of NEW after five weeks

* debian/control: Updated (Build-)Depends: and Suggests:

* debian/control: Set (Build-)Depends: to current R version
* debian/control: Set Standards-Version: to current version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
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 - Diethelm Wuertz, GPL
 
20
#   2007 - Rmetrics Foundation, GPL
 
21
#   Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
 
22
# for code accessed (or partly included) from other sources:
 
23
#   see Rmetric's copyright and license files
 
24
 
 
25
 
 
26
################################################################################
 
27
# FUNCTION:
 
28
#  test.tangencyPortfolio.MV.LongOnly
 
29
#  test.tangencyPortfolio.CVaR.LongOnly
 
30
################################################################################
 
31
 
 
32
 
 
33
 
 
34
test.tangencyPortfolio.MV.LongOnly <-
 
35
    function()
 
36
{
 
37
    # Data:
 
38
    data = as.timeSeries(data(smallcap.ts))
 
39
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
 
40
    head(data)
 
41
 
 
42
    # Specification:
 
43
    spec = portfolioSpec()
 
44
    print(spec)
 
45
 
 
46
    # Constraints:
 
47
    constraints = "LongOnly"
 
48
    print(constraints)
 
49
 
 
50
    # Optimization:
 
51
    portfolio = tangencyPortfolio(data, spec, constraints)
 
52
    print(portfolio)
 
53
 
 
54
    # Return Value:
 
55
    return()
 
56
}
 
57
 
 
58
 
 
59
# ------------------------------------------------------------------------------
 
60
 
 
61
 
 
62
test.tangencyPortfolio.CVaR.LongOnly <-
 
63
    function()
 
64
{
 
65
    # Linear Programming - CVaR Portfolio:
 
66
    #   the return is fixed, we minimie the CVaR
 
67
 
 
68
    # Data:
 
69
    data = as.timeSeries(data(smallcap.ts))
 
70
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
 
71
    head(data)
 
72
 
 
73
    # CVaR Specification:
 
74
    spec = portfolioSpec()
 
75
    setType(spec) = "CVaR"
 
76
    setTargetReturn(spec) = mean(colMeans(data))
 
77
    setAlpha(spec) = 0.05
 
78
    print(spec)
 
79
 
 
80
    # Constraints:
 
81
    constraints = "LongOnly"
 
82
    print(constraints)
 
83
 
 
84
    # CVaR Portfolio:
 
85
    portfolio = tangencyPortfolio(data, spec, constraints)
 
86
    print(portfolio)
 
87
 
 
88
    # Return Value:
 
89
    return()
 
90
}
 
91
 
 
92
 
 
93
################################################################################
 
94