Showing posts with label InformationRatio = ActivePremium/TrackingError. Show all posts
Showing posts with label InformationRatio = ActivePremium/TrackingError. Show all posts

Friday, March 15, 2019

InformationRatio

How to get information Ratio

InformationRatio = ActivePremium/TrackingError
library(quantmod)
information ratio,information ratio cfa,information ratio excel,geometric information ratio,annualized information ratio,information ratio morningstar,information,information ratio calculation example,ratio,sharpe ratio,the information ratio,information ratios,information ratio formula,negative information ratio,information ratio vs sharpe ratio,information density and subset ratio,law ratio information

> stocks <- stockSymbols()
Fetching AMEX symbols...
Fetching NASDAQ symbols...
Fetching NYSE symbols...
> str(stocks)
'data.frame': 6858 obs. of  8 variables:
 $ Symbol   : chr  "AAMC" "AAU" "ACU" "ACY" ...
 $ Name     : chr  "Altisource Asset Management Corp" "Almaden Minerals, Ltd." "Acme United Corporation." "AeroCentury Corp." ...
 $ LastSale : num  35.65 0.619 17.11 12 38.75 ...
 $ MarketCap: chr  "$56.49M" "$69.16M" "$57.64M" "$18.55M" ...
 $ IPOyear  : int  NA 2015 1988 NA NA NA 2018 2014 NA NA ...
 $ Sector   : chr  "Finance" "Basic Industries" "Capital Goods" "Technology" ...
 $ Industry : chr  "Real Estate" "Precious Metals" "Industrial Machinery/Components" "Diversified Commercial Services" ...
 $ Exchange : chr  "AMEX" "AMEX" "AMEX" "AMEX" ...
> stocks[1:5, c(1, 3:4, ncol(stocks))]
  Symbol LastSale MarketCap Exchange
1   AAMC   35.650   $56.49M     AMEX
2    AAU    0.619   $69.16M     AMEX
3    ACU   17.110   $57.64M     AMEX
4    ACY   12.000   $18.55M     AMEX
5     AE   38.750  $163.43M     AMEX
> library(Quandl)
Warning message:
package ‘Quandl’ was built under R version 3.5.2
> LIBOR <- Quandl('FED/RILSPDEPM01_N_B',
+                 start_date = '2016-06-01', end_date = '2019-03-01')
> d <- read.table("data.csv", header = TRUE, sep = ";")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'data.csv': No such file or directory
> d[1:7, c(1:5, (ncol(d) - 6):ncol(d))]
Error: object 'd' not found
> d <- d[, colSums(is.na(d)) == 0]
Error: object 'd' not found
> d <- d[, c(T, colMins(d[, 2:ncol(d)]) > 0)]
Error: object 'd' not found
> d <- d[, colSums(is.na(d)) == 0]
Error: object 'd' not found
> d <- d[, c(T, colMins(d[, 2:ncol(d)]) > 0)]
Error: object 'd' not found
> install.packages("matrixStats")
Installing package into ‘C:/Users/ADMIN/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/matrixStats_0.54.0.zip'
Content type 'application/zip' length 1634325 bytes (1.6 MB)
downloaded 1.6 MB

package ‘matrixStats’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\ADMIN\AppData\Local\Temp\RtmpkHpWON\downloaded_packages
> library(matrixStats)
Warning message:
package ‘matrixStats’ was built under R version 3.5.3
> x <- matrix(FALSE, nrow = 10, ncol = 5)
> x[3:7, c(2, 4)] <- TRUE
> x[2:4, ] <- TRUE
> x[, 1] <- TRUE
> x[5, ] <- FALSE
> x[, 5] <- FALSE
> print(x)
       [,1]  [,2]  [,3]  [,4]  [,5]
 [1,]  TRUE FALSE FALSE FALSE FALSE
 [2,]  TRUE  TRUE  TRUE  TRUE FALSE
 [3,]  TRUE  TRUE  TRUE  TRUE FALSE
 [4,]  TRUE  TRUE  TRUE  TRUE FALSE
 [5,] FALSE FALSE FALSE FALSE FALSE
 [6,]  TRUE  TRUE FALSE  TRUE FALSE
 [7,]  TRUE  TRUE FALSE  TRUE FALSE
 [8,]  TRUE FALSE FALSE FALSE FALSE
 [9,]  TRUE FALSE FALSE FALSE FALSE
