def test_performance(client, data): d = post(client=client, data=data, url="/engine/performance").data.decode() x = pd.read_json(d, typ="series") assert x.to_dict() == { 'Return': '-28.27%', '# Events': '602', '# Events per year': '261', 'Annua Return': '-14.40%', 'Annua Volatility': '18.01%', 'Annua Sharpe Ratio (r_f = 0)': '-0.80', 'Max Drawdown': '32.61%', 'Max % return': '4.07%', 'Min % return': '-9.11%', 'MTD': '1.43%', 'YTD': '1.33%', 'Current Nav': '1200.59', 'Max Nav': '1692.70', 'Current Drawdown': '29.07%', 'Calmar Ratio (3Y)': '-0.44', '# Positive Events': '286', '# Negative Events': '316', 'Value at Risk (alpha = 95)': '1.91%', 'Conditional Value at Risk (alpha = 95)': '2.76%', 'First at': '2013-01-01', 'Last at': '2015-04-22', 'Kurtosis': '8.75' }
def test_volatility(client, data, price): d = json.loads( post(client=client, data=data, url="/engine/volatility").data.decode()) x = parse(d) pt.assert_series_equal(from_nav(price).ewm_volatility().dropna(), x, check_names=False)
def test_month(client, data, price): d = post(client=client, data=data, url="/engine/month").data.decode() x = pd.read_json(d, orient="table") pt.assert_frame_equal( x, from_nav(price).monthlytable.applymap( lambda x: "{0:.2f}%".format(float(100.0 * x)).replace("nan%", "")), check_names=False)
def test_post(client): data = post(client, url="/post", data={}).data assert data.decode() == "Hello Thomas!"
def test_drawdown(client, data, price): d = json.loads( post(client=client, data=data, url="/engine/drawdown").data.decode()) x = parse(d) pt.assert_series_equal(from_nav(price).drawdown, x, check_names=False)