程式

金融:投資組合 - 多空投資組合建構

  • October 14, 2019

我正在嘗試在 R 中建構一個多頭/空頭投資組合。假設我有兩個投資組合TechMature並且我想在投資組合上做多Tech並在投資組合上做空Mature

我使用以下方式收集和下載數據:

tickers <- c("GOOG", "MSFT", "GE", "WAL")

library(tidyquant)
library(dplyr)
library(tidyverse)
library(glue)



data <- tq_get(tickers,
              get = "stock.prices",
              from = "2010-01-01",
              to = "2015-01-01") %>%
 group_by(symbol) %>%
 tq_transmute(select = adjusted,
                mutate_fun = periodReturn,
                period = "monthly",
                type = "arithmetic") %>%
 mutate(portfolio = case_when(
   symbol == "GOOG" ~ "Tech",
   symbol == "MSFT" ~ "Tech",
   symbol == "GE"  ~ "Mature",
   symbol == "WAL" ~ "Mature"
   ),
   date = ceiling_date(date, "month") - days(1)) %>% # set the date to the end of the month
 group_by(portfolio, date) %>%
 summarise(
   Port_Monthly_Rets = mean(monthly.returns)
 )

看起來像:

# A tibble: 120 x 3
# Groups:   portfolio [2]
  portfolio date       Port_Monthly_Rets
  <chr>     <date>                 <dbl>
1 Mature    2010-01-31            0.173 
2 Mature    2010-02-28            0.0639
3 Mature    2010-03-31            0.0605
4 Mature    2010-04-30            0.283 
5 Mature    2010-05-31           -0.104 
6 Mature    2010-06-30           -0.111 
7 Mature    2010-07-31            0.0659
8 Mature    2010-08-31           -0.130 
9 Mature    2010-09-30            0.113 
10 Mature    2010-10-31           -0.0563
# ... with 110 more rows

我還下載了 Fama French Factors:

# Collect Fama French Factors:

temp <- tempfile()
base <- "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/"
factor <- "North_America_3_Factors"
format<-"_CSV.zip"
full_url <-glue(base,factor,format,sep ="")
download.file(full_url,temp,quiet = TRUE)

FF_Factors <- read_csv(unz(temp, "North_America_3_Factors.csv"), skip = 6) %>%
 rename(date = X1) %>%
 mutate_at(vars(-date), as.numeric) %>%
 mutate(date = rollback(ymd(parse_date_time(date, "%Y%m") + months(1)))) %>%
 drop_na(date) %>%
 rename(Mkt_Rf_3 = `Mkt-RF`,
        SMB_3 = SMB,
        HML_3 = HML,
        RF_3 = RF)

我將所有內容連接在一起併計算超額收益:

# Join factors with portfolios

df <- data %>%
 left_join(FF_Factors, by = "date") %>%
 mutate(R_excess = Port_Monthly_Rets - RF_3)

現在看起來像:

# A tibble: 120 x 8
# Groups:   portfolio [2]
  portfolio date       Port_Monthly_Rets Mkt_Rf_3 SMB_3 HML_3  RF_3 R_excess
  <chr>     <date>                 <dbl>    <dbl> <dbl> <dbl> <dbl>    <dbl>
1 Mature    2010-01-31            0.173     -3.63  0.45  0.89  0      0.173 
2 Mature    2010-02-28            0.0639     3.71  0.86  2.35  0      0.0639
3 Mature    2010-03-31            0.0605     6.27  1.5   1.48  0.01   0.0505
4 Mature    2010-04-30            0.283      1.92  3.73  1.9   0.01   0.273 
5 Mature    2010-05-31           -0.104     -7.86  0.74 -2.32  0.01  -0.114 
6 Mature    2010-06-30           -0.111     -5.5  -1.07 -3.73  0.01  -0.121 
7 Mature    2010-07-31            0.0659     6.95  0.02  1.03  0.01   0.0559
8 Mature    2010-08-31           -0.130     -4.44 -1.61 -2.35  0.01  -0.140 
9 Mature    2010-09-30            0.113      9.47  3.67 -1.85  0.01   0.103 
10 Mature    2010-10-31           -0.0563     3.89  0.98 -1.55  0.01  -0.0663
# ... with 110 more rows

