9
9
from financetoolkit .portfolio .overview_model import (
10
10
create_portfolio_overview ,
11
11
create_profit_and_loss_overview ,
12
- create_transactions_overview ,
13
12
)
14
13
15
14
@@ -59,43 +58,9 @@ def sample_betas():
59
58
return pd .Series ([1.2 , 0.8 , 1.5 ], index = ["AAPL" , "MSFT" , "AMZN" ])
60
59
61
60
62
- def test_create_transactions_overview ():
63
- """Test create_transactions_overview function"""
64
- portfolio_volume = pd .Series ([100 , 50 , 200 ], index = ["AAPL" , "MSFT" , "AMZN" ])
65
- portfolio_price = pd .Series ([150.0 , 250.0 , 100.0 ], index = ["AAPL" , "MSFT" , "AMZN" ])
66
- portfolio_costs = pd .Series ([1.0 , 2.0 , 3.0 ], index = ["AAPL" , "MSFT" , "AMZN" ])
67
- latest_returns = pd .Series ([160.0 , 255.0 , 110.0 ], index = ["AAPL" , "MSFT" , "AMZN" ])
68
-
69
- result = create_transactions_overview (
70
- portfolio_volume = portfolio_volume ,
71
- portfolio_price = portfolio_price ,
72
- portfolio_costs = portfolio_costs ,
73
- latest_returns = latest_returns ,
74
- )
75
-
76
- assert isinstance (result , pd .DataFrame )
77
- assert len (result ) == 3
78
- assert "Invested Amount" in result .columns
79
- assert "Current Value" in result .columns
80
- assert "% Return" in result .columns
81
- assert "Return" in result .columns
82
-
83
- # Check calculations
84
- expected_invested = portfolio_volume * portfolio_price + abs (portfolio_costs )
85
- expected_current = portfolio_volume * latest_returns
86
- expected_return_pct = (expected_current / expected_invested ) - 1
87
-
88
- pd .testing .assert_series_equal (
89
- result ["Invested Amount" ], expected_invested , check_names = False
90
- )
91
- pd .testing .assert_series_equal (
92
- result ["Current Value" ], expected_current , check_names = False
93
- )
94
- pd .testing .assert_series_equal (
95
- result ["% Return" ], expected_return_pct , check_names = False
96
- )
97
-
98
-
61
+ @pytest .mark .filterwarnings (
62
+ "ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning"
63
+ )
99
64
def test_create_profit_and_loss_overview ():
100
65
"""Test create_profit_and_loss_overview function"""
101
66
transactions_overview = pd .DataFrame (
@@ -122,6 +87,9 @@ def test_create_profit_and_loss_overview():
122
87
assert "Cumulative PnL" in result .columns
123
88
124
89
90
+ @pytest .mark .filterwarnings (
91
+ "ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning"
92
+ )
125
93
def test_create_profit_and_loss_overview_lifo ():
126
94
"""Test create_profit_and_loss_overview with LIFO method"""
127
95
transactions_overview = pd .DataFrame (
@@ -148,6 +116,9 @@ def test_create_profit_and_loss_overview_lifo():
148
116
assert "Cumulative PnL" in result .columns
149
117
150
118
119
+ @pytest .mark .filterwarnings (
120
+ "ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning"
121
+ )
151
122
def test_create_profit_and_loss_overview_average ():
152
123
"""Test create_profit_and_loss_overview with AVERAGE method"""
153
124
transactions_overview = pd .DataFrame (
@@ -202,24 +173,3 @@ def test_create_portfolio_overview_with_missing_data():
202
173
betas = betas ,
203
174
include_portfolio = True ,
204
175
)
205
-
206
-
207
- def test_create_transactions_overview_with_negative_costs ():
208
- """Test create_transactions_overview with negative costs"""
209
- portfolio_volume = pd .Series ([100 , 50 ], index = ["AAPL" , "MSFT" ])
210
- portfolio_price = pd .Series ([150.0 , 250.0 ], index = ["AAPL" , "MSFT" ])
211
- portfolio_costs = pd .Series ([- 1.0 , - 2.0 ], index = ["AAPL" , "MSFT" ]) # Negative costs
212
- latest_returns = pd .Series ([160.0 , 255.0 ], index = ["AAPL" , "MSFT" ])
213
-
214
- result = create_transactions_overview (
215
- portfolio_volume = portfolio_volume ,
216
- portfolio_price = portfolio_price ,
217
- portfolio_costs = portfolio_costs ,
218
- latest_returns = latest_returns ,
219
- )
220
-
221
- # Should handle negative costs by taking absolute value
222
- assert result .loc ["AAPL" , "Invested Amount" ] == 100 * 150.0 + 1.0 # abs(-1.0)
223
- assert result .loc ["MSFT" , "Invested Amount" ] == 50 * 250.0 + 2.0 # abs(-2.0)
224
-
225
- assert result .loc ["MSFT" , "Invested Amount" ] == 50 * 250.0 + 2.0 # abs(-2.0)
0 commit comments