Portfolio to Po now works well and removed cash

This commit is contained in:
jeroen
2023-02-06 18:58:01 +01:00
parent ee34a1f278
commit b607084f39
3 changed files with 41 additions and 2 deletions

View File

@@ -276,13 +276,49 @@ class PortfolioController(BaseController):
if OPTIMIZATION_TOOLKIT_ENABLED:
if self.portfolio is None:
tickers = []
categories = None
else:
tickers = self.portfolio.tickers_list
transactions = self.portfolio.get_transactions()
categories = {
"ASSET_CLASS": {},
"SECTOR": {},
"INDUSTRY": {},
"COUNTRY": {},
"CURRENT_INVESTED_AMOUNT": {},
"CURRENCY": {},
}
for _, transaction in transactions.iterrows():
if transaction["Ticker"] not in categories["ASSET_CLASS"]:
categories["ASSET_CLASS"][transaction["Ticker"]] = transaction[
"Type"
]
categories["SECTOR"][transaction["Ticker"]] = transaction[
"Sector"
]
categories["INDUSTRY"][transaction["Ticker"]] = transaction[
"Industry"
]
categories["COUNTRY"][transaction["Ticker"]] = transaction[
"Country"
]
categories["CURRENT_INVESTED_AMOUNT"][
transaction["Ticker"]
] = transactions[
transactions["Ticker"] == transaction["Ticker"]
][
"Investment"
].sum()
categories["CURRENCY"][transaction["Ticker"]] = transaction[
"Currency"
]
self.queue = self.load_class(
po_controller.PortfolioOptimizationController,
tickers,
None,
None,
categories,
self.queue,
)
else:

View File

@@ -236,6 +236,9 @@ class PortfolioOptimizationController(BaseController):
if categories:
self.categories = dict(categories)
self.available_categories = list(self.categories.keys())
if "CURRENT_INVESTED_AMOUNT" in self.available_categories:
self.available_categories.remove("CURRENT_INVESTED_AMOUNT")
else:
self.categories = dict()
self.available_categories = list()

View File

@@ -26,7 +26,7 @@ Note that the Excel sheet requires the following columns:
- **Date** - The date the trade occurred
- **Name** - The name of the security
- **Type** - The type of the security. Use Cash/Stock/Crypto/ETF as appropriate
- **Type** - The type of the security. Use Stock/Crypto/ETF as appropriate
- **Price** - The price the security was added or removed at, on a per-unit
basis
- **Quantity** - How much of the security in question was added or removed