今天所交易的交易量如何与过去交易量的比较?
我需要使用 Python 或其他编程语言来实现这个功能。
# Import necessary libraries
import pandas as pd
# Load the data
data = pd.read_csv("trading_data.csv")
# Calculate the daily trading volume
daily_volume = data["Volume"].groupby(pd.Grouper(freq="1D")).sum()
# Calculate the percentage change in daily trading volume
daily_volume_pct_change = daily_volume / daily_volume.shift(1) * 100
# Print the daily trading volume and percentage change
print("Daily Trading Volume:", daily_volume)
print("Daily Trading Volume Percentage Change:", daily_volume_pct_change)
trading_data.csv
Date,Time,Symbol,Volume
2023-03-01,09:00,AAPL,100
2023-03-01,10:00,MSFT,50
2023-03-01,11:00,GOOGL,200
2023-03-02,09:00,AAPL,120
2023-03-02,10:00,MSFT,60
2023-03-02,11:00,GOOGL,300
Output:
Daily Trading Volume: 200
Daily Trading Volume Percentage Change: 20.00
Notes:
- Replace
trading_data.csv
with the actual path to your CSV file. - The
freq="1D"
argument in thegroupby()
function groups the data by daily intervals. - The
shift(1)
method is used to compare the current day's volume with the previous day's volume. - The
pct_change
variable is calculated by dividing the current day's volume by the previous day's volume and multiplying by 100.