How to use financial risk modeling with-R

financial risk modeling with-R


R is a collaborative project with many contributors.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Workspace loaded from ~/.RData]

Loading required package: fOptions
Loading required package: timeDate
Loading required package: timeSeries
Loading required package: fBasics
> library("OptionPricing", lib.loc="~/R/win-library/3.6")
> library("OptHedging", lib.loc="~/R/win-library/3.6")
> library("DEoptimR", lib.loc="~/R/win-library/3.6")
> library("fExoticOptions", lib.loc="~/R/win-library/3.6")
> library("fOptions", lib.loc="~/R/win-library/3.6")
> library("FRAPO", lib.loc="~/R/win-library/3.6")
Loading required package: cccp
Loading required package: Rglpk
Loading required package: slam
Using the GLPK callable library version 4.47
Financial Risk Modelling and Portfolio Optimisation with R (version 0.4-1)

> data(StockIndex)
> head(StockIndex)
            SP500  N225 FTSE100  CAC40   GDAX    HSI
1991-07-31 387.81 24121  2588.8 1754.7 1622.3 4009.0
1991-08-30 395.43 22336  2645.7 1864.3 1650.5 3998.0
1991-09-30 387.86 23916  2621.7 1880.6 1607.0 3956.7
1991-10-31 392.45 25222  2566.0 1856.7 1582.1 4038.7
1991-11-29 375.22 22687  2420.2 1739.7 1566.6 4149.8
1991-12-30 415.14 22984  2420.0 1741.9 1578.0 4275.2
> tail(StockIndex)
             SP500     N225 FTSE100   CAC40    GDAX
2011-01-31 1286.12 10237.92  5862.9 4005.50 7077.48
2011-02-28 1327.22 10624.09  5994.0 4110.35 7272.32
2011-03-31 1325.83  9755.10  5908.8 3989.18 7041.31
2011-04-28 1360.48  9849.74  6069.9 4104.90 7475.22
2011-05-31 1345.20  9693.73  5990.0 4006.94 7293.69
2011-06-30 1320.64  9816.09  5945.7 3982.21 7376.24
                HSI
2011-01-31 23447.34
2011-02-28 23338.02
2011-03-31 23527.52
2011-04-28 23805.63
2011-05-31 23684.13
2011-06-30 22398.10
> y <- StockIndex[, "SP500"]
> cs <- capser(y, min = 100, max = 200)
> head(cs)
[1] 200 200 200 200 200 200
> yret <- diff(log(y))
> bilson <- trdbilson(yret, exponent = 2)
> head(bilson)
[1]  0.01948730 -0.01935785  0.01177193 -0.04517835
[5]  0.10349955 -0.01545405
> yret <- diff(log(y))
> es <- trdes(yret, lambda = 0.95)
> head(es)
[1]  0.018485339 -0.017438597  0.010304526
[4] -0.042136563  0.093941299 -0.009969699
> hp <- trdhp(y, lambda = 1600)
> head(hp)
[1] 387.1268 389.8778 392.6293 395.3850 398.1460
[6] 400.9114
> sma <- trdsma(y, n.periods = 24)
> head(sma, 30)
 [1]       NA       NA       NA       NA       NA
 [6]       NA       NA       NA       NA       NA
[11]       NA       NA       NA       NA       NA
[16]       NA       NA       NA       NA       NA
[21]       NA       NA       NA 418.2483 420.7617
[26] 423.6004 426.5617 429.7025 433.3096 435.5387
> wma <- trdwma(y, weights = c(0.4, 0.3, 0.2, 0.1))
> head(wma, 30)
 [1]      NA      NA      NA 391.205 384.938 395.898
 [7] 402.343 408.264 408.556 410.505 412.633 411.220
[13] 416.691 416.362 417.228 418.201 423.188 430.449
[19] 435.296 439.885 445.320 444.131 446.805 448.474
[25] 448.468 454.988 457.319 462.336 463.207 465.452
> data(MultiAsset)
> head(MultiAsset)
              GSPC    RUA    GDAXI   FTSE     N225
2004-11-30 1173.82 670.84 4126.000 4703.2 10899.25
2004-12-31 1211.92 693.63 4273.805 4814.3 11498.42
2005-01-31 1181.27 674.54 4254.850 4852.3 11387.59
2005-02-28 1203.60 688.05 4350.490 4968.5 11740.60
2005-03-31 1180.59 675.45 4348.770 4894.4 11668.95
2005-04-29 1156.85 660.02 4184.840 4801.7 11005.51
             EEM   DJCBTI  GREXP BG05.L   GLD
