吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2274|回复: 3
收起左侧

[Python 原创] 【python】利用python编程帮助理解艰难晦涩的金融衍生品工具公式。

  [复制链接]
goldenhairs 发表于 2019-11-14 09:11
本帖最后由 goldenhairs 于 2019-11-14 09:31 编辑

因为工作原因需要考一个证,就买了一本学习《投资咨询》的书。书中很多计算公式比较难以理解,自己就试着用这个python写了一个计算各类权益的小程序。希望对各位有所帮助。(第一次试着发帖,如果有格式不当请告知。主要功能就是输入相关的利率及期限,就可以计算出金融衍生品的收益。
源码如下:
[Python] 纯文本查看 复制代码
import math
#权益类的远期价格:
def no_profit():
    r=int(input("请输入利率r%_:"))
    T=int(input("期货合约到期日T:"))
    t=int(input("t时刻建立的头寸:"))
    S0=float(input("现金(元):"))
    #r为利率,t为持有周期,S0为现金
    t=T-t
    f=S0*math.exp(r/100*t/365)
    print("不支付红利的标的资产价格:")
    print("持有周期{0}天:".format(t))
    print("权益资产远期理论价格:",round(f,2),"元")
    
def have_profit():
    r=int(input("请输入利率r%_:"))
    T=int(input("期货合约到期日T:"))
    t=int(input("t时刻建立的头寸:"))
    S0=float(input("现金(元):"))
    D0=int(input("t时刻支付的红利折现值(元):")) 
    #r为利率,t为持有周期,S0为现金,D0为t时刻支付的红利折现值
    t=T-t
    f=(S0-D0)*math.exp(r/100*t/365)
    print("支付红利的标的资产价格:")
    print("持有周期{0}天:".format(t))
    print("权益资产远期理论价格:",round(f,2),"元")

def continues_profit():
    r=int(input("请输入利率r%_:"))
    T=int(input("期货合约到期日T:"))
    t=int(input("t时刻建立的头寸:"))
    S0=float(input("现金(元):"))
    q=int(input("q为连续支付的红利利率%_:"))
    
    #r为利率,t为持有周期,S0为现金,q为连续支付的红利利率
    t=T-t
    f=S0*math.exp((r-q)/100*t/365)
    print("支付红利利率的标的资产价格:")
    print("持有周期{0}天:".format(t))
    print("权益资产远期理论价格:",round(f,2),"元")

#国债期货的定价
def country_dept():
    r=int(input("请输入利率r%_:"))
    T=int(input("期货合约到期日T:"))
    t=int(input("t时刻建立的头寸:"))
    t0=int(input("国债远期合约到期时间(天):"))
    S0=float(input("当前净报价(元):"))
    q=int(input("q为国债的息票率%_:"))
    #r为无风险利率,t为付息时间时间,T下次付息时间,S0为当前报价,q为息票率
    f=(S0+(t*q)/(t+T)-q*math.exp(-r*T/36500))*math.exp(r*t0/36500)
    print("持有周期{0}天:".format(t0))
    print("国债远期理论价格:",round(f,2),"元")




#商品期货的定价
def future_price():
    r=int(input("请输入无风险利率r%_:"))
    t=int(input("期货合约到期天数:"))
    u=int(input("仓储成本率:"))
    z=int(input("便利收益率:"))
    S0=float(input("现货报价(元):"))
    f=S0*math.exp((r+u-z)*t/36500)
    print("持有周期{0}天:".format(t))
    print("商品期货理论价格:",round(f,2),"元")



#外汇期货的定价

def libor_price():
    r=float(input("即期汇率r%_:"))
    rf=float(input("外汇国的无风险利率rf%_:"))
    rd=float(input("本国的无风险利率rd%_:"))
    t=int(input("外汇期货的到期日(月)"))
    f=r*math.exp((rd-rf)*t/1200)
    print("持有周期{0}个月:".format(t))
    print("外汇期货远期汇率是:",round(f,3))

no_profit()
have_profit()
country_dept()
continues_profit()
future_price()
libor_price()

权益类资产价格.zip

995 Bytes, 下载次数: 18, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
heelihua + 1 + 1 鼓励转贴优秀软件安全工具和文档!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

heelihua 发表于 2019-11-15 09:21
楼主,在PY里面用,还是打包好的程序呢?
 楼主| goldenhairs 发表于 2019-11-15 10:28
米多 发表于 2019-11-15 10:45
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-1 11:13

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表