Skip to content

Commit

Permalink
Merge pull request #54 from KikeM/feature/multicurrency_portfolios
Browse files Browse the repository at this point in the history
ENH: Compute with multicurrency positions
  • Loading branch information
emvalbuena authored Jul 23, 2022
2 parents 40dd6b1 + 0b28a62 commit cd21817
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/degiro_wrapper/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/degiro_wrapper/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/degiro_wrapper/core/api_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 7 additions & 19 deletions src/degiro_wrapper/core/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# ---------------------------------------------------------------------
Expand Down Expand Up @@ -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)

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions src/degiro_wrapper/reporting/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/degiro_wrapper/reporting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cd21817

Please sign in to comment.