2004-11-30 19.50 131.6900 302.60 151.93 45.12
2004-12-31 20.43 132.9700 303.80 152.88 43.80
2005-01-31 20.32 133.4700 306.63 152.46 42.22
2005-02-28 22.29 131.7300 305.64 150.47 43.52
2005-03-31 20.53 131.1500 306.70 150.92 42.82
2005-04-29 20.27 133.7033 311.74 153.09 43.35
> Rets <- returnseries(MultiAsset, method = "discrete", trim = TRUE)
> w <- Weights(PMD(Rets))
Iteration: 0
pobj: 0.11477
dobj: -0.961072
pinf: 0
dinf: 3.76706
dgap: 1.07584

Iteration: 1
pobj: 0.113632
dobj: 0.00263219
pinf: 2.22045e-016
dinf: 0.387308
dgap: 0.111

Iteration: 2
pobj: 0.110322
dobj: 0.0805013
pinf: 2.22045e-016
dinf: 0.095544
dgap: 0.0298208

Iteration: 3
pobj: 0.107587
dobj: 0.0965035
pinf: 4.44089e-016
dinf: 0.0295032
dgap: 0.0110831

Iteration: 4
pobj: 0.105282
dobj: 0.102542
pinf: 8.88178e-016
dinf: 0.00180192
dgap: 0.00273982

Iteration: 5
pobj: 0.10454
dobj: 0.103948
pinf: 1.77636e-015
dinf: 9.80713e-005
dgap: 0.000592444

Iteration: 6
pobj: 0.104348
dobj: 0.10421
pinf: 3.33067e-015
dinf: 8.12006e-006
dgap: 0.000138232

Iteration: 7
pobj: 0.104303
dobj: 0.104281
pinf: 6.43929e-015
dinf: 3.19953e-007
dgap: 2.13694e-005

Iteration: 8
pobj: 0.104297
dobj: 0.104295
pinf: 1.24345e-014
dinf: 2.46719e-008
dgap: 2.67608e-006

Iteration: 9
pobj: 0.104297
dobj: 0.104296
pinf: 2.22045e-014
dinf: 5.00253e-009
dgap: 6.11958e-007

Iteration: 10
pobj: 0.104297
dobj: 0.104297
pinf: 4.13003e-014
dinf: 6.97906e-010
dgap: 1.06644e-007

Iteration: 11
pobj: 0.104297
dobj: 0.104297
pinf: 7.92699e-014
dinf: 5.72651e-011
dgap: 1.18903e-008

Optimal solution found.
> V <- cov(Rets)
> DR <- dr(w, V)
> CR <- cr(w, V)
> RhoW <- rhow(w, V)
> test <- 1 / sqrt(RhoW * (1 - CR) + CR)
> all.equal(DR, test)
[1] TRUE
> showClass("PortSol")
Class "PortSol" [package "FRAPO"]

Slots:
                                             
Name:    weights       opt      type      call
Class:   numeric      list character      call

Known Subclasses: "PortCdd", "PortAdd", "PortMdd"
> showClass("PortMdd")
Class "PortMdd" [package "FRAPO"]

Slots:
                                                 
Name:       MaxDD   DrawDown    weights        opt
Class:    numeric timeSeries    numeric       list
                           
Name:        type       call
Class:  character       call

Extends: "PortSol", "PortDD"
> popt <- PMinCDaR(PriceData = StockIndex, alpha = 0.95, softBudget = FALSE)
>
> head(popt)
Error in x[seq_len(n)] : object of type 'S4' is not subsettable
> data(ESCBFX)
> head(ESCBFX)
              AUD    CAD    CHF     GBP    HKD
1999-01-04 1.9100 1.8004 1.6168 0.71110 9.1332
1999-01-05 1.8944 1.7965 1.6123 0.71220 9.1341
1999-01-06 1.8820 1.7711 1.6116 0.70760 9.1010
1999-01-07 1.8474 1.7602 1.6165 0.70585 9.0131
1999-01-08 1.8406 1.7643 1.6138 0.70940 9.0302
1999-01-11 1.8134 1.7463 1.6104 0.70440 8.9655
              JPY    USD
1999-01-04 133.73 1.1789
1999-01-05 130.96 1.1790
1999-01-06 131.42 1.1743
1999-01-07 129.43 1.1632
1999-01-08 130.09 1.1659
1999-01-11 126.33 1.1569
> data(EuroStoxx50)
> head(EuroStoxx50)
           AABA.AS ACA.PA AGN.AS AI.PA AIB.IR
2003-03-03   10.40  11.42   5.54 23.30  10.39
2003-03-10   11.26  11.93   6.58 24.30  10.77
2003-03-17   12.16  12.04   6.70 26.33  11.06
2003-03-24   11.34  12.21   6.17 25.53  10.63
2003-03-31   11.97  12.52   6.32 26.60  10.75
2003-04-07   12.51  13.18   6.53 27.32  10.89
           ALV.DE BAS.DE BAY.DE BBVA.MC BN.PA
