In this story, we are going to do some basic portfolio returns analysis in python.

在这个故事中,我们将使用python做一些基本的投资组合收益分析。

When we analyze a stock, portfolio, or index’s performance, the first thing we look at is usually the returns, and understandably so, since it’s how much money we make from investing in the instrument. So let’s see what are some of the basic techniques involved in the analysis.

当我们分析股票,投资组合或指数的表现时,我们首先要看的是回报,这是可以理解的,因为这是我们从投资该工具中获利多少。 因此,让我们看一下分析中涉及的一些基本技术。

First we need a time series of prices. How do we go about getting that for testing? The easiest way to do it is using the geometric brown motion(GBM) to generate it:

首先,我们需要一个时间序列的价格。 我们如何进行测试? 最简单的方法是使用几何棕色运动(GBM)生成它:

import pandas as pdimport numpy as npdef brownian_prices(start, end):    bdates = pd.bdate_range(start, end)    size = len(bdates)    np.random.seed(1)    wt = np.random.standard_normal(size)    mu = 0.0001    sigma = 0.01    s0 = 100.0    st = s0 * np.cumprod(np.exp((mu - (sigma * sigma / 2.0))) + sigma * wt)    return pd.DataFrame(data={'date': bdates, 'price': st}).set_index('date')prices = brownian_prices('20200101', '20200801')

There are several advantages of using GBM random process:

使用GBM随机过程有几个优点:

  1. It’s always positive, which is what prices are supposed to be. There are exceptions obviously, like the oil futures recently… But for stocks it’s a good assumption.价格始终是积极的,这应该是正确的。 显然也有例外,例如最近的石油期货……但是对于股票来说,这是一个很好的假设。
  2. The returns of the process is independent of the values of the process. For example, stocks can split, but it shouldn’t change how much money you make from the stock.流程的回报与流程的价值无关。 例如,股票可以分割,但不应改变您从股票中赚多少钱。
  3. It has a very nice functional form and satisfies a differential equation that allows for the development of pricing formulas for derivative instruments like options. i.e. Black-Scholes formula.它具有很好的功能形式,并且满足微分方程,可以开发诸如期权之类的衍生工具的定价公式。 即布莱克-斯科尔斯公式。

Once you have the prices, you can calculate the returns of the instrument:

获得价格后,您可以计算工具的回报:

def daily_returns(prices):    res = (prices/prices.shift(1) - 1.0)[1:]    res.columns = ['return']    return resdret = daily_returns(prices)

return

返回

= (current price -previous price) / previous price

=(当前价格-先前价格)/先前价格

= (current price / previous price) -1

=(当前价格/先前价格)-1

A histogram of the returns will give you a good idea of its distribution, in this case, you can see that the returns are roughly normal with mean around zero.

收益的直方图可以使您很好地了解收益的分布,在这种情况下,您可以看到收益大致为正态,均值约为零。

Once you have the returns, next step is calculating cumulative returns:

获得收益后,下一步就是计算累积收益:

def cumulative_returns(returns):    res = (returns + 1.0).cumprod()    res.columns = ['cumulative return']    return rescret = cumulative_returns(dret)

It’s very simple, and it’s essentially the prices rescaled by initial price.

这很简单,实质上是按初始价格重新调整价格。

Now with the cumulative returns, you can calculate the maximum drawdowns.

现在,有了累积收益,您就可以计算最大亏损。

What is the maximum drawdown? it’s basically how much you can possibly lose at any point in time if you invest in a portfolio. For example, if your stock prices are follows:

最大跌幅是多少? 基本上,这是您投资某个组合在任何时间点可能损失的金额。 例如,如果您的股票价格如下:

On day 1 the maximum you can lose is 0.

在第1天,您最多可以损失0。

On day 2 the maximum you can lose is also 0 (yay!)

在第2天,您最多可以输掉0(是!)

On day 3 the maximum you can lose is… 6.0! You can do that by investing in the stock on day2 (paid 10.0 for the stock and now it’s 4.0, you lose 6.0).

