基于目标利润反向推导股票每股卖出价格的公式推导需求
我完全理解你的需求——你现在需要把现有的 scalp 交易利润计算逻辑反过来,从目标利润反推出需要的每股卖出价格,对吧?这其实就是个代数变形的事儿,我一步步给你理清楚:
先回顾原有的正向计算逻辑
首先咱们先把你原来的所有公式列出来,方便后续变形:
BuyCost = Shares * BuyPriceSellCost = Shares * SellPriceCommission = (BuyCost + SellCost) * 0.01SecFee = (BuyCost + SellCost) * 0.00001FinraFee = Shares * 0.00000123TotalFees = Commission + SecFee + FinraFeeProfit = SellCost - BuyCost - TotalFees
逐步代数变形,解出SellPrice
咱们的目标是把Profit作为已知量,解出SellPrice。我先把所有费用项合并简化,再代入利润公式:
合并Commission和SecFee:这两项都基于
BuyCost + SellCost,可以先合并系数:Commission + SecFee = (BuyCost + SellCost) * (0.01 + 0.00001) = (BuyCost + SellCost) * 0.01001代入TotalFees:
TotalFees = (BuyCost + SellCost) * 0.01001 + Shares * 0.00000123把BuyCost和SellCost替换为Shares相关的表达式:
把BuyCost = Shares*BuyPrice、SellCost=Shares*SellPrice代入利润公式:Profit = (Shares*SellPrice) - (Shares*BuyPrice) - [(Shares*BuyPrice + Shares*SellPrice)*0.01001 + Shares*0.00000123]提取Shares公因子,整理同类项:
把含SellPrice的项、含BuyPrice的项、固定费用项分开:Profit = Shares*SellPrice*(1 - 0.01001) - Shares*BuyPrice*(1 + 0.01001) - Shares*0.00000123计算系数后得到:
Profit = Shares*0.98999*SellPrice - Shares*1.01001*BuyPrice - Shares*0.00000123移项求解SellPrice:
把所有不含SellPrice的项移到等式左边,再两边除以Shares*0.98999,最终得到:SellPrice = [Profit + Shares*(1.01001*BuyPrice + 0.00000123)] / (Shares*0.98999)如果你想更直观地按“每股”维度计算,可以拆分一下:
SellPrice = (Profit/Shares + 1.01001*BuyPrice + 0.00000123) / 0.98999
转化为可直接用的算法步骤
如果你要把这个逻辑写到你的app里,按以下步骤执行即可:
- 计算调整后的每股买入成本:
perShareBuyAdjusted = BuyPrice * 1.01001 - 计算每股Finra费用:
perShareFinra = 0.00000123 - 计算每股固定支出总和:
perShareTotalFixed = perShareBuyAdjusted + perShareFinra - 计算每股需要摊薄的目标利润:
perShareProfit = Profit / Shares - 计算分子总和:
numerator = perShareProfit + perShareTotalFixed - 最终得到每股卖出价格:
SellPrice = numerator / 0.98999
验证一下公式的正确性
举个例子验证:假设BuyPrice=10,Shares=100,目标Profit=78.978877(用正向计算SellPrice=11时得到的利润),代入公式:
SellPrice = (78.978877/100 + 1.01001*10 + 0.00000123)/0.98999 = (0.78978877 + 10.1001 + 0.00000123)/0.98999 = 10.88989 / 0.98999 = 11
完全符合预期,说明公式是正确的。
备注:内容来源于stack exchange,提问作者mike_s

