% pylab inline
Populating the interactive namespace from numpy and matplotlib
import numpy as np
import pandas as pd
from datetime import datetime
start_date = datetime(2015, 7, 1)
end_date = datetime(2016, 7, 1)
dates = pd.date_range(start_date, end_date)
max_inventory = pd.TimeSeries(3640, index=dates)
max_inventory[10:] = 3200
min_inventory = pd.TimeSeries(0, index=dates)
min_inventory[10:] = 200
with_rate = pd.Series([2, 4, 8, 15, 23, 30, 35, 38, 40, 42, 43, 43],
index=[0, 1300, 1550, 2000, 2150, 2550, 2800, 3100, 3150, 3200, 3350, 3600])
inj_rate = pd.Series([27, 26, 25, 24, 23, 22, 21, 20, 17, 11, 10, 5],
index=[0, 1300, 1550, 2000, 2150, 2550, 2800, 3100, 3150, 3200, 3350, 3600])
wth_rate_constraints = pd.DataFrame({'min': pd.Series(2, index=dates),
'max': pd.Series(45, index=dates),
})
inj_rate_constraints = pd.DataFrame({'min': pd.Series(2, index=dates),
'max': pd.Series(26, index=dates),
})
storage_params = {'name': 'TestStorage',
'start_inventory': 2500,
'max_inventory': max_inventory,
'min_inventory': min_inventory,
'with_rate': with_rate,
'inj_rate': inj_rate,
'inj_cost': 0,
'with_cost': 0,
'end_inventory': 2500,
'storage_start_date': start_date,
'storage_end_date': end_date,
'wth_rate_constraints': wth_rate_constraints,
'inj_rate_constraints': inj_rate_constraints,
}
import btglib.quant.models.storage as sc
storage = sc.Storage(storage_params)
curve = 20*pd.Series(np.sin(np.linspace(0,10,len(dates))/1.5-0.5), index=dates)+40
storage.optimize(curve, curve)
storage.plot();
curve = 20*pd.Series(np.sin(np.linspace(0,10,len(dates))/1.5+1), index=dates)+40
storage.optimize(curve, curve)
storage.plot();
The optimal strategy depends on the gas price curve
...which we don't know...
...so we generate scenarios
from btglib.quant.models.simulator import Simulator
model_parameters = {'distribution': 'LogNormal',
'volatility': np.array([0.1]*len(dates))[:,None],
'correlation': np.eye(1),
'names': ['gas'],
}
simulator = Simulator('5-Jun-2015', dates, curve[:,None], model_parameters)
sims = simulator.generate_paths(100)
plt.plot(sims.ix[0,:,:], color='k', alpha=0.1);
plt.plot(curve, color='r', linewidth=2);
trades = pd.DataFrame({'Product': ['WkEnd 04/07-05/', 'Q315', 'Aug 15'],
'Market': ['Germany Baseload', 'Germany Peaks', 'Germany Baseload'],
'Volume': [50, -10, 20]})
trades
Market | Product | Volume | |
---|---|---|---|
0 | Germany Baseload | WkEnd 04/07-05/ | 50 |
1 | Germany Peaks | Q315 | -10 |
2 | Germany Baseload | Aug 15 | 20 |
from btglib.utils import parse_traded_product
schedules = [parse_traded_product(p, m, datetime.now(), v) for p,m,v in trades[['Product','Market','Volume']].values]
position = pd.concat(schedules, axis=1).sum(axis=1)
position.plot();
re
pandas
reportlab
pyxll
All of these require an implied volatility surface
from IPython.display import HTML
HTML('<iframe src=http://data.theice.com/MyAccount/Login.aspx?ReturnUrl=~\ViewData\Default.aspx width=1060 height=550></iframe>')
requests
for simple web pagesselenium
when we need to drive a web browser to navigate to the dataBeautifulSoup
to parse the datafrom IPython.display import HTML
HTML('<iframe src=https://plot.ly/~tbaeva/98/vol-surface-25-feb-2015/ width=960 height=700></iframe>')
reportlab
and saved as pdfsmtplib
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
last_message = inbox.Items.GetLast()
print last_message.sender()
print last_message.subject
Yves Hilpisch RE: OSQF Conference in Frankfurt 05.06.2015
pyxll
(Tony Roberts)flask
and jinja
bokeh
reportlab