【金融量化】Python实现根据收益率计算累计收益率并可视化

1 理论

理财产品(本金100元)

第1天:3% :(1+3%) ✖ 100 = 103

第2天:2% :(1+2%)✖ 以上 = 103 +2.06

第3天:5% : (1+5%)✖ 以上 = 收益 ✖ 以上

第4天:6% :(1+6%)✖ 以上 = 收益 ✖ 以上

... 累计收益=(1+当天收益率)的累计乘积-1

这里的计算公式为什么需要减去1呢? 因为我们上面的公式都是包括本金的,比如说103应该减去100,只有3元才是我们的利润,所以这里需要减去1,将本金删除掉

2 实现

python 复制代码
import pandas as pd
# 计算累计收益率
def calculate_cum_prof(data):
    data['cum_profit'] = pd.DataFrame(1+data['profit_pct']).cumprod()-1
    data['cum_profit'].plot()
    return data
相关推荐
Awesome Baron3 分钟前
《Learning Langchain》阅读笔记8-RAG(4)在vector store中存储embbdings
python·jupyter·chatgpt·langchain·llm
阡之尘埃5 分钟前
Python数据分析案例73——基于多种异常值监测算法探查内幕交易信息
人工智能·python·机器学习·数据分析·异常检测·无监督学习
蓝莓味柯基1 小时前
Python3:文件操作
python
xiaoh_71 小时前
解决视频处理中的 HEVC 解码错误:Could not find ref with POC xxx【已解决】
python·ffmpeg·音视频
明月与玄武2 小时前
Python编程的真谛:超越语法,理解编程本质
python·编程语言
CodeCraft Studio2 小时前
Excel处理控件Aspose.Cells教程:使用 Python 在 Excel 中进行数据验
开发语言·python·excel
拾忆-eleven3 小时前
C语言实战:用Pygame打造高难度水果消消乐游戏
c语言·python·pygame
旦莫3 小时前
Python 教程:我们可以给 Python 文件起中文名吗?
开发语言·python
豌豆花下猫3 小时前
Python 潮流周刊#99:如何在生产环境中运行 Python?(摘要)
后端·python·ai
小杨4043 小时前
python入门系列二十(peewee)
人工智能·python·pycharm