Prova 2

import dos módulos básicos


In [530]:
# always yielding a real result, even dividing two integers
from __future__ import division

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st
import datetime as dt
from dateutil.relativedelta import relativedelta
from functools import reduce
import operator

# plot inline
%matplotlib inline

Carregando dados de feriados: cdi e bmf. Fonte: anbima


In [531]:
feriado_arq = 'feriados.xlsx'
feriado_cdi = pd.read_excel(feriado_arq,'cdi')
feriado_bmf = pd.read_excel(feriado_arq,'bmf')

Carregando dados de mercado


In [532]:
mkt_series_arq = 'BBergValues.xlsx'
usdbrl=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="A:E")
ptax=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="G:H")
ibov=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="J:M")
di1f21=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="O:S")
cdi=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="U:V")
cds5y=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="X:AB")
vol1m_off=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="AD:AH")
vol3m_off=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="AJ:AN")
vol12m_off=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="AP:AT")
swpprecdi1m=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="AV:AZ")
swpprecdi3m=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="BB:BF")
swpprecdi12m=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="BH:BL")
fwd1m_on=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="BN:BR")
fwd3m_on=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="BT:BX")
fwd12m_on=pd.read_excel(mkt_series_arq,'Sheet1',skiprows=1,index_col=0,parse_cols="BZ:CD")

In [681]:
vol=pd.DataFrame(vol1m_off['PX_LAST'].values,columns=[1],index=vol1m_off.index)
vol[3]=vol3m_off['PX_LAST'].values
vol[12]=vol12m_off['PX_LAST'].values

fwd=pd.DataFrame(usdbrl['PX_LAST'].values,columns=[0],index=usdbrl.index)
fwd[1]=fwd1m_on['PX_LAST'].values
fwd[3]=fwd3m_on['PX_LAST'].values
fwd[12]=fwd12m_on['PX_LAST'].values

pre=pd.DataFrame(cdi['PX_LAST'].values,columns=[0],index=cdi.index)
pre[1]=swpprecdi1m['PX_LAST'].values
pre[3]=swpprecdi3m['PX_LAST'].values
pre[12]=swpprecdi12m['PX_LAST'].values

In [658]:
cdi.plot()


Out[658]:
<matplotlib.axes._subplots.AxesSubplot at 0x19aed032fd0>

In [5]:
ibov.plot()


Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0xb156f98>

Questão 1


Como estimar o risco dos portfolios do fundo a partir das séries de preços? Aponte as diferenças entre como estimar o risco entre os diferentes tipos de séries. Assuma que esse cálculo está sendo feito em 31-Mar-2016.


In [ ]:

Questão 2


Um trader olhou o gráfico abaixo e pensou em uma estratégia.

a) Qual a estratégia que você acha que ele pensou?


In [ ]:

b) Faz sentido? Qual a proporção dos ativos? Ela é fixa?

c) Se ele tivesse entrado no trade em 13-Abr-2016, qual teria sido o máximo drawdown (perda) dele no período entre 13-Abr-2016 e 22-Jun-2016? Assuma notional de BRL 1MM.

d) A estimativa de risco que você teria feito teria estimado corretamente esse resultado?

e) Acrescente Ibovespa como uma estratégia (não esqueça do funding!); você faria algum novo trade?

Questão 3


Em 30-Jun-2015 vários traders compraram opções de compra de USD (venda de BRL) ATMF para diferentes prazos. Use os dados anexos, interpolação linear para spot e forwards, e a interpolação adequada para vols ATMF (vol forward constante, variância efetiva é a soma das variâncias efetivas) para estimar os resultados finais e perdas máximas de cada um dos traders.

Definindo a função BS para ser utilizada na precificação das opções


In [587]:
def bsv(phi,F,K,discount,vol,t):
    if(t>0):
        # calculate d1 and d2
        sigma_rt = vol*np.sqrt(t)
        d1=(np.log(F/K)+(vol**2/2)*t)/(sigma_rt)
        d2=d1-sigma_rt

        # calculate N(d1) and N(d2)
        Nd1=st.norm.cdf(phi*d1)
        Nd2=st.norm.cdf(phi*d2)
        delta=phi*Nd1*discount
        premium=phi*(F*Nd1-K*Nd2)*discount
    else:
        delta=0
        premium=max(phi*(F-K),0)
        
    return [premium,delta]

Definindo função para fazer a interpolação da vol:


In [589]:
def interpolaVol(dt0,v0,dt1,v1,dt):
    vv0=v0**2
    vv1=v1**2
    d0=dt0.toordinal()
    d1=dt1.toordinal()
    d=dt.toordinal()
    
    vv=((1/(d1-d0))*(vv1*d1*(d-d0)+vv0*d0*(d1-d)))/d
    return np.sqrt(vv)

Definindo a função para inicializar o DataFrame com as séries de acordo com o prazo (tenor)


In [769]:
def portf_initdf(start,months,usdbrl,cdi,fwd_tenor,vol_tenor,swpprecdi_tenor):
    term=relativedelta(months=months)
    end=start+term
    s=pd.Series(usdbrl['PX_LAST'][start:end])
    df=pd.DataFrame(s.index)
    df['t']=[(end.toordinal()-i.toordinal())/365 for i in df['Date']]
    df['tenor']=[i+term for i in s.index]
    df['usdbrl']=usdbrl['PX_LAST'][start:end].values
    df['cdi']=cdi['PX_LAST'][start:end].values/100
    df['cdi']=cdi['PX_LAST'][start:end].values/100
    cdiprod=[reduce(operator.mul,(1+df['cdi'][0:i])**(1/252),1) for i in range(1,len(df))]
    cdiprod.insert(0,1)
    df['cdiprod']=cdiprod
    df['fwd_tenor']=fwd_tenor[months][start:end].values
    df['vol_tenor']=vol_tenor[months][start:end].values/100
    df['pre_tenor']=swpprecdi_tenor[months][start:end].values/100
    df['strike']=df['fwd_tenor'][0]
    
    #interpolações
    if(months==1):
        tenor_short=df['Date']
        fwd_short=df['usdbrl']
        vol_short=df['vol_tenor']
        pre_short=df['cdi']
 
    if(months==3):
        tenor_short=[i+relativedelta(months=1) for i in s.index]
        fwd_short=fwd[1][start:end]
        vol_short=vol[1][start:end]/100
        pre_short=pre[1][start:end]/100
        
    if(months==12):
        tenor_short=[i+relativedelta(months=3) for i in s.index]
        fwd_short=fwd[3][start:end]
        vol_short=vol[3][start:end]/100
        pre_short=pre[3][start:end]/100
 
    df['fwd']=[fwd_short[i]+(df['fwd_tenor'][i]-fwd_short[i])*((end-tenor_short[i])/(df['tenor'][i]-tenor_short[i])) for i in df['Date'].index]
    df['vol']=[interpolaVol(tenor_short[i],vol_short[i],df['tenor'][i],df['vol_tenor'][i],end) for i in df['Date'].index]
    df['discount']=[pre_short[i]+(df['pre_tenor'][i]-pre_short[i])*((end-tenor_short[i])/(df['tenor'][i]-tenor_short[i])) for i in df['Date'].index]
    df['discount']=(1+df['discount'])**[-(end.toordinal()-i.toordinal())/365 for i in df['Date']]
    df=df.join(pd.DataFrame([bsv(call,df['fwd'][i],df['strike'][i],df['discount'][i],df['vol'][i],df['t'][i]) for i in df['Date'].index],columns=['premium','delta']))
    
    return df

