Skip to content

Commit

Permalink
Import and merge CRSP MSF and Compustat Funda file
Browse files Browse the repository at this point in the history
  • Loading branch information
eloualiche committed Jul 3, 2023
1 parent 9266f0f commit ee9c7da
Show file tree
Hide file tree
Showing 11 changed files with 747 additions and 38 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
# STANDARD JULIA IGNORE
/Manifest.toml
docs/build/

# ---------------------------------------------------------


# ---------------------------------------------------------
# DEVELOPMENT FILES
sandbox.jl
sandbox.R
tmp
# ---------------------------------------------------------
22 changes: 10 additions & 12 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FinanceRoutines"
uuid = "2e4c0fa2-b49b-4c8f-9592-485f04b9fc03"
authors = "Erik Loualiche <eloualic@umn.edu>"
authors = ["Erik Loualiche <eloualic@umn.edu>"]
version = "0.1.0"

[deps]
Expand All @@ -9,15 +9,13 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
FlexiJoins = "e37f2e79-19fa-4eb7-8510-b63b51fe0a37"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LibPQ = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1"
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
MonthlyDates = "5be0b35e-b7aa-4f8f-be3c-193ee1a845a6"
PanelShift = "d68e4d5e-4a60-4df1-b225-9a1636c75ae0"
ShiftedArrays = "1277b4bf-5013-50f5-be3d-901d8477a67a"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"

[compat]
CSV = "0.10"
julia = "1"

[extras]
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Markdown", "Test"]
51 changes: 49 additions & 2 deletions README.md
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)
```

3 changes: 3 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ makedocs(
])
deploydocs(;
repo="github.com/eloualiche/FinanceRoutines.jl",
target = "build",
branch = "gh-pages",

)
55 changes: 43 additions & 12 deletions src/FinanceRoutines.jl
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
Loading

0 comments on commit ee9c7da

Please sign in to comment.