Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peitalin/hs-alpha-regressions
Fama French 3-factor OLS regressions
https://github.com/peitalin/hs-alpha-regressions
Last synced: about 2 months ago
JSON representation
Fama French 3-factor OLS regressions
- Host: GitHub
- URL: https://github.com/peitalin/hs-alpha-regressions
- Owner: peitalin
- License: gpl-3.0
- Created: 2015-01-22T03:15:04.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-03-20T14:28:35.000Z (almost 6 years ago)
- Last Synced: 2024-10-12T23:20:11.714Z (3 months ago)
- Language: Haskell
- Homepage:
- Size: 35.2 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Fama-French 3-factor regressions in Haskell
Run:
```bash
$ cabal install
$ cabal run
$ ghci regression.hs
```
```haskell
ghci> main
```#### Cabal Dependencies
- hmatrix
- cassava
- statistics
- hscolour
- pretty-showExample to try in GHCI
```haskell
-- Read in data from ff3.csv
data <- readRawCsv fileP
let y = getKey data lmvtx
let x1 = getKey data market
let x2 = getKey data smb
let x3 = getKey data hml
let x0 = intercept data-- Append columns into a matrix with |+| operator
let x = x0 |+| x1 |+| x2 |+| x3-- Estimate OLS with pseudo inverse
let betas = liftA2 estimateBetas x y
-- Calculate residuals and error corrections
let e = getResiduals <$> y <*> (predictYhat <$> x <*> betas)
let stdErrs = fmap (asColumn . sqrt . takeDiag) $ liftA2 (varCovMatrix) x e
let stdErrs = (asColumn . sqrt . takeDiag) <$> (varCovMatrix <$> x <*> e)
let whiteStdErrs = (asColumn . sqrt . takeDiag) <$> (robustVCV <$> x <*> e)
let tstats = liftA2 (/) betas whiteStdErrs-- Display regression results
let df = regOut <$> betas <*> whiteStdErrs <*> tstats
-- Extract display data out with ! operator
df ! "Alpha"
df ! "HML"
let matrixToList = fmap (ZipList . toList . head . toColumns)
map matrixToList [betas, whiteStdErrs, tstats]```