In [770]:
portf_initdf(start,3,usdbrl,cdi,fwd,vol,pre)


Out[770]:
Date t tenor usdbrl cdi cdiprod fwd_tenor vol_tenor pre_tenor strike fwd vol discount premium delta
0 2015-06-30 0.252055 2015-09-30 3.1030 0.1364 1.000000 3.2018 0.15825 0.140176 3.2018 3.201800 0.158250 0.967475 0.098157 0.499066
1 2015-07-01 0.249315 2015-10-01 3.1492 0.1364 1.000508 3.2487 0.15823 0.140454 3.2018 3.247613 0.158292 0.967777 0.122130 0.567873
2 2015-07-02 0.246575 2015-10-02 3.0967 0.1364 1.001015 3.1941 0.15380 0.140722 3.2018 3.191998 0.153755 0.968084 0.089575 0.483276
3 2015-07-03 0.243836 2015-10-03 3.1341 0.1364 1.001523 3.2342 0.15417 0.140665 3.2018 3.230944 0.153972 0.968458 0.109241 0.544713
4 2015-07-06 0.235616 2015-10-06 3.1376 0.1364 1.002032 3.2357 0.15392 0.140265 3.2018 3.229297 0.152791 0.969612 0.106171 0.543523
5 2015-07-07 0.232877 2015-10-07 3.1863 0.1364 1.002540 3.2856 0.15743 0.140680 3.2018 3.278026 0.156984 0.969895 0.136453 0.617097
6 2015-07-08 0.230137 2015-10-08 3.2353 0.1364 1.003049 3.3364 0.15997 0.139951 3.2018 3.327613 0.159873 0.970378 0.169928 0.684801
7 2015-07-09 0.227397 2015-10-09 3.2130 0.1364 1.003558 3.3367 0.15920 0.140218 3.2018 3.326874 0.159215 0.970690 0.168618 0.685622
8 2015-07-10 0.224658 2015-10-10 3.1599 0.1364 1.004067 3.2576 0.15942 0.139615 3.2018 3.246780 0.158929 0.971142 0.117527 0.571205
9 2015-07-13 0.216438 2015-10-13 3.1344 0.1364 1.004577 3.2316 0.15977 0.139833 3.2018 3.218110 0.157567 0.972164 0.099386 0.527103
10 2015-07-14 0.213699 2015-10-14 3.1393 0.1364 1.005087 3.2381 0.15542 0.139781 3.2018 3.223297 0.155572 0.972516 0.100458 0.536170
11 2015-07-15 0.210959 2015-10-15 3.1401 0.1364 1.005597 3.1745 0.15542 0.139954 3.2018 3.173934 0.155096 0.972843 0.075225 0.452664
12 2015-07-16 0.208219 2015-10-16 3.1568 0.1364 1.006107 3.1805 0.15160 0.139842 3.2018 3.182939 0.150050 0.973220 0.075986 0.466409
13 2015-07-17 0.205479 2015-10-17 3.1881 0.1364 1.006618 3.2415 0.15273 0.140001 3.2018 3.235313 0.151378 0.973545 0.103059 0.558619
14 2015-07-20 0.197260 2015-10-20 3.1958 0.1364 1.007129 3.2595 0.16070 0.138640 3.2018 3.249861 0.160096 0.974752 0.114551 0.581738
15 2015-07-21 0.194521 2015-10-21 3.1716 0.1364 1.007640 3.2160 0.15847 0.139561 3.2018 3.212970 0.158291 0.974991 0.092633 0.520438
16 2015-07-22 0.191781 2015-10-22 3.2231 0.1364 1.008151 3.2715 0.16200 0.139508 3.2018 3.266162 0.163180 0.975332 0.124753 0.607954
17 2015-07-23 0.189041 2015-10-23 3.2854 0.1364 1.008663 3.3265 0.17507 0.140139 3.2018 3.323823 0.177599 0.975594 0.168831 0.682435
18 2015-07-24 0.186301 2015-10-24 3.3554 0.1364 1.009175 3.3860 0.17767 0.142377 3.2018 3.387141 0.183010 0.975670 0.216324 0.755111
19 2015-07-27 0.178082 2015-10-27 3.3637 0.1364 1.009687 3.4663 0.17752 0.142248 3.2018 3.436600 0.182187 0.976713 0.253412 0.811846
20 2015-07-28 0.175342 2015-10-28 3.3567 0.1364 1.010200 3.4590 0.17757 0.142376 3.2018 3.428292 0.181653 0.977041 0.246075 0.806563
21 2015-07-29 0.172603 2015-10-29 3.3314 0.1364 1.010712 3.4343 0.17733 0.142402 3.2018 3.402020 0.181294 0.977388 0.224613 0.782281
22 2015-07-30 0.169863 2015-10-30 3.3713 0.1413 1.011225 3.4735 0.17343 0.142111 3.2018 3.440057 0.172875 0.977545 0.251889 0.832405
23 2015-07-31 0.167123 2015-10-31 3.4211 0.1413 1.011756 3.5248 0.17625 0.141749 3.2018 3.489379 0.176642 0.978119 0.294770 0.870647
24 2015-08-03 0.158904 2015-11-03 3.4508 0.1413 1.012287 3.5546 0.17708 0.142143 3.2018 3.517200 0.181895 0.979155 0.319766 0.889630
25 2015-08-04 0.156164 2015-11-04 3.4711 0.1413 1.012818 3.5716 0.17955 0.141984 3.2018 3.534764 0.183756 0.979515 0.335665 0.900225
26 2015-08-05 0.153425 2015-11-05 3.4851 0.1413 1.013349 3.5863 0.18250 0.142088 3.2018 3.548234 0.184146 0.979868 0.347733 0.909231
27 2015-08-06 0.150685 2015-11-06 3.5363 0.1413 1.013881 3.6372 0.18673 0.143160 3.2018 3.595954 0.188568 0.980147 0.392173 0.928853
28 2015-08-07 0.147945 2015-11-07 3.5071 0.1413 1.014413 3.5665 0.18655 0.143662 3.2018 3.551113 0.187736 0.980465 0.350605 0.911079
29 2015-08-10 0.139726 2015-11-10 3.4404 0.1413 1.014945 3.5215 0.18287 0.142568 3.2018 3.489641 0.182944 0.981618 0.293688 0.885421
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
37 2015-08-20 0.112329 2015-11-20 3.4579 0.1413 1.019212 3.5600 0.18038 0.141680 3.2018 3.505739 0.183999 0.985245 0.305830 0.919604
38 2015-08-21 0.109589 2015-11-21 3.4998 0.1413 1.019747 3.6006 0.18163 0.141795 3.2018 3.543144 0.185918 0.985601 0.340686 0.939474
39 2015-08-24 0.101370 2015-11-24 3.5524 0.1413 1.020282 3.6555 0.18445 0.142106 3.2018 3.593648 0.193689 0.986659 0.389071 0.958522
40 2015-08-25 0.098630 2015-11-25 3.6172 0.1413 1.020817 3.7187 0.18807 0.142140 3.2018 3.657926 0.197205 0.987017 0.451380 0.972630
41 2015-08-26 0.095890 2015-11-26 3.5968 0.1413 1.021353 3.6983 0.19440 0.142023 3.2018 3.635787 0.208778 0.987386 0.430536 0.964841
42 2015-08-27 0.093151 2015-11-27 3.5526 0.1413 1.021888 3.6558 0.18905 0.141900 3.2018 3.590003 0.196283 0.987744 0.385604 0.961890
43 2015-08-28 0.090411 2015-11-28 3.5819 0.1413 1.022425 3.6847 0.19077 0.141934 3.2018 3.616318 0.196683 0.988107 0.411029 0.969934
44 2015-08-31 0.082192 2015-11-30 3.6198 0.1413 1.022961 3.7245 0.19653 0.142797 3.2018 3.654500 0.208950 0.989161 0.448762 0.976673
45 2015-09-01 0.079452 2015-12-01 3.6977 0.1413 1.023498 3.8040 0.20000 0.143122 3.2018 3.732852 0.212699 0.989523 0.525830 0.984769
46 2015-09-02 0.076712 2015-12-02 3.7609 0.1413 1.024035 3.8679 0.20972 0.143128 3.2018 3.794985 0.222855 0.989883 0.587373 0.987230
47 2015-09-03 0.073973 2015-12-03 3.7397 0.1413 1.024572 3.8458 0.20855 0.142535 3.2018 3.772462 0.216883 0.990266 0.565272 0.987813
48 2015-09-04 0.071233 2015-12-04 3.8430 0.1413 1.025109 3.9516 0.21475 0.143942 3.2018 3.873387 0.224221 0.990592 0.665310 0.989939
49 2015-09-07 0.063014 2015-12-07 3.8430 0.1413 1.025647 3.9516 0.21660 0.143942 3.2018 3.869777 0.230912 0.991679 0.662447 0.991196
50 2015-09-08 0.060274 2015-12-08 3.8203 0.1413 1.026185 3.9306 0.21225 0.143741 3.2018 3.850967 0.224878 0.992050 0.644027 0.991679
51 2015-09-09 0.057534 2015-12-09 3.7792 0.1413 1.026723 3.8880 0.21568 0.143375 3.2018 3.807902 0.227996 0.992425 0.601550 0.991737
52 2015-09-10 0.054795 2015-12-10 3.8499 0.1413 1.027262 3.9612 0.22263 0.144082 3.2018 3.878328 0.240230 0.992783 0.671662 0.992491
53 2015-09-11 0.052055 2015-12-11 3.8735 0.1413 1.027801 3.9809 0.22525 0.143767 3.2018 3.895090 0.231317 0.993148 0.688544 0.993056
54 2015-09-14 0.043836 2015-12-14 3.8156 0.1413 1.028340 3.9255 0.22472 0.143350 3.2018 3.836852 0.232112 0.994228 0.631391 0.994139
55 2015-09-15 0.041096 2015-12-15 3.8625 0.1413 1.028880 3.9720 0.22165 0.143027 3.2018 3.882170 0.229658 0.994591 0.676691 0.994576
56 2015-09-16 0.038356 2015-12-16 3.8286 0.1413 1.029419 3.9381 0.21000 0.143311 3.2018 3.847341 0.211514 0.994954 0.642284 0.994950
57 2015-09-17 0.035616 2015-12-17 3.8986 0.1413 1.029960 4.0093 0.20685 0.143584 3.2018 3.916084 0.200782 0.995319 0.710940 0.995319
58 2015-09-18 0.032877 2015-12-18 3.9446 0.1413 1.030500 4.0546 0.22400 0.143972 3.2018 3.958505 0.223132 0.995681 0.753437 0.995681
59 2015-09-21 0.024658 2015-12-21 3.9851 0.1413 1.031040 4.0997 0.22555 0.144851 3.2018 3.997939 0.234086 0.996757 0.793558 0.996757
60 2015-09-22 0.021918 2015-12-22 4.0504 0.1413 1.031581 4.1627 0.23440 0.145234 3.2018 4.062556 0.246472 0.997121 0.858278 0.997121
61 2015-09-23 0.019178 2015-12-23 4.1790 0.1413 1.032123 4.2987 0.24125 0.147965 3.2018 4.188261 0.260199 0.997468 0.983963 0.997468
62 2015-09-24 0.016438 2015-12-24 3.9370 0.1413 1.032664 4.0489 0.25555 0.146035 3.2018 3.959720 0.273633 0.997846 0.756287 0.997846
63 2015-09-25 0.013699 2015-12-25 3.9765 0.1413 1.033206 4.0882 0.25478 0.146084 3.2018 3.981898 0.273967 0.998198 0.778692 0.998198
64 2015-09-28 0.005479 2015-12-28 4.1106 0.1413 1.033748 4.2492 0.25592 0.147988 3.2018 4.111907 0.285338 0.999280 0.909452 0.999280
65 2015-09-29 0.002740 2015-12-29 4.0608 0.1413 1.034290 4.1722 0.25642 0.148226 3.2018 4.067446 0.291607 0.999639 0.865334 0.999639
66 2015-09-30 0.000000 2015-12-30 3.9471 0.1413 1.034833 4.0563 0.25130 0.146139 3.2018 3.953664 0.279244 1.000000 0.751864 0.000000

