Skip to content

Commit

Permalink
0.9.33 fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Oct 24, 2023
1 parent 394f9bd commit 6e73d67
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion czsc/utils/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ def cal_trade_price(bars: Union[List[RawBar], pd.DataFrame], decimals=3, **kwarg
df[f"sum_vcp_{t}"] = df['vol_close_prod'].rolling(t).sum()
df[f"VWAP{t}"] = (df[f"sum_vcp_{t}"] / df[f"sum_vol_{t}"]).shift(-t)
price_cols.extend([f"TWAP{t}", f"VWAP{t}"])
df.drop(columns=[f"sum_vol_{t}", f"sum_vcp_{t}"], inplace=True)

df.drop(columns=['vol_close_prod'], inplace=True)
# 用当前K线的收盘价填充交易价中的 nan 值
for price_col in price_cols:
df.loc[df[price_col].isnull(), price_col] = df[df[price_col].isnull()]['close']

df = df[['symbol', 'dt', 'open', 'close', 'high', 'low', 'vol', 'amount'] + price_cols].round(decimals)
df[price_cols] = df[price_cols].round(decimals)
return df


Expand Down

0 comments on commit 6e73d67

Please sign in to comment.