-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import and merge CRSP MSF and Compustat Funda file
- Loading branch information
1 parent
9266f0f
commit ee9c7da
Showing
11 changed files
with
747 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,57 @@ | ||
# FinanceRoutines | ||
|
||
https://juliadocs.github.io/Documenter.jl/stable | ||
| **Documentation** | **Build Status** | | ||
|:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:| | ||
| [![][docs-stable-img]][docs-stable-url] [![][docs-dev-img]][docs-dev-url] | ![Build Status](https://github.com/eloualiche/FinanceRoutines.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/eloualiche/FinanceRoutines.jl/actions/workflows/CI.yml?query=branch%3Amain) | | ||
|
||
|
||
[!https://eloualiche.github.io/FinanceRoutines.jl/ | ||
|
||
[![Build Status](https://github.com/eloualiche/FinanceRoutines.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/eloualiche/FinanceRoutines.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
|
||
## Functions | ||
|
||
1. Import Financial data | ||
- `ImportFinanceData.jl` | ||
- `import_FF3` | ||
- `build_crsp` | ||
|
||
## To Do | ||
|
||
- Time lags for panel data (if lag and data is not offset by one month, then returns missing). | ||
- `olsgmm` from cochrane GMM code | ||
- rolling regressions | ||
|
||
|
||
## References | ||
|
||
- [WRDS demo on momentum](https://wrds-www.wharton.upenn.edu/documents/1442/wrds_momentum_demo.html) | ||
- Tidy Finance [Book](https://www.tidy-finance.org) and [repo](https://github.com/tidy-finance/website) | ||
- French data [R package](https://nareal.github.io/frenchdata/articles/basic_usage.html) | ||
- Ian Gow [Quarto Book](https://iangow.github.io/far_book/ident.html) | ||
- Replication [Open Source AP](https://github.com/OpenSourceAP/CrossSection/tree/master) | ||
|
||
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg | ||
[docs-stable-url]: https://eloualiche.github.io/FinanceRoutines.jl/ | ||
|
||
## Examples | ||
|
||
### Import data from WRDS | ||
|
||
First import the monthly stock file and the compustat funda file | ||
```julia | ||
using FinanceRoutines | ||
# Set up a wrds connection | ||
wrds_conn = FinanceRoutines.open_wrds_pg() | ||
|
||
# CRSP | ||
df_msf = import_MSF(wrds_conn); # Import the monthly stock file | ||
df_msf = build_MSF(df_msf); # Run common processing | ||
# Compustat | ||
df_funda = import_Funda(wrds_conn); | ||
df_funda = build_Funda(df_funda); | ||
# Merge both files | ||
df_linktable = FinanceRoutines.import_ccm_link(wrds_conn) | ||
df_msf = link_MSF(df_linktable, df_msf) # merge gvkey on monthly stock file | ||
df_msf = innerjoin(df_msf, df_funda, on = [:gvkey, :date_y], matchmissing=:notequal) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,58 @@ | ||
module FinanceRoutines | ||
|
||
|
||
# --------------------------------------------------------- | ||
# ------------------------------------------------------------------------------------------ | ||
import Downloads | ||
import ZipFile | ||
import CSV | ||
import DataFrames: DataFrame, rename! | ||
import DataFramesMeta: DataFramesMeta, @subset!, @transform! | ||
import Dates: Date | ||
# --------------------------------------------------------- | ||
|
||
|
||
# --------------------------------------------------------- | ||
import DataFrames: DataFrame, ByRow, groupby, nrow, passmissing, Not, | ||
rename!, select!, groupby, transform!, leftjoin, disallowmissing! | ||
import DataFramesMeta: DataFramesMeta, | ||
@passmissing, @subset!, @rsubset!, @transform!, @rtransform! | ||
import Dates: Dates, Date, Month, year | ||
import Downloads: Downloads.download | ||
import FlexiJoins: innerjoin, by_key, by_pred | ||
import IntervalSets:(..) | ||
import LibPQ: LibPQ.execute, LibPQ.Connection | ||
import Missings: Missings, missing | ||
import MonthlyDates: MonthlyDate | ||
import PanelShift: panellag! | ||
import ShiftedArrays: lag | ||
import Tables: columntable | ||
import WeakRefStrings: String3, String7, String15 | ||
import ZipFile: ZipFile.Reader | ||
# ------------------------------------------------------------------------------------------ | ||
|
||
|
||
# ------------------------------------------------------------------------------------------ | ||
# Import functions | ||
include("Utilities.jl") | ||
include("ImportFinanceData.jl") | ||
# --------------------------------------------------------- | ||
include("ImportCRSP.jl") | ||
include("ImportComp.jl") | ||
include("Merge_CRSP_Comp.jl") | ||
# ------------------------------------------------------------------------------------------ | ||
|
||
|
||
# --------------------------------------------------------- | ||
# ------------------------------------------------------------------------------------------ | ||
# List of exported functions | ||
export greet_FinanceRoutines # for debugging | ||
export import_FF3 # read monthly FF3 | ||
# --------------------------------------------------------- | ||
|
||
# WRDS | ||
# -- CRSP | ||
export import_MSF # import Monthly Stock File | ||
export import_DSF # import Daily Stock File | ||
export build_MSF # clean Monthly Stock File | ||
# -- Funda | ||
export import_Funda | ||
export build_Funda | ||
# -- Link | ||
export link_Funda | ||
export link_MSF | ||
|
||
# FF | ||
export import_FF3 | ||
# ------------------------------------------------------------------------------------------ | ||
|
||
|
||
end |
Oops, something went wrong.