67 rows × 15 columns

Definindo a função para cálculo do portfolio sem fazer o hedging:


In [675]:
def calc_portf_semhedge(start,months,usdbrl,cdi,fwd_tenor,vol_tenor,swpprecdi_tenor):

    #init data
    df=portf_initdf(start,months,usdbrl,cdi,fwd_tenor,vol_tenor,swpprecdi_tenor)

    #caixa do prêmio
    df['cfwprem']=-df['premium'][0]*df['cdiprod']

    #portfolio
    df['portf']=df['premium']+df['cfwprem']

    return df

a) O primeiro comprou uma opção de 1m e carregou sem hedge até o final.


In [689]:
#traderA=calc_portf_semhedge(start,1,usdbrl,cdi,fwd1m_on,vol1m_off,swpprecdi1m)
traderA=calc_portf_semhedge(start,1,usdbrl,cdi,fwd,vol,pre)
traderA


Out[689]:
Date t tenor usdbrl cdi cdiprod fwd_tenor vol_tenor pre_tenor strike fwd vol discount premium delta cfwprem portf
0 2015-06-30 0.082192 2015-07-30 3.1030 0.1364 1.000000 3.1364 0.16112 0.136743 3.1364 3.136400 0.16112 0.989521 0.057186 0.503877 -0.057186 0.000000
1 2015-07-01 0.079452 2015-08-01 3.1492 0.1364 1.000508 3.1824 0.16195 0.136777 3.1364 3.180258 0.16195 0.989868 0.081250 0.621812 -0.057215 0.024035
2 2015-07-02 0.076712 2015-08-02 3.0967 0.1364 1.001015 3.1300 0.15243 0.136766 3.1364 3.126777 0.15243 0.990217 0.047599 0.474705 -0.057244 -0.009646
3 2015-07-03 0.073973 2015-08-03 3.1341 0.1364 1.001523 3.1680 0.15010 0.136767 3.1364 3.163626 0.15010 0.990565 0.065434 0.586198 -0.057273 0.008161
4 2015-07-06 0.065753 2015-08-06 3.1376 0.1364 1.002032 3.1706 0.14202 0.136944 3.1364 3.163148 0.14202 0.991603 0.059864 0.594216 -0.057302 0.002562
5 2015-07-07 0.063014 2015-08-07 3.1863 0.1364 1.002540 3.2196 0.15350 0.137075 3.1364 3.211006 0.15350 0.991948 0.094129 0.729525 -0.057332 0.036798
6 2015-07-08 0.060274 2015-08-08 3.2353 0.1364 1.003049 3.2694 0.15923 0.137130 3.1364 3.259500 0.15923 0.992295 0.132786 0.835905 -0.057361 0.075426
7 2015-07-09 0.057534 2015-08-09 3.2130 0.1364 1.003558 3.2701 0.15930 0.137130 3.1364 3.251681 0.15930 0.992646 0.125632 0.826301 -0.057390 0.068242
8 2015-07-10 0.054795 2015-08-10 3.1599 0.1364 1.004067 3.1916 0.15640 0.137198 3.1364 3.180352 0.15640 0.992994 0.070895 0.650251 -0.057419 0.013476
9 2015-07-13 0.046575 2015-08-13 3.1344 0.1364 1.004577 3.1683 0.14915 0.137439 3.1364 3.152990 0.14915 0.994039 0.048923 0.568015 -0.057448 -0.008525
10 2015-07-14 0.043836 2015-08-14 3.1393 0.1364 1.005087 3.1736 0.15608 0.137670 3.1364 3.157003 0.15608 0.994385 0.051851 0.582491 -0.057477 -0.005627
11 2015-07-15 0.041096 2015-08-15 3.1401 0.1364 1.005597 3.1722 0.15410 0.137752 3.1364 3.155632 0.15410 0.994736 0.049310 0.580604 -0.057506 -0.008197
12 2015-07-16 0.038356 2015-08-16 3.1568 0.1364 1.006107 3.1898 0.14560 0.137580 3.1364 3.171703 0.14560 0.995090 0.055984 0.654687 -0.057536 -0.001552
13 2015-07-17 0.035616 2015-08-17 3.1881 0.1364 1.006618 3.2193 0.14782 0.137767 3.1364 3.201184 0.14782 0.995438 0.076375 0.768891 -0.057565 0.018810
14 2015-07-20 0.027397 2015-08-20 3.1958 0.1364 1.007129 3.2301 0.15885 0.137951 3.1364 3.206865 0.15885 0.996491 0.079437 0.801775 -0.057594 0.021843
15 2015-07-21 0.024658 2015-08-21 3.1716 0.1364 1.007640 3.2072 0.15795 0.138102 3.1364 3.181935 0.15795 0.996841 0.058974 0.721309 -0.057623 0.001351
16 2015-07-22 0.021918 2015-08-22 3.2231 0.1364 1.008151 3.2567 0.16525 0.138386 3.1364 3.231771 0.16525 0.997192 0.099247 0.889384 -0.057652 0.041594
17 2015-07-23 0.019178 2015-08-23 3.2854 0.1364 1.008663 3.3194 0.18170 0.138801 3.1364 3.293077 0.18170 0.997542 0.157101 0.972007 -0.057682 0.099420
18 2015-07-24 0.016438 2015-08-24 3.3554 0.1364 1.009175 3.3889 0.19095 0.139756 3.1364 3.361884 0.19095 0.997891 0.225062 0.995696 -0.057711 0.167351
19 2015-07-27 0.008219 2015-08-27 3.3637 0.1364 1.009687 3.3992 0.18790 0.140484 3.1364 3.367135 0.18790 0.998947 0.230493 0.998932 -0.057740 0.172752
20 2015-07-28 0.005479 2015-08-28 3.3567 0.1364 1.010200 3.3921 0.18635 0.140764 3.1364 3.358984 0.18635 0.999298 0.222428 0.999298 -0.057770 0.164658
21 2015-07-29 0.002740 2015-08-29 3.3314 0.1364 1.010712 3.3664 0.18557 0.140909 3.1364 3.332529 0.18557 0.999649 0.196060 0.999649 -0.057799 0.138261
22 2015-07-30 0.000000 2015-08-30 3.3713 0.1413 1.011225 3.4055 0.17230 0.144017 3.1364 3.371300 0.17230 1.000000 0.234900 0.000000 -0.057828 0.177072

