zoukankan      html  css  js  c++  java
  • pandas应用之分组因子暴露和分位数分析

    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:

  • 相关阅读:
    自调用匿名函数和js的Module模式
    设置一天中不同时段的倒计时,计算时针和分针的夹角
    移动端web开发中对点透的处理,以及理解fastclick如何做到去除300ms延迟
    使用Fiddler改变线上js文件的引用路径
    Linux下常用设置文件和文件夹读写权限操作
    RESTful API
    mysql之load语句
    Django学习之点赞功能
    Django学习之网站图标
    python学习之pyenv
  • 原文地址:https://www.cnblogs.com/duan-qs/p/6250699.html
Copyright © 2011-2022 走看看