pandas应用之分组因子暴露和分位数分析

首先感谢原书作者Mes McKinney和batteryhp网友的博文, 俺在此基础上继续探索python的神奇功能.

用A股的实际数据, 以书里的代码为蓝本, 做一些实证探索. 发现不少问题

  • pandas版本升级之后, 函数调用的方式必须相应地改变. 比如 pd.rolling_mean 升级为Series.rolling().mean()等等
  • tushare的数据与yahoo财经的数据格式上的差异, 需要规整化, 等等
  • 至少会有两篇后续的博文详细记录探索历程.

《利用python进行数据分析》读书笔记--第十一章 金融和经济数据应用(一) - 司空格子Ored - 博客园 http://www.cnblogs.com/batteryhp/p/5060381.html

第十一章 金融和经济数据应用(一)

自从2005年以来, Python在金融行业的应用得到了迅猛的增长, 这主要受益于成熟的函数库和经验丰富的Python程序员. 很多机构都发现Python不仅非常适合交互式的分析环境, 而且也非常适合开发稳健的系统, 而且所需的时间要比Java或者C++少很多.

The use of Python in the financial industry has been increasing rapidly since 2005, led

largely by the maturation of libraries (like NumPy and pandas) and the availability of

skilled Python programmers. Institutions have found that Python is well-suited both

as an interactive analysis environment as well as enabling robust systems to be devel-

oped often in a fraction of the time it would have taken in Java or C++.

§1 数据规整化方面的话题(data munging topics)

前几章里涉猎过一些不错的金融应用领域方面的数据规整化的工具. 本章我将重点介绍这一问题领域的几个话题.

Many helpful data munging tools for financial applications are spread across the earlier

chapters. Here I’ll highlight a number of topics as they relate to this problem domain.

操作不同频率的时间序列(Operations with TS of different frequncies)

§2 分组变换和分析(group transforms and analysis)

§3 更多应用实例

在第九章中,已经学习了分组统计的基础,还学习了如何对数据集的分组应用自定义的变换函数。

2.1 分组因子暴露(group factor exposure)

因子分析(factor analysis)是投资组合定量管理中的一种技术。投资组合的持有量和性能(收益与损失)可以被分解为一个或多个表示投资组合权重的因子(风险因子就是其中之一)。例如,某只股票与某个基准(比如标普500指数)的协动性被称为其beta风险系数。下面以一个人为构成的投资的投资组合为例进行讲解,它由三个随机生成的因子(通常称为因子载荷)和一些权重构成。

Factor analysis is a technique in quantitative portfolio management. Portfolio holdings and performance (profit and loss) are decomposed using one or more factors (risk factors are one example) represented as a portfolio of weights. For example, a stock price’s co-movement with a benchmark (like S&P 500 index) is known as its beta, a common risk factor. Let’s consider a contrived example of a portfolio constructed from 3 randomly-generated factors (usually called the factor loadings) and some weights:

2.2 十分位和四分位分析(decimal and quantile analysis)

基于样本分位数的分析是金融分析师们的另一个重要工具,例如,股票投资组合的性能可以根据个股的市盈率被划分到四分位里(四个大小相同的象限)。通过pandas.qcutgroupby函数可以非常轻松地实现分位数分析.

在下面的这个例子里, 我们利用跟随策略或者动量交易策略通过SPY-ETF买卖标普500指数. 你可以从yahoo财经下载历史价格.

Analyzing data based on sample quantiles is another important tool for financial ana-

lysts. For example, the performance of a stock portfolio could be broken down into

quartiles (four equal-sized chunks) based on each stock’s price-to-earnings. Using pandas.qcut combined with groupby makes quantile analysis reasonably straightforward.

As an example, let’s consider a simple trend following or momentum strategy trading

the S&P 500 index via the SPY exchange-traded fund. You can download the price

history from Yahoo! Finance:

pandas应用之分组因子暴露和分位数分析的更多相关文章

  1. pandas聚合和分组运算——GroupBy技术(1)

    数据聚合与分组运算——GroupBy技术(1),有需要的朋友可以参考下. pandas提供了一个灵活高效的groupby功能,它使你能以一种自然的方式对数据集进行切片.切块.摘要等操作.根据一个或多个 ...

  2. pandas聚合和分组运算之groupby

    pandas提供了一个灵活高效的groupby功能,它使你能以一种自然的方式对数据集进行切片.切块.摘要等操作.根据一个或多个键(可以是函数.数组或DataFrame列名)拆分pandas对象.计算分 ...

  3. pandas中的分组技术

    目录 1  分组操作 1.1  按照列进行分组 1.2  按照字典进行分组 1.3  根据函数进行分组 1.4  按照list组合 1.5  按照索引级别进行分组 2  分组运算 2.1  agg 2 ...

  4. pandas获取groupby分组里最大值所在的行,获取第一个等操作

    pandas获取groupby分组里最大值所在的行 10/May 2016 python pandas pandas获取groupby分组里最大值所在的行 如下面这个DataFrame,按照Mt分组, ...

  5. pandas学习(数据分组与分组运算、离散化处理、数据合并)

    pandas学习(数据分组与分组运算.离散化处理.数据合并) 目录 数据分组与分组运算 离散化处理 数据合并 数据分组与分组运算 GroupBy技术:实现数据的分组,和分组运算,作用类似于数据透视表 ...

  6. pandas之groupby分组与pivot_table透视表

    zhuanzi: https://blog.csdn.net/qq_33689414/article/details/78973267 pandas之groupby分组与pivot_table透视表 ...

  7. 数据分析06 /pandas高级操作相关案例:人口案例分析、2012美国大选献金项目数据分析

    数据分析06 /pandas高级操作相关案例:人口案例分析.2012美国大选献金项目数据分析 目录 数据分析06 /pandas高级操作相关案例:人口案例分析.2012美国大选献金项目数据分析 1. ...

  8. dubbo源码分析12——服务暴露3_doExportUrls()方法分析

    本文紧接上文,doExportUrls()方法位于ServiceConfig类中,代码入口如下: private void doExportUrls() { List<URL> regis ...

  9. Pandas学习(三)——NBA球员薪资分析

    欢迎加入python学习交流群 667279387 学习笔记汇总 Pandas学习(一)–数据的导入 pandas学习(二)–双色球数据分析 pandas学习(三)–NAB球员薪资分析 pandas学 ...

随机推荐

  1. 【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。

    There are many kinds of testing which really made me confused. To be honest, I've never heard of som ...

  2. CAS学习笔记(一)

    近期做单点登录,看了一些CAS资料,做下总结 一.cas简介 全名:Central Authentication Service 特点: 1.开源的.多协议的 SSO 解决方案: Protocols  ...

  3. Windows Phone 十六、HttpClient

    HttpClient 对象也可以实现网络请求 相对于 HttpWebRequest 对象来说,HttpClient 操作更简单,功能更强大 HttpClient 提供一系列比较简单的API来实现基本的 ...

  4. Json_异常_net.sf.json.JSONException: JSONObject["solution"] not found.

    net.sf.json.JSONException: JSONObject["solution"] not found. 没有这个元素造成的. 问题代码: JSONObject j ...

  5. Android开发新手学习总结(六)——android开发目录结构【图文版】

    转载链接:http://bbs.itcast.cn/thread-87059-1-1.html?rss 既然已经搭建好环境了,那就对Android Studio中项目目录结构做个简单的了解了,这里以最 ...

  6. EF Core 1.0 和 SQLServer 2008 分页的问题

    EF Core 1.0 在sqlserver2008分页的时候需要指定用数字分页. EF Core1.0 生成的分页语句中使用了 Featch Next.这个语句只有在SqlServer2012的时候 ...

  7. soj 1015 Jill's Tour Paths 解题报告

    题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...

  8. Best Part

  9. linux环境下学习使用pro*c/c++工具

    1.proc是oracle用来预编译嵌入SQL语句的c程序. 2.如何使用proc工具 在Linux环境下,首先确保gcc编译器正常使用,安装oracle数据库或者客户端,一般就会默认安装pro*c/ ...

  10. Good Bye 2015 D. New Year and Ancient Prophecy

    D. New Year and Ancient Prophecy time limit per test 2.5 seconds memory limit per test 512 megabytes ...