我對我的投資組合進行 Fama French 回歸:

summary(lm(R_excess ~ Mkt_Rf_3 + SMB_3 + HML_3, data = subset(df, portfolio == "Mature")))
summary(lm(R_excess ~ Mkt_Rf_3 + SMB_3 + HML_3, data = subset(df, portfolio == "Tech")))

例如,Tech投資組合如下所示:

Call:
lm(formula = R_excess ~ Mkt_Rf_3 + SMB_3 + HML_3, data = subset(df, 
   portfolio == "Mature"))

Residuals:
    Min       1Q   Median       3Q      Max 
-0.10673 -0.03100 -0.01297  0.02820  0.18958 

Coefficients:
           Estimate Std. Error t value  Pr(>|t|)    
(Intercept) 0.010782   0.007560   1.426   0.15934    
Mkt_Rf_3    0.009913   0.002130   4.654 0.0000204 ***
SMB_3       0.008572   0.004173   2.054   0.04463 *  
HML_3       0.011192   0.004137   2.705   0.00903 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.05491 on 56 degrees of freedom
Multiple R-squared:  0.5271,    Adjusted R-squared:  0.5018 
F-statistic: 20.81 on 3 and 56 DF,  p-value: 0.00000000349

我想做多tech投資組合,做空mature投資組合。這是我創建多空組合的嘗試。

LS_Portfolio <- df %>%
 select(-Port_Monthly_Rets) %>%
 pivot_wider(names_from = portfolio, values_from = c(R_excess)) %>%
 mutate(Long_Short = Tech - Mature)

summary(lm(Long_Short ~ Mkt_Rf_3 + SMB_3 + HML_3, data = LS_Portfolio))

哪個輸出:

Call:
lm(formula = Long_Short ~ Mkt_Rf_3 + SMB_3 + HML_3, data = LS_Portfolio)

Residuals:
     Min        1Q    Median        3Q       Max 
-0.248952 -0.027568  0.003106  0.029772  0.191031 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) -0.017876   0.009873  -1.810  0.07559 . 
Mkt_Rf_3     0.002387   0.002782   0.858  0.39457   
SMB_3       -0.018172   0.005450  -3.334  0.00152 **
HML_3       -0.012778   0.005404  -2.365  0.02154 * 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.07171 on 56 degrees of freedom
Multiple R-squared:  0.2307,    Adjusted R-squared:  0.1895 
F-statistic: 5.597 on 3 and 56 DF,  p-value: 0.001983

在我看來這是錯誤的,Mkt_Rf_3 應該很重要。當我將其應用於更大的股票投資組合時,我得到了非常相似的回歸結果。

我的問題與程式無關,但鑑於我在每個投資組合中有許多股票,我應該如何建構多頭/空頭投資組合。

我要做的是:

1)根據一些標準形成股票組合

  1. 計算每個投資組合的平均月收益

  2. 通過獲取平均每月投資組合收益並從 Fama French 數據中去除無風險利率來計算投資組合的超額收益

  3. tech投資組合收益並減去mature投資組合收益。

5)執行我的回歸分析(表現不佳)。

我只想知道我的邏輯哪裡出錯了。

你不會在任何地方“出錯”。當你說回歸執行不佳時,這表明你的投資組合的回報並沒有被 fama french 因素很好地解釋(這對你的風險因素來說是一件積極的事情,idk 為什麼你稱之為窮人)。

當您做多兩隻股票時,您創建的投資組合風險低於個別股票(我假設股票的相關性是正的,通常是)。如果您願意,風險較小可能是由於對各種參數或因素的敏感性發生變化。在您的情況下,投資組合回報對市場 (mkt_rf) 是中性的,這非常有意義。

引用自:https://quant.stackexchange.com/questions/49146