用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill run2-quarter-comparison命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Handles reading, populating, and saving .docx files using the python-docx library. Use this skill for any tasks involving template filling or modifying Word documents.
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
This skill includes search capability in 13F, such as fuzzy search a fund information using possibly inaccurate name, or fuzzy search a stock cusip info using its name.
基于 SOC 职业分类
正在显示 SKILL.md
| name | run2_quarter_comparison |
| description | Compare holdings across quarters to identify increased/decreased investments |
Compare a fund's holdings between two quarters (e.g., Q2 to Q3) to identify which stocks received increased or decreased investment.
import pandas as pd
# Q2 (June 30)
coverpage_q2 = pd.read_csv('/root/2025-q2/COVERPAGE.tsv', sep='\t')
fund_q2 = coverpage_q2[coverpage_q2['FILINGMANAGER_NAME'].str.contains('Berkshire', case=False)]
accession_q2 = fund_q2['ACCESSION_NUMBER'].values[0]
# Q3 (September 30)
coverpage_q3 = pd.read_csv('/root/2025-q3/COVERPAGE.tsv', sep='\t')
fund_q3 = coverpage_q3[coverpage_q3['FILINGMANAGER_NAME'].str.contains('Berkshire', case=False)]
accession_q3 = fund_q3['ACCESSION_NUMBER'].values[0]
# Load INFOTABLE for both quarters
infotable_q2 = pd.read_csv('/root/2025-q2/INFOTABLE.tsv', sep='\t', low_memory=False)
infotable_q3 = pd.read_csv('/root/2025-q3/INFOTABLE.tsv', sep='\t', low_memory=False)
# Filter to specific fund
fund_q2_holdings = infotable_q2[infotable_q2['ACCESSION_NUMBER'] == accession_q2]
fund_q3_holdings = infotable_q3[infotable_q3['ACCESSION_NUMBER'] == accession_q3]
# Group Q2 holdings by CUSIP
q2_summary = fund_q2_holdings.groupby('CUSIP').agg({
'VALUE': 'sum',
'NAMEOFISSUER': 'first',
'SSHPRNAMT': 'sum'
}).reset_index()
q2_summary.columns = ['CUSIP', 'VALUE_Q2', 'NAMEOFISSUER_Q2', 'SHARES_Q2']
# Group Q3 holdings by CUSIP
q3_summary = fund_q3_holdings.groupby('CUSIP').agg({
'VALUE': 'sum',
'NAMEOFISSUER': 'first',
'SSHPRNAMT': 'sum'
}).reset_index()
q3_summary.columns = ['CUSIP', 'VALUE_Q3', 'NAMEOFISSUER_Q3', 'SHARES_Q3']
# Merge on CUSIP (outer join to capture new and exited positions)
comparison = pd.merge(q2_summary, q3_summary, on='CUSIP', how='outer')
# Fill NaN with 0 (positions not held in that quarter)
comparison['VALUE_Q2'] = comparison['VALUE_Q2'].fillna(0)
comparison['VALUE_Q3'] = comparison['VALUE_Q3'].fillna(0)
# Calculate value change
comparison['VALUE_CHANGE'] = comparison['VALUE_Q3'] - comparison['VALUE_Q2']
comparison['SHARE_CHANGE'] = comparison['SHARES_Q3'].fillna(0) - comparison['SHARES_Q2'].fillna(0)
# Top 5 stocks with INCREASED investment (positive value change)
top_5_increases = comparison[comparison['VALUE_CHANGE'] > 0].nlargest(5, 'VALUE_CHANGE')
# Top 5 stocks with DECREASED investment (negative value change)
top_5_decreases = comparison[comparison['VALUE_CHANGE'] < 0].nsmallest(5, 'VALUE_CHANGE')
# Get CUSIPs
increased_cusips = top_5_increases['CUSIP'].tolist()
decreased_cusips = top_5_decreases['CUSIP'].tolist()
print("Top 5 Increased Positions:")
print(top_5_increases[['CUSIP', 'NAMEOFISSUER_Q2', 'VALUE_Q2', 'VALUE_Q3', 'VALUE_CHANGE']])
# Use first non-null NAMEOFISSUER
comparison['NAMEOFISSUER'] = comparison['NAMEOFISSUER_Q2'].fillna(comparison['NAMEOFISSUER_Q3'])
# New positions (not in Q2): NAMEOFISSUER_Q2 is NaN
new_positions = comparison[comparison['VALUE_Q2'] == 0][comparison['VALUE_CHANGE'] > 0]
# Exited positions (not in Q3): NAMEOFISSUER_Q3 is NaN
exited_positions = comparison[comparison['VALUE_Q3'] == 0][comparison['VALUE_CHANGE'] < 0]
Some fund filings may have the same CUSIP listed multiple times (different options, derivative types, etc.). The aggregation via groupby().agg() handles this automatically by summing.
# Avoid DtypeWarning when loading INFOTABLE
infotable = pd.read_csv(
'INFOTABLE.tsv',
sep='\t',
low_memory=False, # Critical for INFOTABLE
dtype={'ACCESSION_NUMBER': 'str', 'CUSIP': 'str', 'VALUE': 'int64'}
)
import pandas as pd
# Load files
infotable_q2 = pd.read_csv('/root/2025-q2/INFOTABLE.tsv', sep='\t', low_memory=False)
infotable_q3 = pd.read_csv('/root/2025-q3/INFOTABLE.tsv', sep='\t', low_memory=False)
coverpage_q2 = pd.read_csv('/root/2025-q2/COVERPAGE.tsv', sep='\t')
coverpage_q3 = pd.read_csv('/root/2025-q3/COVERPAGE.tsv', sep='\t')
# Get accession numbers
accession_q2 = coverpage_q2[coverpage_q2['FILINGMANAGER_NAME'] == 'Berkshire Hathaway Inc']['ACCESSION_NUMBER'].values[0]
accession_q3 = coverpage_q3[coverpage_q3['FILINGMANAGER_NAME'] == 'Berkshire Hathaway Inc']['ACCESSION_NUMBER'].values[0]
# Get holdings
q2_holdings = infotable_q2[infotable_q2['ACCESSION_NUMBER'] == accession_q2]
q3_holdings = infotable_q3[infotable_q3['ACCESSION_NUMBER'] == accession_q3]
# Aggregate by CUSIP
q2_agg = q2_holdings.groupby('CUSIP')['VALUE'].sum().reset_index()
q2_agg.columns = ['CUSIP', 'VALUE_Q2']
q3_agg = q3_holdings.groupby('CUSIP')['VALUE'].sum().reset_index()
q3_agg.columns = ['CUSIP', 'VALUE_Q3']
# Merge
comparison = pd.merge(q2_agg, q3_agg, on='CUSIP', how='outer')
comparison['VALUE_Q2'] = comparison['VALUE_Q2'].fillna(0)
comparison['VALUE_Q3'] = comparison[].fillna()
comparison[] = comparison[] - comparison[]
top_5 = comparison[comparison[] > ].nlargest(, )
cusips = top_5[].tolist()
(cusips)
Result should be a list of CUSIPs ordered by value change (descending):
{
"top_5_cusips": ["CUSIP1", "CUSIP2", "CUSIP3", "CUSIP4", "CUSIP5"],
"changes": [
{"cusip": "CUSIP1", "value_change": 4338397000000},
{"cusip": "CUSIP2", "value_change": 3208516000000}
]
}