- OKX交易自动化 (okx-auto-position, okx-crypto, okx-exchange) - 交易信号处理 (signal-confirmation-templates, trading-signal-aggregator) - 量化因子挖掘 (quant-factor-mining) - 长桥集成 (longbridge-cli, longbridge-python-sdk) - 六合彩分析 (lottery-hk) - 股息投资 (dividend-investing, dividend-scanner) - 日内交易 (intraday-trading) - 同花顺 (tonghuashun)
1.8 KiB
1.8 KiB
DCA Yield Filter Pattern
When user wants to filter DCA positions by minimum dividend yield, add this block to the monitor script after loading positions but before fetching quotes.
Code Pattern
positions = config['positions']
# === Yield filter: skip positions below threshold ===
MIN_YIELD = 7.0 # user-configurable
filtered_out = []
for sym in list(positions.keys()):
if positions[sym].get('yield', 0) < MIN_YIELD:
filtered_out.append(f"{sym}({positions[sym]['name']} {positions[sym]['yield']}%)")
del positions[sym]
Budget Reallocation
When filtering removes positions, redistribute budget evenly among remaining:
n = len(positions)
per_stock_hkd = round(7500 / n) # monthly budget / remaining count
usd_hkd = config['budget']['usd_hkd']
for sym, pos in positions.items():
pos['monthly_budget_hkd'] = per_stock_hkd
if pos['market'] == 'US':
pos['monthly_budget_local'] = round(per_stock_hkd / usd_hkd, 2)
else:
pos['monthly_budget_local'] = per_stock_hkd
Config File Structure (dca_positions.json)
Each position has a yield field used for filtering:
{
"positions": {
"NLY.US": {
"name": "Annaly Capital",
"yield": 13.2,
"market": "US",
"ladder": [...],
"monthly_budget_hkd": 2500,
"monthly_budget_local": 320.51
}
},
"alert_settings": { "trigger_pct": 2.0 },
"budget": { "monthly_mid_hkd": 7500, "usd_hkd": 7.8 }
}
Key Points
- Filter runs in-memory at script start; the JSON file retains all positions (including filtered ones) for future reference
- User can change
MIN_YIELDthreshold without editing the JSON - When adding new positions to the JSON, the filter automatically enforces the threshold
filtered_outlist can be logged for transparency