2003-03-03  56.75  28.55  10.46    5.91 10.14
2003-03-10  55.19  27.03   8.84    6.31 10.59
2003-03-17  55.97  33.34  12.06    6.90 11.19
2003-03-24  45.69  31.04  11.28    6.53 11.11
2003-03-31  45.71  33.63  12.24    7.16 11.82
2003-04-07  51.91  33.72  13.24    7.30 12.19
           BNP.PA CA.PA ALU.PA CS.PA DBK.DE DAI.DE
2003-03-03  30.83 28.76   6.00  9.86  33.69  21.66
2003-03-10  33.63 31.50   6.33 11.68  32.37  20.77
2003-03-17  36.37 34.71   6.93 12.20  39.36  24.24
2003-03-24  33.33 32.86   6.53 11.40  35.97  22.64
2003-03-31  35.52 33.99   6.62 11.64  37.35  23.83
2003-04-07  34.79 33.48   6.94 11.76  37.84  24.65
           DTE.DE ELE.MC ENEL.MI ENI.MI EOA.DE
2003-03-03   9.64   8.37    3.14   9.94  30.05
2003-03-10   9.66   8.45    3.11   9.62  27.36
2003-03-17  10.02   9.04    3.14   9.97  30.51
2003-03-24   9.84   8.90    3.22   9.68  30.37
2003-03-31  10.74   9.28    3.27  10.25  32.16
2003-04-07  10.66   9.86    3.23  10.24  32.30
           FORA.AS FP.PA FTE.PA  G.MI GLE.PA IBE.MC
2003-03-03    6.62  4.33  15.99 18.77  36.82   0.47
2003-03-10    7.81  4.40  18.65 19.17  38.47   0.49
2003-03-17    8.32  4.49  17.76 18.83  42.91   0.49
2003-03-24    7.56  4.40  16.62 18.33  39.37   0.50
2003-03-31    8.12  4.57  17.00 17.48  41.02   0.50
2003-04-07    8.88  4.50  17.83 17.65  41.93   0.50
           INGA.AS ISP.MI LG.PA MC.PA MUV2.DE
2003-03-03    8.06   1.14 41.53 34.51   68.87
2003-03-10    9.38   1.17 44.05 37.42   65.29
2003-03-17   10.18   1.27 49.12 38.24   69.82
2003-03-24    9.25   1.22 45.07 35.03   50.55
2003-03-31    9.80   1.24 48.18 33.92   54.81
2003-04-07   10.62   1.24 48.48 36.27   62.00
           NOA3.DE OR.PA PHIA.AS REP.MC RNO.PA
2003-03-03   11.00 52.24   11.98  11.46  27.27
2003-03-10   12.56 55.46   13.61  11.52  27.55
2003-03-17   14.16 56.63   15.42  12.36  29.84
2003-03-24   12.83 54.71   13.89  12.20  26.31
2003-03-31   13.23 59.33   14.23  12.38  28.11
2003-04-07   12.88 60.27   14.76  12.62  27.42
           RWE.DE SAN.MC SAN.PA SAP.DE SGO.PA
2003-03-03  18.49   2.57  41.31  16.18  22.53
2003-03-10  17.43   2.75  41.66  17.72  22.75
2003-03-17  20.07   3.04  45.94  18.13  24.47
2003-03-24  19.51   2.87  42.99  16.74  23.76
2003-03-31  20.57   3.13  46.38  17.19  24.95
2003-04-07  20.68   3.18  46.16  18.71  25.52
           SIE.DE SZE.PA TEF.MC TIT.MI UC.MI VIV.PA
2003-03-03  33.67  10.06   7.68   4.74  2.20   9.89
2003-03-10  33.47   9.79   7.97   4.78  2.43  11.65
2003-03-17  38.86  10.43   8.70   5.08  2.59  12.38
2003-03-24  36.01  10.00   8.15   5.22  2.48  11.48
2003-03-31  37.80  10.90   8.66   5.44  2.57  11.42
2003-04-07  38.34  11.03   8.88   5.75  2.66  10.92
> data(FTSE100)
> head(FTSE100)
             AAL.L ABF.L  AL.L AMEC.L ANTO.L   AV.L
2003-03-03 1141.96 474.0 743.0 195.00  11.79 318.12
2003-03-10 1198.07 501.0 779.5 185.00  11.50 325.84
2003-03-17 1282.87 520.0 837.5 200.00  11.41 363.84
2003-03-24 1169.37 503.0 784.0 199.00  10.78 325.63
2003-03-31 1198.70 514.5 827.5 212.75  11.50 332.28
2003-04-07 1185.31 514.5 835.5 237.50  11.78 330.57
             AZN.L   BA.L BARC.L BATS.L  BAY.L
