亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python障礙式期權定價公式

發布時間:2020-10-19 11:19:15 來源:腳本之家 閱讀:240 作者:王大錘95 欄目:開發技術

早期寫的python障礙式期權的定價腳本,供大家參考,具體內容如下

#coding:utf-8
'''
障礙期權
q=x/s
H = h/x H 障礙價格
[1] Down-and-in call cdi
[2] Up-and-in call cui
[3] Down-and-in put pdi
[4] Up-and-in put pui
[5] Down-and-out call cdo
[6] Up-and-out call cuo
[7] Down-and-out put pdo
[8] Up-and-out put puo

'''
from math import log,sqrt,exp,ceil
from scipy import stats
import datetime
import tushare as ts
import pandas as pd
import numpy as np
import random
import time as timess
import os

def get_codes(path='D:\\code\\20180313.xlsx'):     #從代碼表格從獲取代碼
 codes = pd.read_excel(path)
 codes = codes.iloc[:,1]    
 return codes

def get_datas(code,N=1,path='D:\\data\\'):        #獲取數據N=1當天數據
 datas = pd.read_csv(path+eval(code)+'.csv',encoding='gbk',skiprows=2,header=None,skipfooter=N,engine='python').dropna() #讀取CSV文件 名稱為股票代碼 解gbk skiprows跳過前兩行文字 第一行不做為表頭
 date_c = datas.iloc[:,[0,4,5]]     #只用第0 列代碼數據和第4列收盤價數據
 date_c.index = datas[0]
 return date_c

def get_sigma(close,std_th):
 x_i = np.log(close/close.shift(1)).dropna()
 sigma = x_i.rolling(window=std_th).std().dropna()*sqrt(244)
 return sigma

def get_mu(sigma,r):
 mu = (r-pow(sigma,2)/2)/pow(sigma,2)
 return mu

def get_lambda(mu,r,sigma):
 lam = sqrt(mu*mu+2*r/pow(sigma,2))
 return lam

def x_y(sigma,T,mu,H,lam,q=1):
 x1 = log(1/q)/(sigma*sqrt(T))+(1+mu)*sigma*sqrt(T)
 x2 = log(1/(q*H))/(sigma*sqrt(T))+(1+mu)*sigma*sqrt(T)
 y1 = log(H*H/q)/(sigma*sqrt(T))+(1+mu)*sigma*sqrt(T)
 y2 = log(q*H)/(sigma*sqrt(T))+(1+mu)*sigma*sqrt(T)
 z = log(q*H)/(sigma*sqrt(T))+lam*sigma*sqrt(T)
 return x1,x2,y1,y2,z

def get_standardBarrier(eta,phi,mu,sigma,r,T,H,lam,x1,x2,y1,y2,z,q=1):
 f1 = phi*1*stats.norm.cdf(phi*x1,0.0,1.0)-phi*q*exp(-r*T)*stats.norm.cdf(phi*x1-phi*sigma*sqrt(T),0.0,1.0)
 f2 = phi*1*stats.norm.cdf(phi*x2,0.0,1.0)-phi*q*exp(-r*T)*stats.norm.cdf(phi*x2-phi*sigma*sqrt(T),0.0,1.0)
 f3 = phi*1*pow(H*q,2*(mu+1))*stats.norm.cdf(eta*y1,0.0,1.0)-phi*q*exp(-r*T)*pow(H*q,2*mu)*stats.norm.cdf(eta*y1-eta*sigma*sqrt(T),0.0,1.0)
 f4 = phi*1*pow(H*q,2*(mu+1))*stats.norm.cdf(eta*y2,0.0,1.0)-phi*q*exp(-r*T)*pow(H*q,2*mu)*stats.norm.cdf(eta*y2-eta*sigma*sqrt(T),0.0,1.0)
 f5 = (H-1)*exp(-r*T)*(stats.norm.cdf(eta*x2-eta*sigma*sqrt(T),0.0,1.0)-pow(H*q,2*mu)*stats.norm.cdf(eta*y2-eta*sigma*sqrt(T),0.0,1.0))
 f6 = (H-1)*(pow(H*q,(mu+lam))*stats.norm.cdf(eta*z,0.0,1.0)+pow(H*q,(mu-lam))*stats.norm.cdf(eta*z-2*eta*lam*sigma*sqrt(T),0.0,1.0))
 return f1,f2,f3,f4,f5,f6

def main(param,t,r=0.065):
 typeflag = ['cdi','cdo','cui','cuo','pdi','pdo','pui','puo']
 r = log(1+r)
 T = t/365
 codes = get_codes()
 H = 1.2
 for i in range(len(codes)):
 sdbs = []
 for j in typeflag:
 code = codes.iloc[i]
 datas = get_datas(code)
 close = datas[4]
 sigma = get_sigma(close,40)[-1]
 mu = get_mu(sigma,r)
 lam = get_lambda(mu,r,sigma)
 x1,x2,y1,y2,z = x_y(sigma,T,mu,H,lam)
 eta = param[j]['eta']
 phi = param[j]['phi']
 f1,f2,f3,f4,f5,f6 = get_standardBarrier(eta,phi,mu,sigma,r,T,H,lam,x1,x2,y1,y2,z)
 if j=='cdi':
 sdb = f1-f2+f4+f5
 if j=='cui':
 sdb = f2-f3+f4+f5
 if j=='pdi':
 sdb = f1+f5
 if j=='pui':
 sdb = f3+f5
 if j=='cdo':
 sdb = f2+f6-f4
 if j=='cuo':
 sdb = f1-f2+f3-f4+f6
 if j=='pdo':
 sdb = f6
 if j=='puo':
 sdb = f1-f3+f6
 sdbs.append(sdb)
 print(T,r,sigma,H,sdbs)
if __name__ == '__main__':
 param = {'cdi':{'eta':1,'phi':1},'cdo':{'eta':1,'phi':1},'cui':{'eta':-1,'phi':1},'cuo':{'eta':-1,'phi':1},
 'pdi':{'eta':1,'phi':-1},'pdo':{'eta':1,'phi':-1},'pui':{'eta':-1,'phi':-1},'puo':{'eta':-1,'phi':-1}}
 t = 30
 main(param,t)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

中超| 南靖县| 琼结县| 清水县| 顺昌县| 福州市| 五常市| 和林格尔县| 辛集市| 庆城县| 江西省| 沁水县| 南岸区| 定襄县| 新兴县| 乌鲁木齐县| 德阳市| 大埔区| 丹江口市| 西宁市| 呼玛县| 彭州市| 洛南县| 吉安市| 宜丰县| 牡丹江市| 绩溪县| 东港市| 青阳县| 南昌县| 宁城县| 酒泉市| 璧山县| 洪泽县| 玉田县| 酉阳| 紫金县| 如皋市| 临夏县| 定南县| 容城县|