我有一个带有代码的数据框作为标题和行,在过去一年中每日调整收盘价,我想计算年化波动率,但我不确定如何通过列。当我运行此代码时,出现异常:TypeError: 'Series' object is not callable
import pandas as pd
import datetime as datetime
from datetime import timedelta
import yfinance as yf
df = pd.read_excel('C:/Users/Jacob/Downloads/Benchmark Tickers.xlsx', sheet_name='Sheet1')
tickers_list = df['Ticker'].tolist()
data = pd.DataFrame(columns=tickers_list)
for ticker in tickers_list:
data[ticker] = yf.download(ticker, start=datetime.datetime.now()-datetime.timedelta(days=365), end=datetime.date.today()) ["Adj Close"]
def volatility(ticker):
return data[ticker].pct_change().rolling(252).std()*(252**0.5)
data[ticker].apply(volatility(ticker))
export_excel = data.to_excel(r'C:/Users/User/Downloads/testvol.xlsx', sheet_name='Sheet1', index= True)
我如何将这个波动函数应用于每一列?
以下是执行 yfinance pull 时获取的数据的链接: https ://docs.google.com/spreadsheets/d/11-kS1ah1lP8v6xv2JQZt_0i7YmynQxIw6q0stEvS_nM/edit?usp=sharing