Skip to content

Commit

Permalink
momentum factor
Browse files Browse the repository at this point in the history
  • Loading branch information
nhirschey committed Dec 1, 2023
1 parent b93cc12 commit 600ae88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/NovaSBE.Finance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.5.0 - 2023-12-01

### Added

* NovaSBE.Finance added momentum factors.

## 0.4.1 - 2023-12-01

### Fixed
Expand Down
24 changes: 24 additions & 0 deletions src/NovaSBE.Finance/French.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ type FF5Obs =
Rf : float
Frequency : Frequency }

type WMLObs =
{ Date : DateTime
WML : float
Frequency : Frequency }

module internal Utils =
type FF3Csv = CsvProvider<"Date (string),Mkt-RF,SMB,HML,RF
19260701, 0.10, -0.24, -0.28, 0.009">

type FF5Csv = CsvProvider<"Date (string),Mkt-RF,SMB,HML,RMW,CMA,RF
19260701, 0.10, -0.24, -0.28,0.0,1.2, 0.009">

type WMLCsv = CsvProvider<"Date (string),Mom (float)">

let frenchDay x =
DateTime.ParseExact(x,
"yyyyMMdd",
Expand Down Expand Up @@ -107,3 +114,20 @@ let getFF5 frequency =
Cma = float parsedLine.CMA / 100.0
Rf = float parsedLine.RF / 100.0
Frequency = frequency })

let getWML frequency =
let (dataset, dateParser) =
match frequency with
| Monthly -> "F-F_Momentum_Factor_CSV", frenchMonth
| Daily -> "F-F_Momentum_Factor_daily_CSV", frenchDay
let data = new StringReader(getData dataset)
[| while data.Peek() <> -1 do
data.ReadLine() |]
|> Array.skipWhile(fun line -> not (line.StartsWith(",Mom")))
|> Array.skip 1
|> Array.takeWhile(fun line -> line <> "")
|> Array.map(fun line ->
let parsedLine = WMLCsv.ParseRows(line).[0]
{ Date = dateParser parsedLine.Date
WML = float parsedLine.Mom / 100.0
Frequency = frequency })
9 changes: 9 additions & 0 deletions tests/NovaSBE.Finance.Tests/French.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ let ``Can do ff5 monthly`` () =
let ff5m = getFF5 Frequency.Monthly
ff5m.Length |> shouldBeGreaterThan 10

[<Fact>]
let ``Can do wml daily`` () =
let wmld = getWML Frequency.Daily
wmld.Length |> shouldBeGreaterThan 10

[<Fact>]
let ``Can do wml monthly`` () =
let wmlm = getWML Frequency.Monthly
wmlm.Length |> shouldBeGreaterThan 10

0 comments on commit 600ae88

Please sign in to comment.