2)以深成指为例,请“粗略地”将整个样本期划分为牛市期间、熊市期间、振荡期间(提示 它们未必是连续区间,可能是不同时期的叠加,呈现为非经典、非规范的 时间序列),然后再分市场不同状态、验证牛市/熊市/振荡期间各自的“红 周一”与“黑周末”的统计显著性。r语言代码
时间: 2024-02-24 11:55:47 浏览: 72
大盘创新高的动力有多大.docx
很抱歉,作为一名语言模型AI,我无法运行R语言代码,但你可以参考以下思路:
1. 导入深成指的历史行情数据,包括每个交易日的收盘价和涨跌幅等信息。
2. 根据涨跌幅的正负,将每个交易日划分为涨、跌或平状态。
3. 将整个样本期按照牛市、熊市和振荡市场进行划分,并计算每个市场状态下“红周一”和“黑周末”的出现概率。
4. 进行假设检验,验证“红周一”和“黑周末”的统计显著性。
以下是R语言代码的示例:
```r
# 导入深成指历史行情数据
library(quantmod)
getSymbols("^SZ399001", from = "2013-01-01", to = "2021-09-30")
shenzhen <- as.data.frame(SZ399001)
colnames(shenzhen) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")
shenzhen <- shenzhen[, c("Close")]
# 计算每个交易日的涨跌幅
shenzhen$returns <- diff(log(shenzhen$Close))
# 划分市场状态
bull_market <- shenzhen["2014-11-01/2015-06-30", ]
bear_market <- shenzhen["2015-06-01/2016-02-29", ]
bull_market2 <- shenzhen["2016-02-01/2018-01-31", ]
bear_market2 <- shenzhen["2018-01-01/2019-01-31", ]
oscillating_market <- shenzhen["2013-01-01/2014-11-01", ]
oscillating_market2 <- shenzhen["2021-01-01/2021-04-30", ]
bull_market3 <- shenzhen["2019-01-01/2019-04-30", ]
bull_market4 <- shenzhen["2020-04-01/2021-09-30", ]
# 计算每个市场状态下的“红周一”和“黑周末”的出现概率
red_monday <- function(market) {
monday_returns <- market[weekdays(index(market)) == "Monday", "returns"]
red_monday <- mean(monday_returns > 0)
return(red_monday)
}
black_weekend <- function(market) {
friday_returns <- market[weekdays(index(market)) == "Friday", "returns"]
black_weekend <- mean(friday_returns < 0)
return(black_weekend)
}
red_monday_bull <- red_monday(bull_market)
red_monday_bear <- red_monday(bear_market)
red_monday_bull2 <- red_monday(bull_market2)
red_monday_bear2 <- red_monday(bear_market2)
red_monday_oscillating <- red_monday(oscillating_market)
red_monday_oscillating2 <- red_monday(oscillating_market2)
red_monday_bull3 <- red_monday(bull_market3)
red_monday_bull4 <- red_monday(bull_market4)
black_weekend_bull <- black_weekend(bull_market)
black_weekend_bear <- black_weekend(bear_market)
black_weekend_bull2 <- black_weekend(bull_market2)
black_weekend_bear2 <- black_weekend(bear_market2)
black_weekend_oscillating <- black_weekend(oscillating_market)
black_weekend_oscillating2 <- black_weekend(oscillating_market2)
black_weekend_bull3 <- black_weekend(bull_market3)
black_weekend_bull4 <- black_weekend(bull_market4)
# 进行假设检验,验证统计显著性
t.test(bull_market[weekdays(index(bull_market)) == "Monday", "returns"])
t.test(bear_market[weekdays(index(bear_market)) == "Monday", "returns"])
t.test(bull_market2[weekdays(index(bull_market2)) == "Monday", "returns"])
t.test(bear_market2[weekdays(index(bear_market2)) == "Monday", "returns"])
t.test(oscillating_market[weekdays(index(oscillating_market)) == "Monday", "returns"])
t.test(oscillating_market2[weekdays(index(oscillating_market2)) == "Monday", "returns"])
t.test(bull_market3[weekdays(index(bull_market3)) == "Monday", "returns"])
t.test(bull_market4[weekdays(index(bull_market4)) == "Monday", "returns"])
t.test(bull_market[weekdays(index(bull_market)) == "Friday", "returns"])
t.test(bear_market[weekdays(index(bear_market)) == "Friday", "returns"])
t.test(bull_market2[weekdays(index(bull_market2)) == "Friday", "returns"])
t.test(bear_market2[weekdays(index(bear_market2)) == "Friday", "returns"])
t.test(oscillating_market[weekdays(index(oscillating_market)) == "Friday", "returns"])
t.test(oscillating_market2[weekdays(index(oscillating_market2)) == "Friday", "returns"])
t.test(bull_market3[weekdays(index(bull_market3)) == "Friday", "returns"])
t.test(bull_market4[weekdays(index(bull_market4)) == "Friday", "returns"])
```
阅读全文