2003-03-03 1741.75 116.00 338.00  597.0  94.75
2003-03-10 1737.40 121.00 349.50  599.0 102.50
2003-03-17 1966.97 129.75 393.75  621.0 125.00
2003-03-24 1912.18 113.00 374.50  596.5 108.50
2003-03-31 1940.88 127.00 398.00  570.0 115.75
2003-04-07 1900.01 122.00 400.00  587.0 116.75
             BG.L BGY.L BLND.L  BLT.L   BP.L BSY.L
2003-03-03 237.00  4.60 418.22 240.86 331.36 610.0
2003-03-10 246.00  4.40 402.05 251.10 335.56 626.0
2003-03-17 257.00  4.10 422.45 264.68 358.82 650.5
2003-03-24 248.25  3.75 411.51 255.62 346.87 648.0
2003-03-31 258.50  3.60 396.83 263.30 349.18 666.5
2003-04-07 253.50  4.00 399.81 262.71 339.33 628.0
           BT-A.L  CNE.L CPG.L  CPI.L CPW.L  CW.L
2003-03-03 153.00 470.86 254.5 247.72 51.75 50.41
2003-03-10 160.00 466.56 264.5 251.73 54.75 53.89
2003-03-17 176.75 447.47 300.0 274.95 65.00 51.71
2003-03-24 166.00 460.50 279.0 267.75 63.00 63.01
2003-03-31 171.25 465.77 282.0 265.61 62.00 69.31
2003-04-07 173.50 462.01 282.0 269.88 62.75 69.10
           DGE.L ETI.L  FGP.L  FP.L GSK.L HBOS.L
2003-03-03 615.5 34.93 228.75 75.50  1055 572.35
2003-03-10 640.0 35.41 232.00 73.00  1126 591.27
2003-03-17 674.0 36.44 245.25 89.00  1195 651.72
2003-03-24 664.5 37.16 239.25 80.75  1138 622.44
2003-03-31 680.0 35.62 224.00 87.00  1196 651.72
2003-04-07 676.0 37.19 220.00 92.00  1210 655.02
           HMSO.L HSBA.L  III.L  IMT.L IPR.L ITV.L
2003-03-03 468.88 463.95 668.38  972.5 70.00 52.00
2003-03-10 433.15 472.00 680.88 1001.5 74.25 53.25
2003-03-17 442.02 504.71 758.82 1027.5 82.00 65.50
2003-03-24 427.73 484.14 627.94 1020.0 87.25 59.50
2003-03-31 413.19 498.09 644.85 1044.0 89.50 64.25
2003-04-07 429.70 495.15 640.07 1075.0 93.00 63.75
           JMAT.L LAND.L LGEN.L LLOY.L  LMI.L
2003-03-03    755 712.10  66.00 311.25 593.49
2003-03-10    794 675.86  67.50 336.00 588.50
2003-03-17    820 731.69  82.75 369.75 584.27
2003-03-24    777 721.89  74.00 333.50 526.61
2003-03-31    796 712.10  76.25 352.00 533.53
2003-04-07    799 717.97  73.50 373.00 546.98
            LSE.L  MKS.L  MRW.L NXT.L OML.L  PRU.L
2003-03-03 298.25 280.00 147.00 747.5 44.36 255.50
2003-03-10 286.75 286.00 166.75 777.0 49.12 281.52
2003-03-17 301.00 308.00 185.00 832.5 55.14 325.99
2003-03-24 292.25 289.25 179.75 855.5 50.38 298.23
2003-03-31 292.50 294.00 179.50 886.5 52.92 306.29
2003-04-07 303.00 275.75 189.75 870.5 55.93 312.33
            PSN.L PSON.L  RBS.L RDSB.L  REL.L
2003-03-03 354.75 501.00 316.82 351.12 502.50
2003-03-10 348.59 496.00 340.21 359.54 525.60
2003-03-17 347.72 528.50 378.26 385.29 577.01
2003-03-24 337.89 502.25 364.08 390.49 554.48
2003-03-31 329.81 532.00 388.70 389.50 575.28
2003-04-07 350.34 513.00 387.21 382.82 540.04
            REX.L RIO.L RSA.L RSL.L  RTO.L  RTR.L
