44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
import os
|
|
import pandas as pd
|
|
import pytest
|
|
from pandas.testing import assert_series_equal
|
|
|
|
from . import var
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"prices, horizon, ascending, expected",
|
|
[
|
|
(
|
|
pd.DataFrame([1, 2, 3, 4, 5]),
|
|
1,
|
|
"ascending",
|
|
pd.Series([1.0, 0.5, 0.33333, 0.25], dtype=float),
|
|
)
|
|
],
|
|
)
|
|
def test_calculate_returns(prices, horizon, ascending, expected):
|
|
assert_series_equal(
|
|
var.calculate_returns(prices, horizon, ascending),
|
|
expected,
|
|
# rtol=0.01,
|
|
# check_names=False,
|
|
# check_exact=False,
|
|
)
|
|
|
|
|
|
def test_var():
|
|
pass
|
|
|
|
|
|
def test_end_to_end():
|
|
portfolio = pd.DataFrame([{"ccy-1": 153084.81, "ccy-2": 95891.51}])
|
|
fx_prices = pd.read_csv(
|
|
os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "var_fx_prices.csv"),
|
|
parse_dates=["date"],
|
|
index_col="date",
|
|
dtype=float, # All non-date columns as float
|
|
)
|
|
fx_prices.sort_index(inplace=True, ascending=True)
|
|
assert var.var(portfolio, fx_prices) == pytest.approx(-13572.73)
|