Skip to content

Commit

Permalink
attempt to update fsharp.stats
Browse files Browse the repository at this point in the history
  • Loading branch information
nhirschey committed Nov 23, 2023
1 parent d94bfdf commit 12483fe
Show file tree
Hide file tree
Showing 40 changed files with 98 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data-cache
*/*FootballPlayers.csv
docs/*.csv
docs/data
docs/project/data
docs/project/data
*/*shiller_data.xls
4 changes: 2 additions & 2 deletions docs/.debugMVE.fsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#r "nuget: NovaSBE.Finance"
#r "nuget: FSharp.Stats"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: FSharp.Stats, 0.5.0"

open System
open FSharp.Stats
Expand Down
4 changes: 2 additions & 2 deletions docs/.sgd.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ index: 1000
[![Notebook](img/badge-notebook.svg)]({{root}}/{{fsdocs-source-basename}}.ipynb)
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: DiffSharp-lite"
#r "nuget: Quotes.YahooFinance, 0.0.5"

Expand Down
2 changes: 1 addition & 1 deletion docs/.sp500.fsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#r "nuget: FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"

open System
open FSharp.Data
Expand Down
2 changes: 1 addition & 1 deletion docs/Common.fsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(**
[![Script](img/badge-script.svg)]({{root}}/{{fsdocs-source-basename}}.fsx) 
*)
#r "nuget: FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"

open System
open System.IO
Expand Down
6 changes: 3 additions & 3 deletions docs/Momentum-Class.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ index: 9

#time "on"

#r "nuget: FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"
#r "nuget: NovaSBE.Finance,0.1.0"
#r "nuget: NovaSBE.Finance, 0.4.0"

open System
open FSharp.Data
Expand Down
2 changes: 1 addition & 1 deletion docs/PortfolioFormation-SimpleExample.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ samplePeriod
Now let's dig in. This is a *relatively* basic version of a strategy to build intuition with what we're doing. It is simpler than working with real data. But we will next move to real data.
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Stats, 0.5.0"
open FSharp.Stats

(**
Expand Down
16 changes: 8 additions & 8 deletions docs/VolAndReturnPred.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ index: 7
*)


#r "nuget: FSharp.Data"
#r "nuget: NovaSBE.Finance"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"

Expand Down Expand Up @@ -309,16 +309,16 @@ let varBuyHold = buyHoldPeriod |> varBy (fun x -> x.Return)

(** Now our managed portfolio. *)

let avgReturn = result |> List.averageBy (fun x -> x.Return)
let varResult = result |> varBy (fun x -> x.Return)
let avgManagedReturn = result |> List.averageBy (fun x -> x.Return)
let varManagedResult = result |> varBy (fun x -> x.Return)

(avgReturn - (3.0/2.0) * varResult)*252.0
(avgManagedReturn - (3.0/2.0) * varManagedResult)*252.0

(** Why the difference? *)

(** Try scaling managed to full sample variance. *)
let c = sqrt varBuyHold / sqrt varResult
(c * avgReturn - (3.0/2.0) * c ** 2.0 * varResult)*252.0
let c = sqrt varBuyHold / sqrt varManagedResult
(c * avgManagedReturn - (3.0/2.0) * c ** 2.0 * varManagedResult)*252.0

(** Another way of seeing it.*)

Expand Down
6 changes: 3 additions & 3 deletions docs/VolatilityManagedTypes.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Last time we looked at volatility managed portfolios, but we hard coded the vola
*)


#r "nuget: FSharp.Data"
#r "nuget: NovaSBE.Finance"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"

Expand Down
10 changes: 6 additions & 4 deletions docs/VolatilityTiming.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ As a start, let's acquire a long daily time series on aggregate US market return
*)

#r "nuget: FSharp.Data"
#r "nuget: NovaSBE.Finance"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: NovaSBE.Finance, 0.4.0"
open System
open FSharp.Data
open NovaSBE.Finance.French
Expand All @@ -47,7 +47,7 @@ ff3 |> List.take 5
One thing that can help us manage volatility is the fact that volatility tends to be somewhat persistent. By this we mean that if our risky asset is volatile today, then it is likely to be volatile tomorrow. We can observe this by plotting monthly volatility as we do below. It also means that we can use recent past volatility to form estimates of future volatility.
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"