2003-03-03 327.00  1198 51.13 914.5 172.00 109.00
2003-03-10 344.75  1245 52.36 914.5 167.25 110.25
2003-03-17 363.75  1292 64.32 914.5 175.50 112.50
2003-03-24 363.25  1204 59.37 914.5 173.75 109.25
2003-03-31 357.00  1243 69.89 914.5 178.25 111.50
2003-04-07 361.00  1211 77.93 914.5 183.50 107.00
            SAB.L SBRY.L SCTN.L  SDR.L SDRC.L
2003-03-03 255.42  221.5 313.75 430.00  398.0
2003-03-10 262.83  235.0 328.50 470.25  440.0
2003-03-17 278.51  231.0 358.75 539.00  500.0
2003-03-24 278.34  226.0 346.75 506.00  462.5
2003-03-31 289.54  230.0 350.00 550.00  493.5
2003-04-07 290.58  231.5 339.50 570.00  528.0
            SGE.L  SHP.L  SMIN.L   SN.L SSE.L
2003-03-03 129.50 332.60  919.50 358.00   605
2003-03-10 135.50 347.49  922.50 370.00   614
2003-03-17 128.25 377.28  982.50 374.75   640
2003-03-24 119.50 394.16  990.00 400.00   652
2003-03-31 121.50 408.55 1014.00 399.25   649
2003-04-07 135.00 400.36  987.75 412.75   656
           STAN.L   SVT.L TLW.L TSCO.L  TT.L   TW.L
2003-03-03 539.39 1053.75 85.30 147.86 71.46 137.91
2003-03-10 558.43 1056.00 80.00 156.91 69.00 150.32
2003-03-17 589.37 1095.00 78.00 169.11 85.00 154.07
2003-03-24 548.52 1091.25 77.00 164.82 83.22 149.48
2003-03-31 539.39 1125.00 70.00 169.57 80.00 150.94
2003-04-07 539.39 1117.50 70.75 179.74 91.00 158.03
            ULVR.L  UU.L  VOD.L  WOS.L  WPP.L
2003-03-03 5882.03 564.0 140.86 450.00 351.75
2003-03-10 6019.20 584.0 148.98 479.00 365.00
2003-03-17 6573.39 610.0 157.74 535.00 384.00
2003-03-24 6540.47 600.5 149.30 517.00 349.50
2003-03-31 6639.23 618.0 155.14 530.00 377.00
2003-04-07 6738.00 616.0 156.44 537.25 372.00
            XTA.L
2003-03-03 460.64
2003-03-10 454.95
2003-03-17 454.95
2003-03-24 429.14
2003-03-31 425.64
2003-04-07 482.07
> data(INDTRACK1)
> head(INDTRACK1)
        Index       S1       S2       S3       S4
[1,] 8749.318 9.336752 14.37789 7.366449 29.46580
[2,] 8713.533 9.869266 14.18263 7.401950 27.33574
[3,] 9001.605 9.958019 14.59089 7.774710 28.75578
[4,] 8903.303 9.159247 15.74467 7.632706 28.75578
[5,] 8888.694 9.248000 16.29494 7.490702 27.86825
[6,] 8727.378 8.981742 15.62042 7.543954 26.62572
           S5       S6       S7       S8       S9
[1,] 5.555900 8.555731 16.41919 9.958019 5.857658
[2,] 5.449397 8.502479 16.41919 9.283501 6.248169
[3,] 5.804407 8.733236 16.59670 8.857489 6.514426
[4,] 5.502648 8.857489 16.59670 8.768737 6.301420
[5,] 5.502648 9.212499 16.77420 8.875239 6.301420
[6,] 5.449397 9.159247 16.50795 8.697735 6.390172
          S10      S11      S12      S13      S14
[1,] 1.792798 14.91040 22.54311 26.44821 21.30057
[2,] 1.810549 14.99915 23.60814 25.73819 20.94557
[3,] 1.881551 14.99915 24.49566 26.80322 22.36560
[4,] 2.076806 14.99915 24.49566 26.09320 21.12307
[5,] 1.970303 15.08791 23.96315 26.44821 20.94557
[6,] 1.899301 14.91040 23.78564 26.27071 20.76806
          S15      S16      S17      S18      S19
[1,] 75.88330 3.230587 8.129719 49.70134 5.857658
[2,] 75.43954 3.301589 8.076468 49.34633 5.768906
[3,] 80.32092 3.550096 8.253973 51.12138 6.017412
[4,] 73.22073 4.118111 8.165220 49.34633 6.017412
[5,] 71.44568 4.118111 8.129719 50.58887 5.893159
[6,] 68.33934 4.437620 8.076468 50.76637 5.768906
          S20      S21      S22      S23      S24
