@@ -282,9 +282,15 @@ def toolkit(self) -> Toolkit:
282
282
283
283
if self ._weekly_historical_data .empty :
284
284
self .collect_historical_data ()
285
+
286
+ if self ._daily_historical_data .empty :
287
+ return pd .DataFrame ()
285
288
if self ._weekly_benchmark_data .empty :
286
289
self .collect_benchmark_historical_data ()
287
290
291
+ if self ._daily_historical_data .empty :
292
+ return pd .DataFrame ()
293
+
288
294
symbols = list (self ._tickers ) + ["Portfolio" ] # type: ignore
289
295
290
296
historical_columns = self ._daily_historical_data .columns .get_level_values (
@@ -609,6 +615,9 @@ def collect_benchmark_historical_data(
609
615
if self ._weekly_historical_data .empty :
610
616
self .collect_historical_data ()
611
617
618
+ if self ._daily_historical_data .empty :
619
+ return pd .DataFrame ()
620
+
612
621
benchmark_ticker = (
613
622
benchmark_ticker
614
623
if benchmark_ticker
@@ -793,41 +802,38 @@ def collect_historical_data(
793
802
period = "daily" , progress_bar = progress_bar
794
803
)
795
804
796
- if self ._daily_historical_data .empty :
797
- api_key_check = (
798
- "\n Consider obtaining an API key from FinancialModelingPrep to potentially "
799
- "avoid this issue. You can get 15% "
800
- "off by using the following affiliate link which also supports the project: "
801
- "https://www.jeroenbouma.com/fmp"
802
- if not self ._api_key
803
- else ""
804
- )
805
- raise ValueError (
806
- "No historical data found for the provided tickers and therefore no further calculations are possible."
807
- + api_key_check
805
+ if self ._daily_historical_data .empty and not self ._api_key :
806
+ logger .error (
807
+ "Failed to collect historical data. Please ensure you have provided valid tickers. "
808
+ "Yahoo Finance is unstable and has rate limits which you could have reached.\n "
809
+ "Therefore, consider obtaining an API key with the following link: "
810
+ "https://www.jeroenbouma.com/fmp. You can get 15% off by using the "
811
+ "affiliate link which also supports the project."
808
812
)
813
+ return pd .DataFrame ()
809
814
810
815
self ._daily_historical_data = self ._daily_historical_data .rename (
811
816
columns = self ._ticker_combinations , level = 1
812
817
)
813
818
814
819
currency_conversions = {}
815
- if self ._currency_column and not self . _historical_statistics . empty : # type: ignore
820
+ if self ._currency_column : # type: ignore
816
821
self ._historical_statistics = self ._toolkit .get_historical_statistics (
817
822
progress_bar = False
818
823
)
819
824
self ._historical_statistics = self ._historical_statistics .rename (
820
825
columns = self ._ticker_combinations , level = 0
821
826
)
822
827
823
- for (_ , ticker ), currency in self ._portfolio_dataset [
824
- self ._currency_column # type: ignore
825
- ].items ():
826
- data_currency = self ._historical_statistics .loc ["Currency" , ticker ]
827
- if self ._historical_statistics .loc ["Currency" , ticker ] != currency :
828
- currency_conversions [ticker ] = (
829
- f"{ currency } { data_currency } =X" .upper ()
830
- )
828
+ if not self ._historical_statistics .empty :
829
+ for (_ , ticker ), currency in self ._portfolio_dataset [
830
+ self ._currency_column # type: ignore
831
+ ].items ():
832
+ data_currency = self ._historical_statistics .loc ["Currency" , ticker ]
833
+ if self ._historical_statistics .loc ["Currency" , ticker ] != currency :
834
+ currency_conversions [ticker ] = (
835
+ f"{ currency } { data_currency } =X" .upper ()
836
+ )
831
837
832
838
if currency_conversions :
833
839
self ._currency_toolkit = Toolkit (
@@ -962,20 +968,16 @@ def get_positions_overview(self, rounding: int | None = None):
962
968
| 2025-02-28 | 101 | -14 | 1747.63 | 4932.84 | 2.8226 | 0.0126 | 0.0054 |
963
969
"""
964
970
if self ._weekly_historical_data .empty :
965
- try :
966
- self .collect_historical_data ()
967
- except ValueError as error :
968
- raise ValueError (
969
- f"Failed to collect historical data due to { error } "
970
- ) from error
971
+ self .collect_historical_data ()
972
+
973
+ if self ._daily_historical_data .empty :
974
+ return pd .DataFrame ()
971
975
972
976
if self ._weekly_benchmark_data .empty :
973
- try :
974
- self .collect_benchmark_historical_data ()
975
- except ValueError as error :
976
- raise ValueError (
977
- f"Failed to collect benchmark historical data due to { error } "
978
- ) from error
977
+ self .collect_benchmark_historical_data ()
978
+
979
+ if self ._daily_historical_data .empty :
980
+ return pd .DataFrame ()
979
981
980
982
if self ._transactions_overview .empty :
981
983
try :
@@ -1093,20 +1095,16 @@ def get_portfolio_overview(
1093
1095
| Portfolio | 2142 | -532 | 59.8406 | 128710 | 368.549 | 789432 | 5.1334 | 660721 | 2.0773 | 0.4187 | 0.1937 | 3.0561 | 1.3272 | 1 |
1094
1096
"""
1095
1097
if self ._weekly_historical_data .empty :
1096
- try :
1097
- self .collect_historical_data ()
1098
- except ValueError as error :
1099
- raise ValueError (
1100
- f"Failed to collect historical data: { error } "
1101
- ) from error
1098
+ self .collect_historical_data ()
1099
+
1100
+ if self ._daily_historical_data .empty :
1101
+ return pd .DataFrame ()
1102
1102
1103
1103
if self ._weekly_benchmark_data .empty :
1104
- try :
1105
- self .collect_benchmark_historical_data ()
1106
- except ValueError as error :
1107
- raise ValueError (
1108
- f"Failed to collect benchmark historical data: { error } "
1109
- ) from error
1104
+ self .collect_benchmark_historical_data ()
1105
+
1106
+ if self ._daily_historical_data .empty :
1107
+ return pd .DataFrame ()
1110
1108
1111
1109
if self ._portfolio_volatilities .empty :
1112
1110
self ._portfolio_volatilities = pd .concat (
@@ -1237,20 +1235,16 @@ def get_portfolio_performance(
1237
1235
period = "quarterly" if self ._quarterly else "yearly"
1238
1236
1239
1237
if self ._weekly_historical_data .empty :
1240
- try :
1241
- self .collect_historical_data ()
1242
- except ValueError as error :
1243
- raise ValueError (
1244
- f"Failed to collect historical data: { error } "
1245
- ) from error
1238
+ self .collect_historical_data ()
1239
+
1240
+ if self ._daily_historical_data .empty :
1241
+ return pd .DataFrame ()
1246
1242
1247
1243
if self ._weekly_benchmark_data .empty :
1248
- try :
1249
- self .collect_benchmark_historical_data ()
1250
- except ValueError as error :
1251
- raise ValueError (
1252
- f"Failed to collect benchmark historical data: { error } "
1253
- ) from error
1244
+ self .collect_benchmark_historical_data ()
1245
+
1246
+ if self ._daily_historical_data .empty :
1247
+ return pd .DataFrame ()
1254
1248
1255
1249
if self ._positions_overview .empty :
1256
1250
try :
@@ -1377,20 +1371,16 @@ def get_transactions_overview(
1377
1371
)
1378
1372
1379
1373
if self ._weekly_historical_data .empty :
1380
- try :
1381
- self .collect_historical_data ()
1382
- except ValueError as error :
1383
- raise ValueError (
1384
- f"Failed to collect historical data: { error } "
1385
- ) from error
1374
+ self .collect_historical_data ()
1375
+
1376
+ if self ._daily_historical_data .empty :
1377
+ return pd .DataFrame ()
1386
1378
1387
1379
if self ._weekly_benchmark_data .empty :
1388
- try :
1389
- self .collect_benchmark_historical_data ()
1390
- except ValueError as error :
1391
- raise ValueError (
1392
- f"Failed to collect benchmark historical data: { error } "
1393
- ) from error
1380
+ self .collect_benchmark_historical_data ()
1381
+
1382
+ if self ._daily_historical_data .empty :
1383
+ return pd .DataFrame ()
1394
1384
1395
1385
try :
1396
1386
new_columns = overview_model .create_transactions_overview (
@@ -1519,20 +1509,16 @@ def get_transactions_performance(
1519
1509
period = "quarterly" if self ._quarterly else "yearly"
1520
1510
1521
1511
if self ._weekly_historical_data .empty :
1522
- try :
1523
- self .collect_historical_data ()
1524
- except ValueError as error :
1525
- raise ValueError (
1526
- f"Failed to collect historical data: { error } "
1527
- ) from error
1512
+ self .collect_historical_data ()
1513
+
1514
+ if self ._daily_historical_data .empty :
1515
+ return pd .DataFrame ()
1528
1516
1529
1517
if self ._weekly_benchmark_data .empty :
1530
- try :
1531
- self .collect_benchmark_historical_data ()
1532
- except ValueError as error :
1533
- raise ValueError (
1534
- f"Failed to collect benchmark historical data: { error } "
1535
- ) from error
1518
+ self .collect_benchmark_historical_data ()
1519
+
1520
+ if self ._daily_historical_data .empty :
1521
+ return pd .DataFrame ()
1536
1522
1537
1523
if not period :
1538
1524
raise ValueError (
0 commit comments