b) O segundo comprou uma opção de 1m e fez o delta hedge até o final.

c) O terceiro comprou uma opção de 3m e carregou sem hedge até o final.


In [772]:
traderC=calc_portf_semhedge(start,3,usdbrl,cdi,fwd,vol,pre)
traderC


Out[772]:
Date t tenor usdbrl cdi cdiprod fwd_tenor vol_tenor pre_tenor strike fwd vol discount premium delta cfwprem portf
0 2015-06-30 0.252055 2015-09-30 3.1030 0.1364 1.000000 3.2018 0.15825 0.140176 3.2018 3.201800 0.158250 0.967475 0.098157 0.499066 -0.098157 0.000000
1 2015-07-01 0.249315 2015-10-01 3.1492 0.1364 1.000508 3.2487 0.15823 0.140454 3.2018 3.247613 0.158292 0.967777 0.122130 0.567873 -0.098207 0.023923
2 2015-07-02 0.246575 2015-10-02 3.0967 0.1364 1.001015 3.1941 0.15380 0.140722 3.2018 3.191998 0.153755 0.968084 0.089575 0.483276 -0.098257 -0.008682
3 2015-07-03 0.243836 2015-10-03 3.1341 0.1364 1.001523 3.2342 0.15417 0.140665 3.2018 3.230944 0.153972 0.968458 0.109241 0.544713 -0.098307 0.010935
4 2015-07-06 0.235616 2015-10-06 3.1376 0.1364 1.002032 3.2357 0.15392 0.140265 3.2018 3.229297 0.152791 0.969612 0.106171 0.543523 -0.098356 0.007814
5 2015-07-07 0.232877 2015-10-07 3.1863 0.1364 1.002540 3.2856 0.15743 0.140680 3.2018 3.278026 0.156984 0.969895 0.136453 0.617097 -0.098406 0.038047
6 2015-07-08 0.230137 2015-10-08 3.2353 0.1364 1.003049 3.3364 0.15997 0.139951 3.2018 3.327613 0.159873 0.970378 0.169928 0.684801 -0.098456 0.071472
7 2015-07-09 0.227397 2015-10-09 3.2130 0.1364 1.003558 3.3367 0.15920 0.140218 3.2018 3.326874 0.159215 0.970690 0.168618 0.685622 -0.098506 0.070111
8 2015-07-10 0.224658 2015-10-10 3.1599 0.1364 1.004067 3.2576 0.15942 0.139615 3.2018 3.246780 0.158929 0.971142 0.117527 0.571205 -0.098556 0.018971
9 2015-07-13 0.216438 2015-10-13 3.1344 0.1364 1.004577 3.2316 0.15977 0.139833 3.2018 3.218110 0.157567 0.972164 0.099386 0.527103 -0.098606 0.000780
10 2015-07-14 0.213699 2015-10-14 3.1393 0.1364 1.005087 3.2381 0.15542 0.139781 3.2018 3.223297 0.155572 0.972516 0.100458 0.536170 -0.098656 0.001802
11 2015-07-15 0.210959 2015-10-15 3.1401 0.1364 1.005597 3.1745 0.15542 0.139954 3.2018 3.173934 0.155096 0.972843 0.075225 0.452664 -0.098706 -0.023481
12 2015-07-16 0.208219 2015-10-16 3.1568 0.1364 1.006107 3.1805 0.15160 0.139842 3.2018 3.182939 0.150050 0.973220 0.075986 0.466409 -0.098756 -0.022770
13 2015-07-17 0.205479 2015-10-17 3.1881 0.1364 1.006618 3.2415 0.15273 0.140001 3.2018 3.235313 0.151378 0.973545 0.103059 0.558619 -0.098807 0.004252
14 2015-07-20 0.197260 2015-10-20 3.1958 0.1364 1.007129 3.2595 0.16070 0.138640 3.2018 3.249861 0.160096 0.974752 0.114551 0.581738 -0.098857 0.015694
15 2015-07-21 0.194521 2015-10-21 3.1716 0.1364 1.007640 3.2160 0.15847 0.139561 3.2018 3.212970 0.158291 0.974991 0.092633 0.520438 -0.098907 -0.006274
16 2015-07-22 0.191781 2015-10-22 3.2231 0.1364 1.008151 3.2715 0.16200 0.139508 3.2018 3.266162 0.163180 0.975332 0.124753 0.607954 -0.098957 0.025796
17 2015-07-23 0.189041 2015-10-23 3.2854 0.1364 1.008663 3.3265 0.17507 0.140139 3.2018 3.323823 0.177599 0.975594 0.168831 0.682435 -0.099007 0.069824
18 2015-07-24 0.186301 2015-10-24 3.3554 0.1364 1.009175 3.3860 0.17767 0.142377 3.2018 3.387141 0.183010 0.975670 0.216324 0.755111 -0.099058 0.117267
19 2015-07-27 0.178082 2015-10-27 3.3637 0.1364 1.009687 3.4663 0.17752 0.142248 3.2018 3.436600 0.182187 0.976713 0.253412 0.811846 -0.099108 0.154304
20 2015-07-28 0.175342 2015-10-28 3.3567 0.1364 1.010200 3.4590 0.17757 0.142376 3.2018 3.428292 0.181653 0.977041 0.246075 0.806563 -0.099158 0.146917
21 2015-07-29 0.172603 2015-10-29 3.3314 0.1364 1.010712 3.4343 0.17733 0.142402 3.2018 3.402020 0.181294 0.977388 0.224613 0.782281 -0.099208 0.125405
22 2015-07-30 0.169863 2015-10-30 3.3713 0.1413 1.011225 3.4735 0.17343 0.142111 3.2018 3.440057 0.172875 0.977545 0.251889 0.832405 -0.099259 0.152631
23 2015-07-31 0.167123 2015-10-31 3.4211 0.1413 1.011756 3.5248 0.17625 0.141749 3.2018 3.489379 0.176642 0.978119 0.294770 0.870647 -0.099311 0.195459
24 2015-08-03 0.158904 2015-11-03 3.4508 0.1413 1.012287 3.5546 0.17708 0.142143 3.2018 3.517200 0.181895 0.979155 0.319766 0.889630 -0.099363 0.220403
25 2015-08-04 0.156164 2015-11-04 3.4711 0.1413 1.012818 3.5716 0.17955 0.141984 3.2018 3.534764 0.183756 0.979515 0.335665 0.900225 -0.099415 0.236250
26 2015-08-05 0.153425 2015-11-05 3.4851 0.1413 1.013349 3.5863 0.18250 0.142088 3.2018 3.548234 0.184146 0.979868 0.347733 0.909231 -0.099467 0.248266
27 2015-08-06 0.150685 2015-11-06 3.5363 0.1413 1.013881 3.6372 0.18673 0.143160 3.2018 3.595954 0.188568 0.980147 0.392173 0.928853 -0.099519 0.292653
28 2015-08-07 0.147945 2015-11-07 3.5071 0.1413 1.014413 3.5665 0.18655 0.143662 3.2018 3.551113 0.187736 0.980465 0.350605 0.911079 -0.099572 0.251033
29 2015-08-10 0.139726 2015-11-10 3.4404 0.1413 1.014945 3.5215 0.18287 0.142568 3.2018 3.489641 0.182944 0.981618 0.293688 0.885421 -0.099624 0.194064
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
37 2015-08-20 0.112329 2015-11-20 3.4579 0.1413 1.019212 3.5600 0.18038 0.141680 3.2018 3.505739 0.183999 0.985245 0.305830 0.919604 -0.100043 0.205787
38 2015-08-21 0.109589 2015-11-21 3.4998 0.1413 1.019747 3.6006 0.18163 0.141795 3.2018 3.543144 0.185918 0.985601 0.340686 0.939474 -0.100095 0.240590
39 2015-08-24 0.101370 2015-11-24 3.5524 0.1413 1.020282 3.6555 0.18445 0.142106 3.2018 3.593648 0.193689 0.986659 0.389071 0.958522 -0.100148 0.288923
40 2015-08-25 0.098630 2015-11-25 3.6172 0.1413 1.020817 3.7187 0.18807 0.142140 3.2018 3.657926 0.197205 0.987017 0.451380 0.972630 -0.100200 0.351180
41 2015-08-26 0.095890 2015-11-26 3.5968 0.1413 1.021353 3.6983 0.19440 0.142023 3.2018 3.635787 0.208778 0.987386 0.430536 0.964841 -0.100253 0.330283
42 2015-08-27 0.093151 2015-11-27 3.5526 0.1413 1.021888 3.6558 0.18905 0.141900 3.2018 3.590003 0.196283 0.987744 0.385604 0.961890 -0.100305 0.285298
43 2015-08-28 0.090411 2015-11-28 3.5819 0.1413 1.022425 3.6847 0.19077 0.141934 3.2018 3.616318 0.196683 0.988107 0.411029 0.969934 -0.100358 0.310671
44 2015-08-31 0.082192 2015-11-30 3.6198 0.1413 1.022961 3.7245 0.19653 0.142797 3.2018 3.654500 0.208950 0.989161 0.448762 0.976673 -0.100411 0.348351
45 2015-09-01 0.079452 2015-12-01 3.6977 0.1413 1.023498 3.8040 0.20000 0.143122 3.2018 3.732852 0.212699 0.989523 0.525830 0.984769 -0.100463 0.425366
46 2015-09-02 0.076712 2015-12-02 3.7609 0.1413 1.024035 3.8679 0.20972 0.143128 3.2018 3.794985 0.222855 0.989883 0.587373 0.987230 -0.100516 0.486857
47 2015-09-03 0.073973 2015-12-03 3.7397 0.1413 1.024572 3.8458 0.20855 0.142535 3.2018 3.772462 0.216883 0.990266 0.565272 0.987813 -0.100569 0.464703
48 2015-09-04 0.071233 2015-12-04 3.8430 0.1413 1.025109 3.9516 0.21475 0.143942 3.2018 3.873387 0.224221 0.990592 0.665310 0.989939 -0.100622 0.564689
49 2015-09-07 0.063014 2015-12-07 3.8430 0.1413 1.025647 3.9516 0.21660 0.143942 3.2018 3.869777 0.230912 0.991679 0.662447 0.991196 -0.100674 0.561773
50 2015-09-08 0.060274 2015-12-08 3.8203 0.1413 1.026185 3.9306 0.21225 0.143741 3.2018 3.850967 0.224878 0.992050 0.644027 0.991679 -0.100727 0.543300
51 2015-09-09 0.057534 2015-12-09 3.7792 0.1413 1.026723 3.8880 0.21568 0.143375 3.2018 3.807902 0.227996 0.992425 0.601550 0.991737 -0.100780 0.500770
52 2015-09-10 0.054795 2015-12-10 3.8499 0.1413 1.027262 3.9612 0.22263 0.144082 3.2018 3.878328 0.240230 0.992783 0.671662 0.992491 -0.100833 0.570829
53 2015-09-11 0.052055 2015-12-11 3.8735 0.1413 1.027801 3.9809 0.22525 0.143767 3.2018 3.895090 0.231317 0.993148 0.688544 0.993056 -0.100886 0.587658
54 2015-09-14 0.043836 2015-12-14 3.8156 0.1413 1.028340 3.9255 0.22472 0.143350 3.2018 3.836852 0.232112 0.994228 0.631391 0.994139 -0.100939 0.530452
55 2015-09-15 0.041096 2015-12-15 3.8625 0.1413 1.028880 3.9720 0.22165 0.143027 3.2018 3.882170 0.229658 0.994591 0.676691 0.994576 -0.100992 0.575700
56 2015-09-16 0.038356 2015-12-16 3.8286 0.1413 1.029419 3.9381 0.21000 0.143311 3.2018 3.847341 0.211514 0.994954 0.642284 0.994950 -0.101045 0.541239
57 2015-09-17 0.035616 2015-12-17 3.8986 0.1413 1.029960 4.0093 0.20685 0.143584 3.2018 3.916084 0.200782 0.995319 0.710940 0.995319 -0.101098 0.609842
58 2015-09-18 0.032877 2015-12-18 3.9446 0.1413 1.030500 4.0546 0.22400 0.143972 3.2018 3.958505 0.223132 0.995681 0.753437 0.995681 -0.101151 0.652286
59 2015-09-21 0.024658 2015-12-21 3.9851 0.1413 1.031040 4.0997 0.22555 0.144851 3.2018 3.997939 0.234086 0.996757 0.793558 0.996757 -0.101204 0.692354
60 2015-09-22 0.021918 2015-12-22 4.0504 0.1413 1.031581 4.1627 0.23440 0.145234 3.2018 4.062556 0.246472 0.997121 0.858278 0.997121 -0.101257 0.757021
61 2015-09-23 0.019178 2015-12-23 4.1790 0.1413 1.032123 4.2987 0.24125 0.147965 3.2018 4.188261 0.260199 0.997468 0.983963 0.997468 -0.101310 0.882653
62 2015-09-24 0.016438 2015-12-24 3.9370 0.1413 1.032664 4.0489 0.25555 0.146035 3.2018 3.959720 0.273633 0.997846 0.756287 0.997846 -0.101363 0.654924
63 2015-09-25 0.013699 2015-12-25 3.9765 0.1413 1.033206 4.0882 0.25478 0.146084 3.2018 3.981898 0.273967 0.998198 0.778692 0.998198 -0.101416 0.677276
64 2015-09-28 0.005479 2015-12-28 4.1106 0.1413 1.033748 4.2492 0.25592 0.147988 3.2018 4.111907 0.285338 0.999280 0.909452 0.999280 -0.101470 0.807982
65 2015-09-29 0.002740 2015-12-29 4.0608 0.1413 1.034290 4.1722 0.25642 0.148226 3.2018 4.067446 0.291607 0.999639 0.865334 0.999639 -0.101523 0.763811
66 2015-09-30 0.000000 2015-12-30 3.9471 0.1413 1.034833 4.0563 0.25130 0.146139 3.2018 3.953664 0.279244 1.000000 0.751864 0.000000 -0.101576 0.650288

