自己來解答 看過vedel 大PO的"AmiBroker 投資組合試算" http://coco-in.net/forum.php?mod=viewthread&tid=20544&fromuid=6528 想到可以寫段把留倉成本算出來的腳本 事後再來計算就好(感覺很多此一舉) ANYWAY 下面寫法很粗糙 希望有前輩可以指出錯誤 或幫忙縮短 (或是直接點明AB哪邊可以設留倉成本) _SECTION_BEGIN("HoldingCost"); Buy_time=ValueWhen(Buy,TimeNum(),1); Sell_time=ValueWhen(Sell,TimeNum(),1); Buy_date=ValueWhen(Buy,DayOfYear(),1); Sell_date=ValueWhen(Sell,DayOfYear(),1); Buy_year=ValueWhen(Buy,Year(),1); Sell_year=ValueWhen(Sell,Year(),1); Buy_Holdingday=IIf(Year()!=Sell_year, IIf(Buy_date>Sell_date, 365-Buy_date+DayOfYear(), IIf(Year()==Buy_year, DayOfYear()-Buy_date,0) ), IIf(Buy_year==Sell_year, IIf(Buy_date>Sell_date,DayOfYear()-Buy_date, IIf(Buy_date==Sell_dateAND Buy_time>Sell_time,DayOfYear()-Buy_date,0) ), IIf(Buy_date<Sell_date,DayOfYear()-Buy_date, IIf(Buy_date==Sell_dateAND Buy_time>Sell_time,DayOfYear()-Buy_date,0) ) ) ); Short_time=ValueWhen(Short,TimeNum(),1); Cover_time=ValueWhen(Cover,TimeNum(),1); Short_date=ValueWhen(Short,DayOfYear(),1); Cover_date=ValueWhen(Cover,DayOfYear(),1); Short_year=ValueWhen(Short,Year(),1); Cover_year=ValueWhen(Cover,Year(),1); Short_Holdingday=IIf(Year()!=Cover_year, IIf(Short_date>Cover_date, 365-Short_date+DayOfYear(), IIf(Year()==Short_year, DayOfYear()-Short_date,0) ), IIf(Short_year==Cover_year, IIf(Short_date>Cover_date,DayOfYear()-Short_date, IIf(Short_date==Cover_dateAND Short_time>Cover_time,DayOfYear()-Short_date,0) ), IIf(Short_date<Cover_date,DayOfYear()-Short_date, IIf(Short_date==Cover_dateAND Short_time>Cover_time,DayOfYear()-Short_date,0) ) ) ); COCO=(Buy_Holdingday+Short_Holdingday)*7; HoldingCost=IIf(Sell ORCover,Ref(COCO,-1),0); "HoldingCost="+COCO; _SECTION_END(); AddToComposite(Equity(),"~TX","C"); AddToComposite(HoldingCost,"~TX","V"); 紅色7就是隔夜成本 我設7 然後是把隔夜成本當作成交量丟到TX商品去 出來的圖會是長這樣 下方只是算總資金部位
|