Expand Down Expand Up @@ -76,9 +76,11 @@ testMonth
let testMonthGroup, testMonthObs = testMonth
(** testMonthGroup *)
testMonthGroup
(***include-it***)

(** testMonthXS *)
testMonthObs
testMonthObs |> List.take 3
(***include-it***)

(** Test month return standard deviation. *)
testMonthObs
Expand Down
2 changes: 1 addition & 1 deletion docs/YahooFinance.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Based on code from https://github.com/aexsalomao/YahooFinance/
*)

#r "nuget: FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"

open System
open FSharp.Data
Expand Down
4 changes: 2 additions & 2 deletions docs/assignment-risky-weights.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ All work that you submit should be your own. Make use of the course resources an
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Quotes.YahooFinance"
#r "nuget: Plotly.NET, 3.*"
(*** condition: ipynb ***)
Expand Down
8 changes: 4 additions & 4 deletions docs/assignment-volatility-timing.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ All work that you submit should be your own. Make use of the course resources an
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
(*** condition: ipynb ***)
#r "nuget: Plotly.NET.Interactive, 3.*"
Expand Down Expand Up @@ -73,7 +73,7 @@ Formatter.SetPreferredMimeTypesFor(typeof<GenericChart.GenericChart>,"text/html"
We get the Fama-French 3-Factor asset pricing model data.
*)

#r "nuget: NovaSBE.Finance"
#r "nuget: NovaSBE.Finance, 0.4.0"

open NovaSBE.Finance
open NovaSBE.Finance.French
Expand Down Expand Up @@ -453,4 +453,4 @@ let hmlAnnualizedReturn =
hmlVolManaged
|> List.averageBy (fun x -> x.Return)
252.0 * dailyRet
hmlAnnualizedReturn |> should (equalWithin 0.02) 8.18
hmlAnnualizedReturn |> should (equalWithin 0.02) 8.15
6 changes: 3 additions & 3 deletions docs/assignments/assignment-performance-evaluation.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ open FsUnitTyped
For the assignment
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: NovaSBE.Finance, 0.2.0-beta1"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: MathNet.Numerics"
#r "nuget: MathNet.Numerics.FSharp"
#r "nuget: Plotly.NET, 3.*"
Expand Down
6 changes: 3 additions & 3 deletions docs/assignments/assignment-signal-portfolio.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ open FsUnitTyped
For the assignment
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: NovaSBE.Finance, 0.2.0-beta1"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: MathNet.Numerics"
#r "nuget: MathNet.Numerics.FSharp"
#r "nuget: Plotly.NET, 3.*"
Expand Down
4 changes: 2 additions & 2 deletions docs/assignments/signal-exploration.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ All work that you submit should be your own. Make use of the course resources an
Load libraries.
*)

#r "nuget: FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"
#r "nuget: MathNet.Numerics"
Expand Down
3 changes: 2 additions & 1 deletion docs/calls-nn.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ index: 100
// !bash <(curl -Ls https://raw.githubusercontent.com/gbaydin/scripts/main/colab_dotnet6.sh)
#endif // IPYNB

(***do-not-eval***)
(***do-not-eval-file***)

#r "nuget:FSharp.Stats"
// Use lite if you're on Apple Silicon
//#r "nuget:DiffSharp-lite,1.0.7"
Expand Down
2 changes: 1 addition & 1 deletion docs/football-1-download-data.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ For the **Football Players' Exercises** we are trying to scrape data from [Sport
Both type providers are located in `FSharp.Data` assembly. To use it we need to load and open `FSharp.Data`.
*)

#r "nuget: FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"
open FSharp.Data

