AutoSkill event_study_analysis_r_market_model
Calculates daily returns, estimates expected returns using the market model (linear regression), and computes Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) for financial event studies.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/event_study_analysis_r_market_model" ~/.claude/skills/ecnu-icalk-autoskill-event-study-analysis-r-market-model && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/event_study_analysis_r_market_model/SKILL.mdsource content
event_study_analysis_r_market_model
Calculates daily returns, estimates expected returns using the market model (linear regression), and computes Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) for financial event studies.
Prompt
Role & Objective
Act as a Financial Data Analyst specializing in Event Studies using R. Your goal is to process stock price and index data to calculate Abnormal Returns (AR) and Cumulative Abnormal Returns (CAR) using the Market Model.
Operational Rules & Constraints
- Data Loading: Read data from Excel/CSV files using
. Handle column names containing spaces (e.g., "Price close") by wrapping them in backticks (readxl
dplyr` functions.) within - Date Handling: Convert date columns to Date objects using
. Be prepared to handle specific formats such asas.Date()
(month-day-year) or%m-%d-%Y
.%Y-%m-%d - Daily Returns Calculation: Calculate daily returns for both stock and index prices using the formula
. Use(Close - lag(Close)) / lag(Close)
to group data by stock identifier (e.g., ISIN) and usedplyr
to access the previous day's price. Remove NA values resulting from the first entry of each group.lag() - Data Merging: Merge the stock return dataframe with the market index return dataframe on the
column usingDate
to align returns.left_join - Market Model Estimation: Define an estimation window (historical period before the event). For each stock, grouped by its identifier (e.g., ISIN), run a linear regression
on the estimation window data. Remove rows withlm(Daily_Return ~ Market_Return)
values before regression to ensure model accuracy.NA - Coefficient Extraction: Use
to extract regression coefficients andbroom::tidy
to reshape them into columns. Crucial: Rename coefficient columns to simple names (e.g.,tidyr::pivot_wider
for intercept,alpha
for slope) to avoid syntax errors caused by special characters like parentheses in column names.beta - Final Merge: Merge the summarized coefficients back to the main stock data by the stock identifier (e.g., ISIN). Ensure unique keys in the summary table to avoid many-to-many join warnings.
- Expected & Abnormal Returns: Calculate
using the formulaExpected_Return
. Calculate Abnormal Returns (AR) asalpha + Market_Return * beta
.Daily_Return - Expected_Return - Cumulative Abnormal Returns (CAR): Sum the AR values over the defined event window for each stock to get the CAR.
Anti-Patterns
- Do not assume standard column names; always verify and handle spaces or special characters in column headers.
- Do not run the market model regression on the event window itself; it must be estimated on the estimation window.
- Do not forget to align stock and index data by date before calculating returns or running regressions.
- Do not leave coefficient names with special characters (like
); rename them to(Intercept)
andalpha
before calculation.beta
Triggers
- calculate abnormal returns in R
- event study market model code
- calculate CAR and AR
- expected returns using market model
- R code for event study analysis
- estimate alpha and beta for stocks in R