在第3天,您可能损失的最大金额为…6.0! 您可以通过在第2天投资股票来做到这一点(支付10.0的股票价格,现在为4.0,则亏损6.0)。

On day 4 the maximum you can lose is 2.0, again by paying 10.0 on day 2 for the stock.

在第4天,您可以损失的最大金额为2.0,再次在第2天为该股票支付10.0。

On day 5, what is the maximum you can lose? I think it’s pretty clear now that it’s 5.0, since you can pay a max of 10.0 for the stock. Notice it’s not 8.0 minus 5.0, because even though 8.0 is a peak, it’s not the maximum peak.

在第5天,您可以损失的最大金额是多少? 我认为现在是5.0,因为您最多可以为股票支付10.0。 请注意,它不是8.0减去5.0,因为即使8.0是一个峰值,也不是最大峰值。

Below is the code to do that:

下面是执行此操作的代码:

def max_drawdown(cum_returns):    max_returns = np.fmax.accumulate(cum_returns)    res = cum_returns / max_returns - 1    res.columns = ['max drawdown']    return resddown = max_drawdown(cret)

Why is max drawdown important? Aside from the fact that you don’t ever want to lose money, it’s important to limit max drawdown because it is an indication of risk and too much drawdown in a leveraged portfolio can trigger a margin call.

为什么最大亏损很重要? 除了您永远不想亏本的事实外,限制最大跌幅非常重要,因为这是一种风险迹象,杠杆投资组合中的太多跌幅可能会触发追加保证金。

翻译自: https://medium.com/the-innovation/portfolio-analysis-basics-returns-and-drawdowns-70c5f7a0eb3d


http://www.taodudu.cc/news/show-7055395.html

相关文章:

  • 如何借助new bing修复 pyfolio: AttributeError: ‘numpy.int64‘ object has no attribute ‘to_pydatetime‘
  • 用 pyfolio 进行量化交易回测
  • 量化框架backtrader之一文读懂observer观测器
  • backtrader:基于信号的策略开发及参数优化
  • 量化框架backtrader之一文读懂Analyzer分析器
  • 浏览器的渲染流程详解
  • Chromium 最新渲染引擎--RenderingNG
  • 2.浏览器渲染原理
  • 美术学习2200:模型基础
  • 最快的 Houdini 和 V-Ray 云渲染服务
  • Unity渲染顺序文章收集
  • 浏览器渲染顺序
  • V-Ray怎么快速渲染_渲染加速小技巧
  • Unity-默认渲染管线-刻晴卡渲shader
  • 使用Marmoset Toolbag八猴渲染器的Marmoset Viewer进行离线本地观察
  • 计算机二级c语言难度排名,计算机二级难度排名 复习时有哪些技巧
  • 数学建模常规算法:插值和拟合
  • 在云服务器上部署R和Rstudio
  • [ R ] 如何在iPadOS、iOS和MacOS上优雅的跑R —— 使用腾讯云搭建RStudio server的懒人包
  • 云服务器上利用R运行tensorflow/keras
  • 运放输出接电容会带来的问题
  • TL431接电容产生振荡的波形和原因分析
  • 【英语学习】宣传资料的英文单词
  • 资料免费
  • 必须学会看官方的英文文档资料等
  • 重要资料呀
  • 网上英语资料汇总
  • 【找工作资料】英文简历、面试常用词汇
  • 【找工作资料】英文面试问题集
  • 相关资料

