From 0b28a629c82195efb0c56823699974003ad0542b Mon Sep 17 00:00:00 2001 From: Enriqure Millan Valbuena Date: Sat, 23 Jul 2022 02:41:12 +0200 Subject: [PATCH] ENH: Compute tna and cfs with multicurrency positions --- CHANGELOG.md | 4 +++ src/degiro_wrapper/cli/cli.py | 5 ++-- src/degiro_wrapper/conventions.py | 4 +-- src/degiro_wrapper/core/api_methods.py | 2 +- src/degiro_wrapper/core/preprocess.py | 26 ++++++-------------- src/degiro_wrapper/reporting/calculations.py | 6 ++--- src/degiro_wrapper/reporting/utils.py | 1 - 7 files changed, 18 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afee3f9..d89cfa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.6.4] - 23/07/22 + +ENH: Compute tna and cfs with multicurrency positions + ## [0.6.3] - 17/07/22 - CLN: Modify degiro describe entrypoint to be used diff --git a/src/degiro_wrapper/cli/cli.py b/src/degiro_wrapper/cli/cli.py index 63c22a7..d9410cd 100644 --- a/src/degiro_wrapper/cli/cli.py +++ b/src/degiro_wrapper/cli/cli.py @@ -74,9 +74,7 @@ def download_positions(start, end, path, dry): if not dry: credentials = get_login_data() - download_positions_raw( - path=path, calendar=calendar, credentials=credentials - ) + download_positions_raw(path=path, calendar=calendar, credentials=credentials) if dry: click.echo("Nothing done, end of dry run!") @@ -342,6 +340,7 @@ def create_db_transactions(path, path_to): click.echo(f"To : {path_to.absolute()}") raw = pd.read_csv(path) + # breakpoint() transactions = clean_transactions(raw) transactions.to_csv(path_to, index=False) diff --git a/src/degiro_wrapper/conventions.py b/src/degiro_wrapper/conventions.py index 7d22111..cee4399 100644 --- a/src/degiro_wrapper/conventions.py +++ b/src/degiro_wrapper/conventions.py @@ -114,8 +114,8 @@ class Transactions: VALUE_LOCAL = Positions.VALUE_LOCAL VALUE_LOCAL_CCY = VALUE_LOCAL + "Ccy" - VALUE = Positions.VALUE_PORTFOLIO - VALUE_CCY = VALUE + "Ccy" + VALUE_PORTFOLIO = Positions.VALUE_PORTFOLIO + VALUE_CCY = VALUE_PORTFOLIO + "Ccy" TRANSACTION_COSTS = "costsTransaction" TRANSACTION_COSTS_CCY = "costsTransactionCcy" diff --git a/src/degiro_wrapper/core/api_methods.py b/src/degiro_wrapper/core/api_methods.py index 9c34061..aebe18a 100644 --- a/src/degiro_wrapper/core/api_methods.py +++ b/src/degiro_wrapper/core/api_methods.py @@ -208,7 +208,7 @@ def multithread(func: Callable, iterable: Iterable, total: int) -> None: Returns ------- None - This functio doesn't returns anything. + This function doesn't returns anything. """ with futures.ThreadPoolExecutor() as executor: res = executor.map(func, iterable) diff --git a/src/degiro_wrapper/core/preprocess.py b/src/degiro_wrapper/core/preprocess.py index 2df421c..02ee33c 100644 --- a/src/degiro_wrapper/core/preprocess.py +++ b/src/degiro_wrapper/core/preprocess.py @@ -118,15 +118,11 @@ def clean_positions(path): PositionsRaw.VALUE_EUR, PositionsRaw.VALUE_LOCAL, ] - positions_day[columns_to_float] = positions_day[ - columns_to_float - ].astype(float) + positions_day[columns_to_float] = positions_day[columns_to_float].astype(float) columns_to_string = [PositionsRaw.ISIN, PositionsRaw.PRODUCT] positions_day = positions_day.fillna("-") - positions_day[columns_to_string] = positions_day[ - columns_to_string - ].astype(str) + positions_day[columns_to_string] = positions_day[columns_to_string].astype(str) positions_day = positions_day.replace("-", np.nan) # --------------------------------------------------------------------- @@ -201,9 +197,7 @@ def clean_cashflows(raw): # ------------------------------------------------------------------------- # Convert to float columns_commas = [Cashflows.DELTA, Cashflows.AMOUNT] - clean[columns_commas] = replace_values( - clean[columns_commas], old=",", new="." - ) + clean[columns_commas] = replace_values(clean[columns_commas], old=",", new=".") clean[columns_commas] = clean[columns_commas].astype(float) # ------------------------------------------------------------------------- @@ -251,7 +245,7 @@ def clean_transactions(raw): TransactionsRaw.UNNAMED_PRICE: Transactions.PRICE_CCY, TransactionsRaw.VALUE_LOCAL: Transactions.VALUE_LOCAL, TransactionsRaw.UNNAMED_VALUE_LOCAL: Transactions.VALUE_LOCAL_CCY, - TransactionsRaw.VALUE: Transactions.VALUE, + TransactionsRaw.VALUE: Transactions.VALUE_PORTFOLIO, TransactionsRaw.UNNAMED_VALUE: Transactions.VALUE_CCY, TransactionsRaw.TRANSACTION_COSTS: Transactions.TRANSACTION_COSTS, TransactionsRaw.UNNAMED_COSTS: Transactions.TRANSACTION_COSTS_CCY, @@ -300,15 +294,9 @@ def positions_raw_to_clean(raw_positions): ----- It does not contain the returns of the cash position. """ - amount_df = raw_positions.pivot( - index="date", columns="ISIN", values="amount" - ) - prices_df = raw_positions.pivot( - index="date", columns="ISIN", values="price" - ) - shares_df = raw_positions.pivot( - index="date", columns="ISIN", values="shares" - ) + amount_df = raw_positions.pivot(index="date", columns="ISIN", values="amount") + prices_df = raw_positions.pivot(index="date", columns="ISIN", values="price") + shares_df = raw_positions.pivot(index="date", columns="ISIN", values="shares") # Compute share-adjusted values nav_df = (amount_df / shares_df).dropna(axis=1, how="all") diff --git a/src/degiro_wrapper/reporting/calculations.py b/src/degiro_wrapper/reporting/calculations.py index c9b4ec1..420f3c6 100644 --- a/src/degiro_wrapper/reporting/calculations.py +++ b/src/degiro_wrapper/reporting/calculations.py @@ -3,7 +3,7 @@ def compute_tna(positions): - tna = positions.groupby(Positions.DATE)[Positions.VALUE_LOCAL].sum() + tna = positions.groupby(Positions.DATE)[Positions.VALUE_PORTFOLIO].sum() tna = tna.squeeze() tna.name = Calculations.TNA @@ -13,9 +13,7 @@ def compute_tna(positions): def compute_cfs(transactions): - cfs = transactions.groupby(Transactions.DATE)[ - Transactions.VALUE_LOCAL - ].sum() + cfs = transactions.groupby(Transactions.DATE)[Transactions.VALUE_PORTFOLIO].sum() cfs = cfs.squeeze() # In the original file, buying is negative from the cash amount, diff --git a/src/degiro_wrapper/reporting/utils.py b/src/degiro_wrapper/reporting/utils.py index d5b7d91..c9e4c48 100644 --- a/src/degiro_wrapper/reporting/utils.py +++ b/src/degiro_wrapper/reporting/utils.py @@ -66,7 +66,6 @@ def filter_transactions(transactions, isins, start=None, end=None): Transactions.EXECUTION, Transactions.ID, Transactions.RATE, - Transactions.VALUE, Transactions.VALUE_CCY, Transactions.PRICE_CCY, Transactions.TOTAL,