[1,] 16.95171 38.87355 29.28829 12.07033 17.39547
[2,] 16.41919 37.27601 28.93328 12.07033 17.57297
[3,] 16.41919 39.05105 28.57827 12.78034 17.75048
[4,] 16.50795 41.18111 27.86825 12.60284 18.99301
[5,] 16.50795 39.40606 28.93328 13.49036 18.63800
[6,] 16.86296 37.27601 28.22326 13.13535 17.92798
          S25      S26      S27      S28      S29
[1,] 24.61991 43.70168 44.21644 41.12786 2.431816
[2,] 24.85067 44.78446 43.73718 41.41187 2.343063
[3,] 26.39496 47.78429 44.69571 43.18692 2.307562
[4,] 26.62572 48.88482 43.89693 45.84949 3.816353
[5,] 25.73819 49.96760 43.89693 45.49448 3.674349
[6,] 25.06368 50.25161 43.08041 45.84949 4.082610
          S30      S31
[1,] 29.11079 10.91654
[2,] 27.86825 11.27155
[3,] 29.28829 11.62656
[4,] 28.40077 11.36031
[5,] 28.57827 11.36031
[6,] 28.93328 11.18280
> PGMV(Rets)
Iteration: 0
pobj: 0.396694
dobj: -0.797435
pinf: 3.31531
dinf: 4.86496
dgap: 16.2746

Iteration: 1
pobj: 0.429327
dobj: -0.591061
pinf: 0.316147
dinf: 0.463922
dgap: 2.37423

Iteration: 2
pobj: 0.430326
dobj: -0.102681
pinf: 0.0657035
dinf: 0.0964149
dgap: 0.761109

Iteration: 3
pobj: 0.393718
dobj: 0.179723
pinf: 0.0131117
dinf: 0.0192405
dgap: 0.243563

Iteration: 4
pobj: 0.355241
dobj: 0.2805
pinf: 0.00187089
dinf: 0.00274539
dgap: 0.0767899

Iteration: 5
pobj: 0.340985
dobj: 0.320463
pinf: 0.000260152
dinf: 0.000381753
dgap: 0.0206442

Iteration: 6
pobj: 0.335827
dobj: 0.329761
pinf: 3.0625e-005
dinf: 4.49398e-005
dgap: 0.00607401

Iteration: 7
pobj: 0.334207
dobj: 0.332124
pinf: 6.53239e-006
dinf: 9.58579e-006
dgap: 0.00208414

Iteration: 8
pobj: 0.333389
dobj: 0.332899
pinf: 2.84217e-014
dinf: 5.08768e-016
dgap: 0.000490514

Iteration: 9
pobj: 0.333219
dobj: 0.333109
pinf: 5.37348e-014
dinf: 9.08757e-016
dgap: 0.000110014

Iteration: 10
pobj: 0.333181
dobj: 0.333165
pinf: 1.05027e-013
dinf: 1.12127e-015
dgap: 1.65065e-005

Iteration: 11
pobj: 0.333176
dobj: 0.333173
pinf: 2.05169e-013
dinf: 1.41308e-015
dgap: 2.15942e-006

Iteration: 12
pobj: 0.333174
dobj: 0.333174
pinf: 4.00346e-013
dinf: 1.39553e-015
dgap: 2.62284e-007

Optimal solution found.


Optimal weights for porfolio of type:
Global Minimum Variance

   GSPC     RUA   GDAXI    FTSE    N225     EEM
 4.8891  0.0000  4.3411  0.0045  1.7276  0.0000
 DJCBTI   GREXP  BG05.L     GLD
 0.0000 87.8716  0.9589  0.2071

> yc <- diff(log(StockIndex[, "SP500"])) * 100
> yd <- returnseries(StockIndex[, "SP500"], method = "discrete", percentage = TRUE, trim = TRUE)
> yconv <- returnconvert(yd, convdir = "disc2cont",
+                        percentage = TRUE)
> all.equal(yc, yconv)
[1] TRUE
> Rets <- returnseries(StockIndex, method = "discrete", trim = TRUE,
+                      percentage = TRUE)
> tdc(Rets, method = "EmpTC")
            SP500      N225   FTSE100     CAC40
SP500   1.0000000 0.4666667 0.6666667 0.6666667
N225    0.4666667 1.0000000 0.3333333 0.3333333
FTSE100 0.6666667 0.3333333 1.0000000 0.7333333
CAC40   0.6666667 0.3333333 0.7333333 1.0000000
GDAX    0.6666667 0.4000000 0.6000000 0.8000000
HSI     0.3333333 0.4000000 0.4666667 0.4666667
             GDAX       HSI
SP500   0.6666667 0.3333333
N225    0.4000000 0.4000000
FTSE100 0.6000000 0.4666667
CAC40   0.8000000 0.4666667
GDAX    1.0000000 0.4666667
HSI     0.4666667 1.0000000
> tdc(Rets, method = "EVT")
            SP500      N225   FTSE100     CAC40
