diff --git a/src/var.py b/src/var.py index 56d6909..6153d1b 100644 --- a/src/var.py +++ b/src/var.py @@ -17,4 +17,4 @@ def var(portfolio, prices, sort="ascending"): pnl = portfolio.dot(returns.T) daily_pnl = pnl.sum(axis=0) daily_pnl_asc = daily_pnl.sort_values(ascending=True) - return 0.4 * daily_pnl_asc[1] + 0.6 * daily_pnl_asc[2] + return 0.4 * daily_pnl_asc.iloc[1] + 0.6 * daily_pnl_asc.iloc[2] diff --git a/src/var_test.py b/src/var_test.py index e339d88..d69dde0 100644 --- a/src/var_test.py +++ b/src/var_test.py @@ -25,8 +25,8 @@ def test_calculate_returns(prices, horizon, ascending, expected): @pytest.mark.parametrize( "portfolio, prices, expected", [ - ({"FX-1": [100.00]}, {"FX-1": [1, 1.1, 0.9, 0.8]}, -6.909090), - ({"FX-1": [100.00]}, {"FX-1": [1, 0.9, 0.8, 0.8]}, -10.66666), + ({"FX-1": [100.00]}, {"FX-1": [1, 1.1, 1.0, 0.9, 0.8]}, -9.454545), + ({"FX-1": [100.00]}, {"FX-1": [1, 0.9, 1.0, 0.8, 0.8]}, -4.0), ], ) def test_var(portfolio, prices, expected): @@ -39,6 +39,7 @@ def test_end_to_end(): os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "var_fx_prices.csv"), parse_dates=["date"], index_col="date", + dayfirst=True, dtype=float, ) fx_prices.sort_index(inplace=True, ascending=True)