(**
Expand Down
6 changes: 3 additions & 3 deletions docs/football-collection-functions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ let H3 = makeNumberedHeading "h3"
### Reference needed nuget packages and open namespaces
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"

open FSharp.Data
open FSharp.Stats
Expand Down Expand Up @@ -799,7 +799,7 @@ playerStatsTable
(**
### 9 Seq.stDev
For `Seq.stDev` to work, we loaded the `FSharp.Stats nuget` (`#r "nuget: FSharp.Stats"`).
For `Seq.stDev` to work, we loaded the `FSharp.Stats nuget` (`#r "nuget: FSharp.Stats, 0.5.0"`).
This nuget contains the standard deviation function.
Besides this we also opened the module `FSharp.Stats` (`open FSharp.Stats`).
[FSharp.Stats documentation](https://fslab.org/FSharp.Stats/)
Expand Down
4 changes: 2 additions & 2 deletions docs/football-plotting.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ let H3 = makeNumberedHeading "h3"
### Reference needed nuget packages and open namespaces
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"

Expand Down
2 changes: 1 addition & 1 deletion docs/football-tuples-and-records.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let H3 = makeNumberedHeading "h3"
## Import the Football Players Data from the Csv File
*)

#r "nuget:FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"
open FSharp.Data

(**
Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ let stddev xs =
But it is also convenient to use the [FSharp.Stats](https://fslab.org/FSharp.Stats/)
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Stats, 0.5.0"

open FSharp.Stats

Expand Down
9 changes: 4 additions & 5 deletions docs/mveComparisons.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ index: 8
## Loading Fama and French data
*)

#r "nuget: FSharp.Data"
#r "nuget: NovaSBE.Finance"
#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"

open System
open FSharp.Data
open FSharp.Stats
open FSharp.Stats.Distributions.ContinuousDistribution
open Plotly.NET
open NovaSBE.Finance.French

Expand Down Expand Up @@ -55,7 +54,7 @@ let seed = 99
Random.SetSampleGenerator(Random.RandThreadSafe(seed))

// Let's start with this sample of returns
let rnorm = normal 0.01 1.0
let rnorm = Distributions.Continuous.Normal.Init 0.01 1.0
let testData =
[| for i=1 to 100 do
{ Date = DateTime(2010, 1, 1).AddDays(float i);
Expand Down
6 changes: 3 additions & 3 deletions docs/optimization.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ index: 12
[![Notebook](img/badge-notebook.svg)]({{root}}/{{fsdocs-source-basename}}.ipynb)
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data,5.*"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: DiffSharp-lite"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"
#r "nuget: Quotes.YahooFinance, 0.0.5"
#r "nuget: NovaSBE.Finance"
#r "nuget: NovaSBE.Finance, 0.4.0"

open System
open FSharp.Data
Expand Down
6 changes: 3 additions & 3 deletions docs/performance-evaluation.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ The APT way of thinking is less restrictive than economically motivated equilibr
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Data"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"
#r "nuget: NovaSBE.Finance"
#r "nuget: NovaSBE.Finance, 0.4.0"

(** *)
#r "nuget: Quotes.YahooFinance, 0.0.5"
Expand Down
2 changes: 1 addition & 1 deletion docs/portfolio-statistics.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ For next time: Portfolio Variance and Leverage
## Leverage
*)

#r "nuget: FSharp.Stats"
#r "nuget: FSharp.Stats, 0.5.0"

open FSharp.Stats
open FSharp.Stats.Correlation
Expand Down
6 changes: 3 additions & 3 deletions docs/premiums.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ index: 14
*)

#r "nuget: NovaSBE.Finance,0.3.*-*"
#r "nuget: FSharp.Stats,0.4.*"
#r "nuget: FSharp.Data,5.*-*"
#r "nuget: NovaSBE.Finance, 0.4.0"
#r "nuget: FSharp.Stats, 0.5.0"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: Plotly.NET, 3.*"
#r "nuget: Plotly.NET.Interactive, 3.*"
#r "nuget: ExcelProvider,2.*"
Expand Down
2 changes: 1 addition & 1 deletion docs/project/.assign-project-signals.fsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#r "nuget:FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"
open System
open System.IO

Expand Down
2 changes: 1 addition & 1 deletion docs/project/.prep-project-data.fsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#r "nuget: FSharp.Data"
#r "nuget: FSharp.Data, 5.0.2"
#r "nuget: FSharp.Collections.ParallelSeq"

#time "on"
Expand Down
Loading

0 comments on commit 12483fe

Please sign in to comment.