SP500   1.0000000 0.4666667 0.6666667 0.6666667
N225    0.4666667 1.0000000 0.3333333 0.3333333
FTSE100 0.6666667 0.3333333 1.0000000 0.7333333
CAC40   0.6666667 0.3333333 0.7333333 1.0000000
GDAX    0.6666667 0.4000000 0.6000000 0.8000000
HSI     0.3333333 0.4000000 0.4666667 0.4666667
             GDAX       HSI
SP500   0.6666667 0.3333333
N225    0.4000000 0.4000000
FTSE100 0.6000000 0.4666667
CAC40   0.8000000 0.4666667
GDAX    1.0000000 0.4666667
HSI     0.4666667 1.0000000
>
> PMTD(Rets)
Iteration: 0
pobj: 0.571883
dobj: -0.49252
pinf: 0
dinf: 3.05247
dgap: 1.0644

Iteration: 1
pobj: 0.570275
dobj: 0.472065
pinf: 1.3947e-016
dinf: 0.280309
dgap: 0.0982096

Iteration: 2
pobj: 0.567879
dobj: 0.551695
pinf: 7.34344e-017
dinf: 0.0393641
dgap: 0.0161841

Iteration: 3
pobj: 0.56744
dobj: 0.565466
pinf: 6.3596e-017
dinf: 0.00342768
dgap: 0.00197472

Iteration: 4
pobj: 0.56741
dobj: 0.567224
pinf: 3.92523e-017
dinf: 0.000241732
dgap: 0.000186047

Iteration: 5
pobj: 0.56741
dobj: 0.567399
pinf: 8.44153e-017
dinf: 1.27771e-005
dgap: 1.07084e-005

Iteration: 6
pobj: 0.56741
dobj: 0.567409
pinf: 3.92523e-017
dinf: 6.41115e-007
dgap: 5.40576e-007

Iteration: 7
pobj: 0.56741
dobj: 0.56741
pinf: 8.88612e-017
dinf: 3.20615e-008
dgap: 2.7042e-008

Optimal solution found.


Optimal weights for porfolio of type:
Minimum Tail Dependent

  SP500    N225 FTSE100   CAC40    GDAX     HSI
17.9566 26.8682 19.9236  8.4298  7.7707 19.0511

> bilson <- trdbilson(yret, exponent = 2)
> plot(bilson)
> S <- cov(StockIndex)
> SR <- sqrm(S)
> all.equal(crossprod(SR), S)
[1] TRUE
> eigen(cbind(c(1,-1), c(-1,1)))
eigen() decomposition
$values
[1] 2 0

$vectors
           [,1]       [,2]
[1,] -0.7071068 -0.7071068
[2,]  0.7071068 -0.7071068

> eigen(cbind(c(1,-1), c(-1,1)), symmetric = FALSE)
eigen() decomposition
$values
[1] 2 0

$vectors
           [,1]      [,2]
[1,]  0.7071068 0.7071068
[2,] -0.7071068 0.7071068

> eigen(cbind(1, c(1,-1)), only.values = TRUE)
$values
[1]  1.414214 -1.414214

$vectors
NULL

> eigen(cbind(-1, 2:1))
eigen() decomposition
$values
[1] 0+1i 0-1i

$vectors
                     [,1]                 [,2]
[1,] 0.8164966+0.0000000i 0.8164966+0.0000000i
[2,] 0.4082483+0.4082483i 0.4082483-0.4082483i

> eigen(print(cbind(c(0, 1i), c(-1i, 0)))) # Hermite ==> real Eigenvalues
     [,1] [,2]
[1,] 0+0i 0-1i
[2,] 0+1i 0+0i
eigen() decomposition
$values
[1]  1 -1

$vectors
                      [,1]                  [,2]
[1,] -0.7071068+0.0000000i -0.7071068+0.0000000i
[2,]  0.0000000-0.7071068i  0.0000000+0.7071068i

> eigen(cbind( 1, 3:1, 1:3))
eigen() decomposition
$values
[1]  5.000000e+00  1.000000e+00 -4.440892e-16

$vectors
          [,1]       [,2]       [,3]
[1,] 0.5773503 -0.8451543 -0.9428090
[2,] 0.5773503 -0.1690309  0.2357023
[3,] 0.5773503  0.5070926  0.2357023

> eigen(cbind(-1, c(1:2,0), 0:2))
eigen() decomposition
$values
[1]  1.8846462+0.589743i  1.8846462-0.589743i
[3] -0.7692924+0.000000i

$vectors
                     [,1]                 [,2]
