aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration/curve_trades.py
blob: f4144551eff05e236fc7fb74677b897bc8d393f3 (plain)
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
from index_data import get_index_quotes, index_returns
import pandas as pd
import math

## look at spreads
df = get_index_quotes("IG", [23, 24, 25, 26, 27], tenor=['3yr', '5yr', '7yr', '10yr'])
spreads = df.groupby(level=['date', 'tenor']).nth(-1)['closespread'].unstack(-1)
# remove 'yr'
spreads.columns = [int(col[:-2]) for col in spreads.columns]
spreads = spreads.sort_index(1)
spreads_diff = spreads.diff(axis=1)
spreads_diff = spreads_diff.filter([5, 7, 10])
spreads_diff.columns = ['3-5', '5-7', '7-10']
spreads_diff.plot()

## look at returns
df = index_returns(index='IG', series=[24, 25, 26, 27, 28], tenor=['3yr', '5yr', '7yr', '10yr'])
## on-the-run returns
returns = df.price_return.unstack(-1).dropna().groupby(level='date').nth(-1)
strategy510 = returns['5yr'] - 0.56 * returns['10yr']
strategy710 = returns['7yr'] - 0.75 * returns['10yr']
strategy3510 = -2*returns['3yr']+3*returns['5yr'] - returns['10yr']
monthly_returns510 = strategy510.groupby(pd.TimeGrouper(freq='M')).agg(lambda df:(1+df).prod()-1)
monthly_returns710 = strategy710.groupby(pd.TimeGrouper(freq='M')).agg(lambda df:(1+df).prod()-1)

sharpe510 = strategy510.mean()/strategy510.std()*math.sqrt(252)
sharpe710 = strategy710.mean()/strategy710.std()*math.sqrt(252)
sharpe3510 = strategy3510.mean()/strategy3510.std()*math.sqrt(252)