投资组合分析的基础收益和亏损相关推荐

  1. 投资组合风险收益率公式_投资组合分析的基础收益和亏损

    投资组合风险收益率公式 In this story, we are going to do some basic portfolio returns analysis in python. 在这个故事 ...

  2. 使用Python进行交易策略和投资组合分析

    我们将在本文中衡量交易策略的表现.并将开发一个简单的动量交易策略,它将使用四种资产类别:债券.股票和房地产.这些资产类别的相关性很低,这使得它们成为了极佳的风险平衡选择. 动量交易策略 这个策略是基于 ...

  3. 市场因子(Market Factor)——投资组合分析(EAP.portfolio_analysis)

    实证资产定价(Empirical asset pricing)已经发布于Github. 包的具体用法(Documentation)博主将会陆续在CSDN中详细介绍. Github: GitHub - ...

  4. 盈利因子(Profitability factor)——投资组合分析(EAP.portfolio_analysis)

    本文根据Bail et al.的著作Empirical Asset Pricing编写相关程序,投资组合分析的模块是EAP.portfolio_analysis.本文的Package已发布于Githu ...

  5. 有效前沿和最优投资组合matlab,matlab 实验名称:投资组合分析 实验性质:综合性和研究探索性 实 联合开发网 - pudn.com...

    matlab 所属分类:matlab例程 开发工具:matlab 文件大小:5918KB 下载次数:30 上传日期:2017-12-27 13:31:24 上 传 者:waffle 说明:  实验名称 ...

  6. python爬取股票平均成本怎么算_Python-多个股票的投资组合分析,对,进行

    一. 股票数据 1 股票选择 一共有十只股票,投资者购买目标指数中的资产,如果购买全部,从理论上讲能够完 美跟踪指数,但是当指数成分股较多时,购买所有资产的成本过于高昂,同时也 需要很高的管理成本,在 ...

  7. python股票编程入门_Python股票量化投资-3.python基础

    Python股票量化投资-1.开发环境部署 Python股票量化投资-2.量化投资介绍 继续开始今天的内容,主要介绍 PyCharm的开发使用[这IDE对JAVA人员来说不陌生] Python的语法推 ...

  8. 投资组合分析:EAP.portfolio_analysis

    投资组合分析是实证资产定价中最常用的工具之一.它的主要用途是研究因子对资产价格的影响,主要方法是通过构建投资组合(portfolios)和投资组合差分(differenced portfolios), ...

  9. 万洲金业:投资现货黄金的收益与风险如何平衡?

    做任何投资都存在收益与风险,理所当然实现收益是投资者喜闻乐见的,风险则受投资者排斥.其实盈利与风险是相伴随行的,在黄金投资中想获得财富的增值,需要平衡好收益与风险两者的关系,让盈利机会增大的同时降低投 ...

最新文章

  1. (Incomplete) UVa 719 Glass Beads
  2. discuzx3.2发帖流程
  3. Java中常用的测试工具JUnit
  4. Druid-目前最好的连接池
  5. 让TFS忽略packages文件夹的更改
  6. ffmpeg的编译(for x86,for arm)安装及使用(网络资料整理)
  7. 【2016年第1期】山东省农业大数据发展刍议
  8. 华为智慧屏华为正式发布鸿蒙,舒适大屏体验,华为智慧屏SE让智慧生活一步到位...
  9. 编译器GCC的Windows版本 : MinGW-w64安装教程
  10. JavaScript表单验证
  11. php居民小区物业水电费管理系统mysql
  12. 生也有涯而知也无涯,以有涯应无涯,殆矣
  13. 服务器带宽10M能带多少人同时访问之并发数计算
  14. 别费劲找站长工具共享VIP了 这个工具也不错
  15. Xmind软件 2020最新安装教程讲解
  16. split函数的用法——java
  17. Apache Jakarta 项目介绍
  18. Angular 脚手架
  19. java.lang.ClassNotFoundException: sun . jdbc . odbc . JdbcOdbcDriver
  20. 线激光扫描三维重建 平移装置 光平面标定

热门文章

  1. chromium 24 chromium 关于crx扩展加载的问题
  2. iconv函数详细解释
  3. k8s篇-集群内的DNS原理与配置和K8s hosts 解析 HostAliases
  4. 【Word】Word文档里怎么输入几分之一
  5. mac下载python的路径在哪?
  6. 12306购票信息爬虫
  7. MacBook上u盘无法格式化
  8. orangepi3 tls更新image
  9. css 定位脱标,CSS 定位
  10. 计算机为什么设置网关地址,默认网关怎么设置?默认网关怎么填?