67 rows × 17 columns

d) O quarto comprou uma opção de 3m e fez o delta hedge até o final.

e) O quinto comprou uma opção de 12m e carregou sem hedge até o final.


In [776]:
traderE=calc_portf_semhedge(start,12,usdbrl,cdi,fwd,vol,pre)
traderE


Out[776]:
Date t tenor usdbrl cdi cdiprod fwd_tenor vol_tenor pre_tenor strike fwd vol discount premium delta cfwprem portf
0 2015-06-30 1.002740 2016-06-30 3.1030 0.1364 1.000000 3.4828 0.15985 0.142825 3.4828 3.482800 0.159850 0.874705 0.194332 0.465251 -0.194332 0.000000
1 2015-07-01 1.000000 2016-07-01 3.1492 0.1364 1.000508 3.5312 0.15985 0.143122 3.4828 3.530169 0.159844 0.874805 0.216817 0.494533 -0.194430 0.022386
2 2015-07-02 0.997260 2016-07-02 3.0967 0.1364 1.001015 3.4672 0.15865 0.141529 3.4828 3.465207 0.158615 0.876340 0.184569 0.454675 -0.194529 -0.009960
3 2015-07-03 0.994521 2016-07-03 3.1341 0.1364 1.001523 3.5058 0.15955 0.141051 3.4828 3.502826 0.159492 0.877022 0.203079 0.478859 -0.194628 0.008451
4 2015-07-06 0.986301 2016-07-06 3.1376 0.1364 1.002032 3.5085 0.15832 0.141249 3.4828 3.502526 0.158225 0.877837 0.200788 0.478933 -0.194726 0.006061
5 2015-07-07 0.983562 2016-07-07 3.1863 0.1364 1.002540 3.5618 0.16100 0.141015 3.4828 3.554744 0.160910 0.878322 0.229755 0.511493 -0.194825 0.034929
6 2015-07-08 0.980822 2016-07-08 3.2353 0.1364 1.003049 3.6156 0.16275 0.140553 3.4828 3.607448 0.162670 0.878995 0.259578 0.542746 -0.194924 0.064654
7 2015-07-09 0.978082 2016-07-09 3.2130 0.1364 1.003558 3.6159 0.16193 0.140553 3.4828 3.606729 0.161841 0.879307 0.258016 0.542824 -0.195023 0.062993
8 2015-07-10 0.975342 2016-07-10 3.1599 0.1364 1.004067 3.5281 0.16257 0.139290 3.4828 3.518228 0.162456 0.880558 0.213072 0.490448 -0.195122 0.017950
9 2015-07-13 0.967123 2016-07-13 3.1344 0.1364 1.004577 3.5031 0.16270 0.139563 3.4828 3.490219 0.162562 0.881297 0.199045 0.473384 -0.195221 0.003824
10 2015-07-14 0.964384 2016-07-14 3.1393 0.1364 1.005087 3.5093 0.16010 0.139625 3.4828 3.495443 0.159864 0.881570 0.198072 0.476448 -0.195320 0.002752
11 2015-07-15 0.961644 2016-07-15 3.1401 0.1364 1.005597 3.5076 0.16035 0.139301 3.4828 3.489365 0.160084 0.882106 0.195297 0.472853 -0.195419 -0.000122
12 2015-07-16 0.958904 2016-07-16 3.1568 0.1364 1.006107 3.5265 0.15835 0.139137 3.4828 3.506296 0.157964 0.882539 0.200676 0.483701 -0.195518 0.005157
13 2015-07-17 0.956164 2016-07-17 3.1881 0.1364 1.006618 3.5585 0.15855 0.138820 3.4828 3.538832 0.158195 0.883066 0.216888 0.504785 -0.195618 0.021271
14 2015-07-20 0.947945 2016-07-20 3.1958 0.1364 1.007129 3.5623 0.16300 0.137425 3.4828 3.540198 0.162833 0.885026 0.222793 0.506549 -0.195717 0.027077
15 2015-07-21 0.945205 2016-07-21 3.1716 0.1364 1.007640 3.5659 0.16278 0.137716 3.4828 3.539083 0.162454 0.885086 0.221509 0.505923 -0.195816 0.025692
16 2015-07-22 0.942466 2016-07-22 3.2231 0.1364 1.008151 3.5880 0.16380 0.137789 3.4828 3.562588 0.163656 0.885348 0.234792 0.520447 -0.195916 0.038876
17 2015-07-23 0.939726 2016-07-23 3.2854 0.1364 1.008663 3.6583 0.16632 0.140318 3.4828 3.630448 0.167072 0.883927 0.274776 0.558703 -0.196015 0.078761
18 2015-07-24 0.936986 2016-07-24 3.3554 0.1364 1.009175 3.7358 0.16963 0.142785 3.4828 3.705161 0.170349 0.882472 0.320986 0.596943 -0.196115 0.124871
19 2015-07-27 0.928767 2016-07-27 3.3637 0.1364 1.009687 3.7504 0.16930 0.142771 3.4828 3.722405 0.170127 0.883461 0.330634 0.607067 -0.196214 0.134420
20 2015-07-28 0.926027 2016-07-28 3.3567 0.1364 1.010200 3.7422 0.17040 0.142652 3.4828 3.713260 0.171146 0.883853 0.326113 0.602186 -0.196314 0.129799
21 2015-07-29 0.923288 2016-07-29 3.3314 0.1364 1.010712 3.7139 0.17278 0.142698 3.4828 3.684307 0.173267 0.884145 0.311131 0.586323 -0.196413 0.114718
22 2015-07-30 0.920548 2016-07-30 3.3713 0.1413 1.011225 3.7709 0.16828 0.139947 3.4828 3.738338 0.168851 0.886241 0.339185 0.618410 -0.196513 0.142672
23 2015-07-31 0.917808 2016-07-31 3.4211 0.1413 1.011756 3.8343 0.16972 0.139508 3.4828 3.799284 0.170471 0.886861 0.379522 0.647822 -0.196616 0.182905
24 2015-08-03 0.909589 2016-08-03 3.4508 0.1413 1.012287 3.8372 0.17123 0.140070 3.4828 3.802133 0.171966 0.887415 0.382378 0.649007 -0.196719 0.185659
25 2015-08-04 0.906849 2016-08-04 3.4711 0.1413 1.012818 3.8500 0.17380 0.140785 3.4828 3.814438 0.174545 0.887303 0.392790 0.652842 -0.196822 0.195968
26 2015-08-05 0.904110 2016-08-05 3.4851 0.1413 1.013349 3.8623 0.17472 0.141249 3.4828 3.826037 0.175762 0.887327 0.401399 0.657380 -0.196926 0.204473
27 2015-08-06 0.901370 2016-08-06 3.5363 0.1413 1.013881 3.9131 0.17995 0.144636 3.4828 3.875843 0.180880 0.885497 0.438671 0.673586 -0.197029 0.241642
28 2015-08-07 0.898630 2016-08-07 3.5071 0.1413 1.014413 3.8983 0.18055 0.145493 3.4828 3.852284 0.181394 0.885267 0.423052 0.663348 -0.197132 0.225920
29 2015-08-10 0.890411 2016-08-10 3.4404 0.1413 1.014945 3.8221 0.17905 0.143852 3.4828 3.777120 0.179627 0.887344 0.372504 0.633038 -0.197236 0.175268
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
227 2016-05-12 0.134247 2017-05-12 3.4848 0.1413 1.126035 3.8429 0.18003 0.131601 3.4828 3.539517 0.179532 0.982377 0.121074 0.598927 -0.218824 -0.097750
228 2016-05-13 0.131507 2017-05-13 3.5324 0.1413 1.126626 3.8976 0.17925 0.131637 3.4828 3.587451 0.178867 0.982720 0.150502 0.675647 -0.218939 -0.068437
229 2016-05-16 0.123288 2017-05-16 3.4992 0.1413 1.127217 3.8637 0.17958 0.131801 3.4828 3.552374 0.177398 0.983760 0.124496 0.626006 -0.219054 -0.094558
230 2016-05-17 0.120548 2017-05-17 3.4883 0.1413 1.127809 3.8497 0.17720 0.132358 3.4828 3.540693 0.174669 0.984133 0.115159 0.608920 -0.219169 -0.104010
231 2016-05-18 0.117808 2017-05-18 3.5682 0.1413 1.128400 3.9316 0.17757 0.133065 3.4828 3.616087 0.177723 0.984495 0.166253 0.729427 -0.219284 -0.053031
232 2016-05-19 0.115068 2017-05-19 3.5650 0.1413 1.128992 3.9356 0.17943 0.132320 3.4828 3.611417 0.180104 0.984836 0.163028 0.722597 -0.219399 -0.056371
233 2016-05-20 0.112329 2017-05-20 3.5203 0.1413 1.129585 3.8765 0.17697 0.132440 3.4828 3.568522 0.177243 0.985193 0.131328 0.659760 -0.219514 -0.088186
234 2016-05-23 0.104110 2017-05-23 3.5726 0.1413 1.130177 3.9296 0.18127 0.132756 3.4828 3.618651 0.181905 0.986254 0.165802 0.741816 -0.219629 -0.053827
235 2016-05-24 0.101370 2017-05-24 3.5715 0.1413 1.130770 3.9273 0.18240 0.132467 3.4828 3.614799 0.182760 0.986606 0.162438 0.738038 -0.219744 -0.057306
236 2016-05-25 0.098630 2017-05-25 3.5831 0.1413 1.131363 3.9355 0.18265 0.132828 3.4828 3.623010 0.183373 0.986999 0.167952 0.752519 -0.219860 -0.051908
237 2016-05-26 0.095890 2017-05-26 3.5831 0.1413 1.131957 3.9363 0.18278 0.132582 3.4828 3.622498 0.183493 0.987351 0.166778 0.754734 -0.219975 -0.053197
238 2016-05-27 0.093151 2017-05-27 3.6083 0.1413 1.132551 3.9631 0.18200 0.133210 3.4828 3.643255 0.181272 0.987696 0.181297 0.790198 -0.220090 -0.038793
239 2016-05-30 0.084932 2017-05-30 3.5704 0.1413 1.133145 3.9219 0.18270 0.131881 3.4828 3.608576 0.181904 0.988766 0.152320 0.748198 -0.220206 -0.067886
240 2016-05-31 0.082192 2017-05-31 3.6109 0.1413 1.133739 3.9663 0.18642 0.131995 3.4828 3.647866 0.187438 0.989113 0.183664 0.804036 -0.220321 -0.036657
241 2016-06-01 0.079452 2017-06-01 3.6003 0.1413 1.134334 3.9627 0.18465 0.130806 3.4828 3.634700 0.184995 0.989460 0.171644 0.792434 -0.220437 -0.048793
242 2016-06-02 0.076712 2017-06-02 3.5945 0.1413 1.134929 3.9527 0.18160 0.130514 3.4828 3.627921 0.176872 0.989818 0.163169 0.796313 -0.220553 -0.057383
243 2016-06-03 0.073973 2017-06-03 3.5275 0.1413 1.135524 3.8771 0.18005 0.129938 3.4828 3.561138 0.175333 0.990184 0.112211 0.681284 -0.220668 -0.108458
244 2016-06-06 0.065753 2017-06-06 3.4890 0.1413 1.136120 3.8353 0.18022 0.129663 3.4828 3.523529 0.174618 0.991259 0.084291 0.605703 -0.220784 -0.136493
245 2016-06-07 0.063014 2017-06-07 3.4410 0.1413 1.136716 3.7782 0.18180 0.130401 3.4828 3.475286 0.174212 0.991631 0.056532 0.484928 -0.220900 -0.164368
246 2016-06-08 0.060274 2017-06-08 3.3611 0.1413 1.137313 3.6837 0.18140 0.129690 3.4828 3.387438 0.177849 0.991993 0.023661 0.267449 -0.221016 -0.197355
247 2016-06-09 0.057534 2017-06-09 3.3998 0.1413 1.137909 3.7366 0.18377 0.130623 3.4828 3.425488 0.183682 0.992329 0.036027 0.358681 -0.221132 -0.185104
248 2016-06-10 0.054795 2017-06-10 3.4327 0.1413 1.138506 3.7538 0.18855 0.131515 3.4828 3.440899 0.191175 0.992699 0.042780 0.399094 -0.221248 -0.178467
249 2016-06-13 0.046575 2017-06-13 3.4821 0.1413 1.139103 3.8173 0.18823 0.131234 3.4828 3.503590 0.193213 0.993789 0.068662 0.561460 -0.221364 -0.152702
250 2016-06-14 0.043836 2017-06-14 3.4815 0.1413 1.139701 3.8157 0.18730 0.131783 3.4828 3.501216 0.190936 0.994150 0.064997 0.557094 -0.221480 -0.156483
251 2016-06-15 0.041096 2017-06-15 3.4746 0.1413 1.140299 3.8055 0.18690 0.132010 3.4828 3.488705 0.189205 0.994517 0.056031 0.522374 -0.221596 -0.165565
252 2016-06-16 0.038356 2017-06-16 3.4660 0.1413 1.140897 3.8036 0.18660 0.132341 3.4828 3.481400 0.190231 0.994886 0.050794 0.500553 -0.221712 -0.170919
253 2016-06-17 0.035616 2017-06-17 3.4167 0.1413 1.141496 3.7476 0.18555 0.132722 3.4828 3.442018 0.185163 0.995243 0.030446 0.372854 -0.221829 -0.191383
254 2016-06-20 0.027397 2017-06-20 3.3948 0.1413 1.142095 3.7183 0.18340 0.132727 3.4828 3.407512 0.181773 0.996343 0.014107 0.237573 -0.221945 -0.207838
255 2016-06-21 0.024658 2017-06-21 3.4142 0.1413 1.142694 3.7314 0.18560 0.131668 3.4828 3.431082 0.188464 0.996702 0.019993 0.310776 -0.222061 -0.202068
256 2016-06-22 0.021918 2017-06-22 3.3775 0.1413 1.143293 3.6928 0.18545 0.131949 3.4828 3.387585 0.187866 0.997069 0.007987 0.162392 -0.222178 -0.214191