[10,]  TRUE FALSE FALSE FALSE FALSE
> print(rowCounts(x))
 [1] 1 4 4 4 0 3 3 1 1 1
> print(colCounts(x))
[1] 9 5 3 5 0
> print(rowAnys(x))
 [1]  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
 [8]  TRUE  TRUE  TRUE
> print(which(rowAnys(x)))
[1]  1  2  3  4  6  7  8  9 10
> print(colAnys(x))
[1]  TRUE  TRUE  TRUE  TRUE FALSE
> print(which(colAnys(x)))
[1] 1 2 3 4
> x <- rnorm(n = 1000)
> x[seq(300, length(x), by = 100)] <- NA
> stopifnot(anyMissing(x) == any(is.na(x)))
> x <- 1:200
> mu <- double(length(x))
> mu[1:50] <- 5
> mu[101:150] <- -5
> y <- mu + rnorm(length(x))
> bx <- c(0, 50, 100, 150, 200) + 0.5
> y_s <- binMeans(y, x = x, bx = bx)
> plot(x, y)
> for (kk in seq_along(y_s)) {
+     lines(bx[c(kk, kk + 1)], y_s[c(kk, kk)], col = "blue", lwd = 2)
+ }
> install.packages("colMins")
Installing package into ‘C:/Users/ADMIN/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘colMins’ is not available (for R version 3.5.0)
> x <- matrix(1:27, ncol = 3)
> y <- rowCollapse(x, 1)
> stopifnot(identical(y, x[, 1]))
> y <- rowCollapse(x, 2)
> stopifnot(identical(y, x[, 2]))
> y <- rowCollapse(x, c(1, 1, 1, 1, 1, 3, 3, 3, 3))
> stopifnot(identical(y, c(x[1:5, 1], x[6:9, 3])))
> y <- rowCollapse(x, 1:3)
> print(y)
[1]  1 11 21  4 14 24  7 17 27
> y_truth <- c(x[1, 1], x[2, 2], x[3, 3], x[4, 1], x[5, 2],
+              x[6, 3], x[7, 1], x[8, 2], x[9, 3])
> stopifnot(identical(y, y_truth))
> x <- 1:10
> n <- length(x)
> m1 <- mad(x)
> m2 <- weightedMad(x)
> stopifnot(identical(m1, m2))
> w <- rep(1, times = n)
> m1 <- weightedMad(x, w)
> stopifnot(identical(m1, m2))
> p <- d[, 3:ncol(d)]
Error: object 'd' not found
> r <- log(p[2:nrow(p), ] / p[1:(nrow(p) - 1), ])
Error: object 'p' not found
> return.calculate(data, method="log")
Error in return.calculate(data, method = "log") :
  could not find function "return.calculate"
> install.packages("PerformanceAnalytics")
Installing package into ‘C:/Users/ADMIN/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/PerformanceAnalytics_1.5.2.zip'
Content type 'application/zip' length 2862064 bytes (2.7 MB)
downloaded 2.7 MB

package ‘PerformanceAnalytics’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\ADMIN\AppData\Local\Temp\RtmpkHpWON\downloaded_packages
> library(PerformanceAnalytics)

Package PerformanceAnalytics (1.5.2) loaded.
Copyright (c) 2004-2018 Peter Carl and Brian G. Peterson, GPL-2 | GPL-3
https://github.com/braverock/PerformanceAnalytics


Attaching package: ‘PerformanceAnalytics’

The following object is masked from ‘package:graphics’:

    legend

Warning message:
package ‘PerformanceAnalytics’ was built under R version 3.5.3
> data(portfolio_bacon)
> MAR = 0.005
> print(VolatilitySkewness(portfolio_bacon[,1], MAR, stat="volatility"))
[1] 1.323046
> print(VolatilitySkewness(portfolio_bacon[,1], MAR, stat="variability"))
[1] 1.150238
> data(edhec)
> VaR(edhec, p=.95, method="historical")
    Convertible Arbitrage CTA Global
VaR              -0.01916    -0.0354
    Distressed Securities
VaR             -0.018875
    Emerging Markets
VaR        -0.044605
    Equity Market Neutral Event Driven
VaR             -0.006385     -0.02254
    Fixed Income Arbitrage Global Macro
VaR               -0.00929     -0.01624
    Long/Short Equity Merger Arbitrage
VaR          -0.02544        -0.013455
    Relative Value Short Selling
VaR      -0.013175      -0.07848
    Funds of Funds
VaR      -0.021265
> VaR(edhec, p=.95, method="gaussian")
    Convertible Arbitrage  CTA Global
VaR           -0.02645782 -0.03471098
    Distressed Securities
VaR            -0.0221269
    Emerging Markets
VaR      -0.05498927
    Equity Market Neutral Event Driven
VaR          -0.008761813  -0.02246202
    Fixed Income Arbitrage Global Macro
VaR            -0.01900198  -0.02023018
    Long/Short Equity Merger Arbitrage
VaR       -0.02859264      -0.01152478
    Relative Value Short Selling
VaR    -0.01493049   -0.08617027
    Funds of Funds
VaR    -0.02393888
> VaR(edhec, p=.95, method="modified")
    Convertible Arbitrage  CTA Global
VaR           -0.03247395 -0.03380228
    Distressed Securities
VaR            -0.0274924
    Emerging Markets
VaR      -0.06363081
    Equity Market Neutral Event Driven
VaR           -0.01134637  -0.02812515
    Fixed Income Arbitrage Global Macro
VaR             -0.0246791  -0.01548247
    Long/Short Equity Merger Arbitrage
VaR       -0.03037494      -0.01486869
    Relative Value Short Selling
VaR    -0.01926435   -0.07431463
    Funds of Funds
VaR    -0.02502852
> VaR(edhec, p=.99)
    Convertible Arbitrage  CTA Global
VaR            -0.1009223 -0.04847019
    Distressed Securities
VaR           -0.06533764
    Emerging Markets
VaR       -0.1397195
    Equity Market Neutral Event Driven
VaR           -0.04404136  -0.06385154
    Fixed Income Arbitrage Global Macro
VaR            -0.05850228  -0.02437999
    Long/Short Equity Merger Arbitrage
VaR       -0.05508705      -0.03630211
    Relative Value Short Selling
VaR      -0.050531     -0.122236
    Funds of Funds
VaR    -0.05500037
> VaR(edhec, p=.01)
    Convertible Arbitrage  CTA Global
VaR            -0.1009223 -0.04847019
    Distressed Securities
VaR           -0.06533764
    Emerging Markets
VaR       -0.1397195
    Equity Market Neutral Event Driven
VaR           -0.04404136  -0.06385154
    Fixed Income Arbitrage Global Macro
VaR            -0.05850228  -0.02437999
    Long/Short Equity Merger Arbitrage
VaR       -0.05508705      -0.03630211
    Relative Value Short Selling
VaR      -0.050531     -0.122236
    Funds of Funds
VaR    -0.05500037
> VaR(edhec, clean="boudt")
    Convertible Arbitrage  CTA Global
VaR            -0.0192821 -0.03380228
    Distressed Securities
VaR           -0.02281122
    Emerging Markets
VaR      -0.05335613
    Equity Market Neutral Event Driven
VaR          -0.006583541  -0.02588255
    Fixed Income Arbitrage Global Macro
VaR            -0.01947099  -0.01612116
    Long/Short Equity Merger Arbitrage
VaR       -0.02997413      -0.01255334
    Relative Value Short Selling
VaR     -0.0147671   -0.07881339
    Funds of Funds
VaR    -0.02474761
> VaR(edhec, clean="boudt", portfolio_method="component")
no weights passed in, assuming equal weighted portfolio
$`MVaR`
[1] 0.01206124

$contribution
 Convertible Arbitrage
          1.189614e-03
            CTA Global
          7.392667e-05
 Distressed Securities
          1.380388e-03
      Emerging Markets
          3.044882e-03
 Equity Market Neutral
          3.255042e-04
          Event Driven
          1.633369e-03
Fixed Income Arbitrage
          1.122597e-03
          Global Macro
          9.551128e-04
     Long/Short Equity
          1.725166e-03
      Merger Arbitrage
          5.594788e-04
        Relative Value
          9.422577e-04
         Short Selling
         -2.647415e-03
        Funds of Funds
          1.756359e-03

$pct_contrib_MVaR
 Convertible Arbitrage
           0.098631120
            CTA Global
           0.006129276
 Distressed Securities
           0.114448260
      Emerging Markets
           0.252451840
 Equity Market Neutral
           0.026987629
          Event Driven
           0.135422963
Fixed Income Arbitrage
           0.093074804
          Global Macro
           0.079188612
     Long/Short Equity
           0.143033874
      Merger Arbitrage
           0.046386511
        Relative Value
           0.078122792
         Short Selling
          -0.219497771
        Funds of Funds
           0.145620091

> data(portfolio_bacon)
> MAR = 0.005
> print(UpsideRisk(portfolio_bacon[,1], MAR, stat="risk"))
[1] 0.02937332
> print(UpsideRisk(portfolio_bacon[,1], MAR, stat="variance"))
[1] 0.0008627917
> print(UpsideRisk(portfolio_bacon[,1], MAR, stat="potential"))
[1] 0.01770833
> UpsidePotentialRatio(edhec[, 6], MAR=.05/12)
                              Event Driven
Upside Potential (MAR = 0.4%)    0.5376613
> UpsidePotentialRatio(edhec[, 1:6], MAR=0)
                            Convertible Arbitrage
Upside Potential (MAR = 0%)             0.4450702
                            CTA Global
Upside Potential (MAR = 0%)   1.174942
                            Distressed Securities
Upside Potential (MAR = 0%)              0.646571
                            Emerging Markets
Upside Potential (MAR = 0%)        0.5684649
                            Equity Market Neutral
Upside Potential (MAR = 0%)             0.5200563
                            Event Driven
Upside Potential (MAR = 0%)    0.6294689
> SharpeRatio(edhec,Rf = .04/12)
                                Convertible Arbitrage
StdDev Sharpe (Rf=0.3%, p=95%):            0.15339751
VaR Sharpe (Rf=0.3%, p=95%):               0.09469804
ES Sharpe (Rf=0.3%, p=95%):                0.03089192
                                CTA Global
StdDev Sharpe (Rf=0.3%, p=95%): 0.12558803
VaR Sharpe (Rf=0.3%, p=95%):    0.09337063
ES Sharpe (Rf=0.3%, p=95%):     0.07366957
                                Distressed Securities
StdDev Sharpe (Rf=0.3%, p=95%):            0.25179740
VaR Sharpe (Rf=0.3%, p=95%):               0.16804482
ES Sharpe (Rf=0.3%, p=95%):                0.07589603
                                Emerging Markets
StdDev Sharpe (Rf=0.3%, p=95%):       0.12736677
VaR Sharpe (Rf=0.3%, p=95%):          0.07720662
ES Sharpe (Rf=0.3%, p=95%):           0.03841453
                                Equity Market Neutral
StdDev Sharpe (Rf=0.3%, p=95%):             0.2963971
VaR Sharpe (Rf=0.3%, p=95%):                0.2352556
ES Sharpe (Rf=0.3%, p=95%):                 0.0622208
                                Event Driven
StdDev Sharpe (Rf=0.3%, p=95%):   0.23372885
VaR Sharpe (Rf=0.3%, p=95%):      0.15249824
ES Sharpe (Rf=0.3%, p=95%):       0.07257669
                                Fixed Income Arbitrage
StdDev Sharpe (Rf=0.3%, p=95%):             0.06333844
VaR Sharpe (Rf=0.3%, p=95%):                0.03637036
ES Sharpe (Rf=0.3%, p=95%):                 0.01508086
                                Global Macro
StdDev Sharpe (Rf=0.3%, p=95%):    0.2549431
VaR Sharpe (Rf=0.3%, p=95%):       0.2802548
ES Sharpe (Rf=0.3%, p=95%):        0.2187777
                                Long/Short Equity
StdDev Sharpe (Rf=0.3%, p=95%):        0.19962891
VaR Sharpe (Rf=0.3%, p=95%):           0.14572983
ES Sharpe (Rf=0.3%, p=95%):            0.09399888
                                Merger Arbitrage
StdDev Sharpe (Rf=0.3%, p=95%):        0.3090483
VaR Sharpe (Rf=0.3%, p=95%):           0.2321344
ES Sharpe (Rf=0.3%, p=95%):            0.1037628
                                Relative Value
StdDev Sharpe (Rf=0.3%, p=95%):     0.25525305
VaR Sharpe (Rf=0.3%, p=95%):        0.17482979
ES Sharpe (Rf=0.3%, p=95%):         0.06890142
                                Short Selling
StdDev Sharpe (Rf=0.3%, p=95%):   0.015024743
VaR Sharpe (Rf=0.3%, p=95%):      0.011139811
ES Sharpe (Rf=0.3%, p=95%):       0.009175123
                                Funds of Funds
StdDev Sharpe (Rf=0.3%, p=95%):     0.14194452
VaR Sharpe (Rf=0.3%, p=95%):        0.10328569
ES Sharpe (Rf=0.3%, p=95%):         0.05597178
> data(managers)
> InformationRatio(managers[,"HAM1",drop=FALSE], managers[, "SP500 TR", drop=FALSE])
[1] 0.3604125
> InformationRatio(managers[,1:6], managers[,8,drop=FALSE])
                                 HAM1
Information Ratio: SP500 TR 0.3604125
                                 HAM2
Information Ratio: SP500 TR 0.5059751
                                 HAM3
Information Ratio: SP500 TR 0.4701009
                                HAM4
Information Ratio: SP500 TR 0.154914
                                 HAM5
Information Ratio: SP500 TR 0.1212162
                                 HAM6
Information Ratio: SP500 TR 0.6722844
> InformationRatio(managers[,1:6], managers[,8:7])
                                    HAM1
Information Ratio: SP500 TR    0.3604125
Information Ratio: EDHEC LS EQ 0.2593770
                                    HAM2
Information Ratio: SP500 TR    0.5059751
Information Ratio: EDHEC LS EQ 0.4162701
                                    HAM3
Information Ratio: SP500 TR    0.4701009
Information Ratio: EDHEC LS EQ 0.1279329
                                     HAM4
Information Ratio: SP500 TR     0.1549140
Information Ratio: EDHEC LS EQ -0.0294821
                                     HAM5
Information Ratio: SP500 TR     0.1212162
Information Ratio: EDHEC LS EQ -0.2277438
                                    HAM6
Information Ratio: SP500 TR    0.6722844
Information Ratio: EDHEC LS EQ 0.9667207
> TrackingError(managers[,1,drop=FALSE], managers[,8,drop=FALSE])
[1] 0.1131667
> TrackingError(managers[,1:6], managers[,8,drop=FALSE])
                              HAM1
Tracking Error: SP500 TR 0.1131667
                              HAM2
Tracking Error: SP500 TR 0.1533647
                              HAM3
Tracking Error: SP500 TR 0.1158673
                              HAM4
Tracking Error: SP500 TR 0.1596656
                              HAM5
Tracking Error: SP500 TR 0.1800291
                             HAM6
Tracking Error: SP500 TR 0.112839
> TrackingError(managers[,1:6], managers[,8:7,drop=FALSE])
                                  HAM1
Tracking Error: SP500 TR    0.11316666
Tracking Error: EDHEC LS EQ 0.07577263
                                  HAM2
Tracking Error: SP500 TR    0.15336472
Tracking Error: EDHEC LS EQ 0.09071824
                                  HAM3
Tracking Error: SP500 TR    0.11586735
Tracking Error: EDHEC LS EQ 0.08156934
                                 HAM4
Tracking Error: SP500 TR    0.1596656
Tracking Error: EDHEC LS EQ 0.1569067
                                 HAM5
Tracking Error: SP500 TR    0.1800291
Tracking Error: EDHEC LS EQ 0.1421533
                                  HAM6
Tracking Error: SP500 TR    0.11283904
Tracking Error: EDHEC LS EQ 0.05651657
> ActivePremium(managers[, "HAM1", drop=FALSE], managers[, "SP500 TR", drop=FALSE])
[1] 0.04078668
> ActivePremium(managers[,1,drop=FALSE], managers[,8,drop=FALSE])
[1] 0.04078668
> ActivePremium(managers[,1:6], managers[,8,drop=FALSE])
                               HAM1
Active Premium: SP500 TR 0.04078668
                               HAM2
Active Premium: SP500 TR 0.07759873
                               HAM3
Active Premium: SP500 TR 0.05446935
                               HAM4
Active Premium: SP500 TR 0.02473443
                               HAM5
Active Premium: SP500 TR 0.02182245
                               HAM6
Active Premium: SP500 TR 0.07585993
> ActivePremium(managers[,1:6], managers[,8:7,drop=FALSE])
                                  HAM1
Active Premium: SP500 TR    0.04078668
Active Premium: EDHEC LS EQ 0.01965368
                                  HAM2
Active Premium: SP500 TR    0.07759873
Active Premium: EDHEC LS EQ 0.03776329
                                  HAM3
Active Premium: SP500 TR    0.05446935
Active Premium: EDHEC LS EQ 0.01043540
                                   HAM4
Active Premium: SP500 TR     0.02473443
Active Premium: EDHEC LS EQ -0.00462594
                                   HAM5
Active Premium: SP500 TR     0.02182245
Active Premium: EDHEC LS EQ -0.03237453
                                  HAM6
Active Premium: SP500 TR    0.07585993
Active Premium: EDHEC LS EQ 0.05463574
> Return.annualized(managers[,1,drop=FALSE])
                      HAM1
Annualized Return 0.137532
> Return.annualized(managers[,1:8])
                      HAM1      HAM2
Annualized Return 0.137532 0.1746569
                       HAM3      HAM4
Annualized Return 0.1512147 0.1214798
                        HAM5      HAM6
Annualized Return 0.03731645 0.1372755
                  EDHEC LS EQ   SP500 TR
Annualized Return   0.1180134 0.09674533
> Return.annualized(managers[,1:8],geometric=FALSE)
                       HAM1      HAM2
Annualized Return 0.1334727 0.1697184
                       HAM3   HAM4
Annualized Return 0.1493636 0.1322
                        HAM5      HAM6
Annualized Return 0.04905974 0.1326563
                  EDHEC LS EQ  SP500 TR
Annualized Return     0.11454 0.1039841

Black-Scholes formula-R

 Black-Scholes formula-R > BlackScholes <- function(TypeFlag = c("c", "p"), S, X, Time, r, b, sigma) { TypeFla...