Skip to content

Commit fa5d299

Browse files
committed
modfied run weekly
1 parent b892845 commit fa5d299

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

run_weekly_report.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,35 @@ def _convert_signals_to_dataframe(signals: dict, strategy_name: str) -> pd.DataF
178178

179179
# BUY signals
180180
for ticker, data in signals.get("BUY", {}).items():
181+
size = float(data.get("size", 0)) if isinstance(data.get("size", 0), Decimal) else data.get("size", 0)
182+
price = float(data.get("price", 0)) if isinstance(data.get("price", 0), Decimal) else data.get("price", 0)
183+
total_value = size * price if size and price else 0
184+
181185
rows.append({
182186
"Ticker": ticker,
183187
"Signal": "BUY",
184188
"Strategy": strategy_name,
185-
"Size": data.get("size", 0),
186-
"Price": data.get("price", 0),
187-
"Stop_Loss": data.get("stop", 0),
188-
"Risk_Amount": data.get("risk", 0),
189-
"Notes": f"Size: {data.get('size', 0)} shares at €{data.get('price', 0):.2f}"
189+
"Size": size,
190+
"Price": price,
191+
"Total_Value": total_value,
192+
"Stop_Loss": float(data.get("stop", 0)) if isinstance(data.get("stop", 0), Decimal) else data.get("stop", 0),
193+
"Risk_Amount": float(data.get("risk", 0)) if isinstance(data.get("risk", 0), Decimal) else data.get("risk", 0),
194+
"Notes": f"Size: {size} shares at €{price:.2f} = €{total_value:.2f}"
190195
})
191196

192197
# SELL signals
193198
for ticker, data in signals.get("SELL", {}).items():
199+
size = float(data.get("quantity", 0)) if isinstance(data.get("quantity", 0), Decimal) else data.get("quantity", 0)
200+
price = float(data.get("price", 0)) if isinstance(data.get("price", 0), Decimal) else data.get("price", 0)
201+
total_value = size * price if size and price else 0
202+
194203
rows.append({
195204
"Ticker": ticker,
196205
"Signal": "SELL",
197206
"Strategy": strategy_name,
198-
"Size": data.get("quantity", 0),
199-
"Price": data.get("price", 0),
207+
"Size": size,
208+
"Price": price,
209+
"Total_Value": total_value,
200210
"Stop_Loss": "",
201211
"Risk_Amount": "",
202212
"Notes": data.get("reason", "Strategy sell")
@@ -210,16 +220,18 @@ def _convert_signals_to_dataframe(signals: dict, strategy_name: str) -> pd.DataF
210220
"Strategy": strategy_name,
211221
"Size": "",
212222
"Price": "",
223+
"Total_Value": "",
213224
"Stop_Loss": "",
214225
"Risk_Amount": "",
215226
"Notes": data.get("reason", "Keep position")
216227
})
217228

218229
if not rows:
219230
return pd.DataFrame(columns=["Ticker", "Signal", "Strategy", "Size", "Price",
220-
"Stop_Loss", "Risk_Amount", "Notes"])
231+
"Total_Value", "Stop_Loss", "Risk_Amount", "Notes"])
221232

222-
return pd.DataFrame(rows)
233+
df = pd.DataFrame(rows)
234+
return _convert_decimals_to_float(df)
223235

224236

225237
def _get_portfolio_snapshots_week(portfolio_name: str, today_str: str) -> pd.DataFrame:

0 commit comments

Comments
 (0)