257 rows × 17 columns

Questão 4


a) Monte Carlo

b) PDE

implementação sugerida


In [ ]:
def grid(N,T,Nj,S,dx,vol,r,q,K,output='V'):
    dt = T / N
    if dx < vol * np.sqrt(3 * dt):
        print('Convergence error')
    mu = -(0.5)*(r-q)*vol**2
    emdx = np.exp(-dx)
    ppu = 0.5 * dt * ((vol / dx) ** 2 + mu / dx)
    ppm = 1.0-dt * (vol / dx) ** 2-r * dt
    ppd = 0.5 * dt * ((vol / dx) ** 2-mu / dx)
    St = np.full(2 * Nj + 1,0.)
    St[0] = S * np.exp(Nj * dx)
    for j in np.arange(1,2 * Nj + 1):
        St[j] = St[j-1]*emdx
    Ct = np.full((2 * Nj + 1,N + 1),np.nan)
    for j in np.arange(0,2 * Nj + 1):
        Ct[j,N] = np.max([St[j]-K,0])
    for i in np.arange(N-1,-1,-1):
        for k in np.arange(N-i,2 * Nj + 1-(N-i)):
            Ct[k,i] = ppu * Ct[k-1,i + 1]+ ppm * Ct[k,i + 1] + ppd * Ct[k + 1,i + 1]
        #Boundary
    #Boundary
    if output == 'G':
        return Ct
    else:
        return Ct[Nj,0]

In [ ]: