-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopeland_test.py
56 lines (47 loc) · 1.56 KB
/
copeland_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 17 14:00:28 2015
@author: Desmond
"""
from __future__ import division
import numpy as np
import pandas as pd
import copy
from phd_utils.options.EuropeanOption import *
from phd_utils.assetPricing.models import *
from phd_utils.optionPricing.models import *
from phd_utils.optionPricing.qntyModels import *
from phd_utils.mechanisms.online_models import *
from phd_utils.mechanisms.experiment import *
from phd_utils.tradingAlgos.CDATrader import *
from phd_utils.options.EuropeanCompoundOption import *
import scipy.optimize as optim
import scipy.stats as stats
import matplotlib.pyplot as plt
import sys
price=5
option=CallOption(S0=100,K=105,r=0.05,sigma=0.2, T=0.5)
theta=0.07
phi_b=0.25
phi_a=1-phi_b
volume=5
@np.vectorize
def getLambdaAsk(p):
return volume-(volume/price)*(p-price)
@np.vectorize
def getLambdaBid(p):
return volume+(volume/price)*(p-price)
@np.vectorize
def copelandObjective(p_a, p_b):
puni=np.array([phi_b*(p_a-price), phi_a*(price-p_b)])
pinf=np.array([max(euroCompound(option.S0, option.K, p_a, option.r, option.T-0.0001, option.T, option.sigma, 1),0), max(euroCompound(option.S0, option.K, p_b, option.r, option.T-0.0001, option.T, option.sigma, 3),0)])
lambdas=np.array([getLambdaAsk(p_a), getLambdaBid(p_b)])
obj=np.dot((1-theta)*puni-theta*pinf, lambdas)
return obj
bids=np.linspace(0.01,price, 50)
asks=np.linspace(price,2*price, 50)
xx,yy=np.meshgrid(bids, asks, sparse=True)
z=copelandObjective(xx,yy)
plt.clf()
plt.imshow(z, extent=[0,price, price,2*price])
plt.show()