[1,] 0.2777976-0.0567935i 0.2777976+0.0567935i
[2,] 0.8348414+0.0000000i 0.8348414+0.0000000i
[3,] 0.1814955+0.4355482i 0.1814955-0.4355482i
             [,3]
[1,] 0.9191652+0i
[2,] 0.2120584+0i
[3,] 0.3319134+0i

> require(graphics)
> arima.sim(n = 63, list(ar = c(0.8897, -0.4858), ma = c(-0.2279, 0.2488)),
+           sd = sqrt(0.1796))
Time Series:
Start = 1
End = 63
Frequency = 1
 [1] -0.32637817  0.67169441  1.22204051  0.13551934
 [5]  0.24795317  0.12780499  0.19767618  0.62838848
 [9]  0.41328199  0.58140861  0.38492790 -0.16019104
[13] -0.26436379 -1.27445296 -0.63468190 -0.13556088
[17]  0.61549499  0.19640118 -0.41648105 -0.09408137
[21]  0.12815573  0.68119701  0.13113440  0.72085503
[25] -0.02875213  0.03563969 -1.39280521 -1.37047742
[29] -0.83616747 -0.18121802  0.01505626 -0.20561851
[33]  0.14693045 -0.08328003 -0.05415154 -0.26963473
[37]  0.29904476  0.39861170  0.41191561  0.89266403
[41]  0.17719036  0.01382766 -0.44732830  0.39003942
[45]  0.52934152  0.34431491 -0.16969279  0.07467076
[49] -0.32684463 -0.64202373 -0.54746416 -0.02225844
[53]  0.49350293  0.74760125  0.80610460 -0.12032726
[57]  0.32538213 -0.24392085  0.81902587  0.26587884
[61]  0.36647713  0.14428340  0.35180392
> arima.sim(n = 63, list(ar = c(0.8897, -0.4858), ma = c(-0.2279, 0.2488)),
+           rand.gen = function(n, ...) sqrt(0.1796) * rt(n, df = 5))
Time Series:
Start = 1
End = 63
Frequency = 1
 [1] -0.373207188 -0.081970003  0.717091474
 [4]  0.141178237  0.176226984  0.194109240
 [7]  0.149510847 -0.263653700 -0.975013044
[10] -0.882612630 -0.850231212 -0.673373812
[13] -0.024376534  0.003299654 -0.321455190
[16] -0.428247902  0.116763137 -0.373675924
[19]  0.007485032  0.393974642 -0.435729505
[22] -0.150410012 -1.874770205 -1.490835956
[25] -0.159505702  0.458516381  0.389498175
[28]  0.318894408 -0.240332227 -0.375157538
[31]  0.683456486 -0.625538700  1.176042270
[34]  0.596942212 -0.113929762 -1.062199305
[37]  0.366115640  0.067361725  0.649607222
[40]  0.155344825 -0.267537228 -0.026739851
[43] -0.146007577  0.033798364 -0.094371374
[46] -0.125766478  0.482920914 -0.570907354
[49] -0.215693606 -0.163440995 -1.094038680
[52] -0.166535190 -0.139567237  0.361964170
[55]  0.423001638 -0.046322093 -0.721089465
[58] -0.284954979 -0.165845139  0.670785604
[61]  1.929652404  0.663949741 -0.251499392
>
> ts.sim <- arima.sim(list(order = c(1,1,0), ar = 0.7), n = 200)
> ts.plot(ts.sim)
> od <- options(digits = 5)
> predict(arima(lh, order = c(3,0,0)), n.ahead = 12)
$pred
Time Series:
Start = 49
End = 60
Frequency = 1
 [1] 2.4602 2.2708 2.1986 2.2607 2.3470 2.4145
 [7] 2.4389 2.4315 2.4102 2.3917 2.3827 2.3827

$se
Time Series:
Start = 49
End = 60
Frequency = 1
 [1] 0.42268 0.50293 0.52452 0.52472 0.53055 0.53692
 [7] 0.53880 0.53884 0.53910 0.53952 0.53970 0.53971

> (fit <- arima(USAccDeaths, order = c(0,1,1),
+               seasonal = list(order = c(0,1,1))))

Call:
arima(x = USAccDeaths, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1)))

Coefficients:

         ma1    sma1
      -0.430  -0.553
s.e.   0.123   0.178

sigma^2 estimated as 99347:  log likelihood = -425.44,  aic = 856.88
> predict(fit, n.ahead = 6)
$pred
        Jan    Feb    Mar    Apr    May    Jun
1979 8336.1 7531.8 8314.6 8616.9 9488.9 9859.8

$se
        Jan    Feb    Mar    Apr    May    Jun
1979 315.45 363.01 405.02 443.06 478.09 510.72

Post a Comment

0 Comments