金融时间序列分析笔记

原油价格和汽油价格对美国经济的重要影响:
20 实际 70 年代初期石油危机展示了石油资源的战略意义。
2008 年汽油价格高涨影响了居民生活:
– 交通成本上涨
– 供热成本上涨
– 食品,服务价格上涨 ==> 通货膨胀
– 降低了消费者在其它消费项目上的可支配收入,可能导致经济萧条
研究美国汽油价格以及原油价格对其影响。数据为美国普通石油价格周数据,从 1997-01-06 到 2010-09-27 。时间是每周三 , 共 717 个时间点 ; 美国原油价格周数据,从 1997-01-03 到 2010-09-24 。时间是每周日。共717 个时间点。原油价格比汽油价格早 3 天发布。
读入数据: w-petroprice.txt 又是一个用单个空格、多个空格、制表符、空格加制表符分隔的文件。这种
文件千万不要自己制造出来。最简单的解决办法是用文本编辑器编辑,将制表符都替换成单个空格。下面的R 程序用了 R 语言的文件操作和正则表达式进行替换:

la <- readLines("w-petroprice.txt")
la <- gsub("\\s+", " ", la)
la <- gsub("^\\s+|\\s$", "", la)

Regular Expression Syntax:
在这里插入图片描述

R gsub Function Examples – EndMemo
http://www.endmemo.com/program/R/gsub.php

gsub() function replaces all matches of a string, if the parameter is a string vector, returns a string vector of the same length and with the same attributes (after possible coercion to character). elements of string vectors which are not substituted will be returned unchanged (including any declared encoding).

替换字符串的所有匹配,如果参数是字符串向量,则返回相同长度和相同属性的字符串向量(在可能强制字符之后)。 未被替换的字符串向量的元素将不变地返回(包括任何声明的编码)。

gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)

pattern: string to be matched, supports regular expression
模式:要匹配的字符串,支持正则表达式
replacement: string for replacement
替换:字符串进行替换
x: string or string vector
x:字符串或字符串向量
perl: logical. should perl-compatible regexps be used? has priority over extended
应该使用Perl兼容的regexps吗? 优先于扩展
fixed: logical. if true, pattern is a string to be matched as is. overrides all conflicting arguments
如果为真,则模式是要匹配的字符串。 覆盖所有冲突的参数
usebytes: logical. if true the matching is done byte-by-byte rather than character-by-character
如果为真,则匹配是逐字节完成的,而不是逐字符完成的

附录:原题
在这里插入图片描述
这本书在这里下载:https://www.quantsummaries.com/Li_FTSA.pdf

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值