This file contains hidden or 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
| using Distributions | |
| using Downloads | |
| using DelimitedFiles | |
| using MarketData | |
| using Dates | |
| """ | |
| business_days(start_date, end_date) |
This file contains hidden or 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
| ############################################################################### | |
| # Martingales by simulation (Julia) | |
| # | |
| # This script illustrates several facts discussed in lecture: | |
| # | |
| # (1) Brownian motion W_t has independent increments and is a martingale. | |
| # (2) Additive Brownian stock model S_t = S_0 + μ t + σ W_t. | |
| # (3) The conditional expectation (filtered value) | |
| # V_t = E[(S_T - K)^+ | 𝔽_t] | |
| # is a martingale in t (tower property). |
This file contains hidden or 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
| using Random | |
| rng = MersenneTwister(0) | |
| n = 2000 | |
| # True SEM: X -> Y -> Z | |
| true_adj = Bool[ | |
| 0 1 0 | |
| 0 0 1 | |
| 0 0 0] |
This file contains hidden or 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
| using DelimitedFiles, GLMakie, Distributions | |
| # Black-Scholes formula | |
| normcdf(x) = cdf(Normal(), x) | |
| function blcall(S0, K, r, T, σ) | |
| B = exp(r*T) | |
| F = S0 * B | |
| d1 = log(F/K) / (σ*sqrt(T)) + σ*sqrt(T)/2 | |
| (F*normcdf(d1) - K*normcdf((d1 - σ*sqrt(T))))/B | |
| end |
This file contains hidden or 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
| # Solving the problem in https://bsky.app/profile/p-hunermund.com/post/3lci6xojlmt25 | |
| using CausalInference, Graphs | |
| # defining the graphical do-operator we need here | |
| function do!(g, v) | |
| for u in collect(inneighbors(g, v)) | |
| rem_edge!(g, u, v) | |
| end | |
| end |
This file contains hidden or 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
| using CausalInference | |
| using Associations: CorrTest, PC, Associations | |
| using Test | |
| using Graphs: SimpleDiGraph, Graphs, complete_graph | |
| using StableRNGs | |
| using LinearAlgebra, Random, Distributions | |
| using CausalInference: pcalg, gausscitest, CausalInference | |
| using Combinatorics | |
| using Tables: table, istable | |
| rng = StableRNG(123) |
This file contains hidden or 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
| using CausalInference, Graphs | |
| V = [:U, :T, :P, :O] | |
| ι = Dict(v=>i for (i,v) in enumerate(V)) | |
| g = digraph([1=>3, 2=>3, 3=>4, 2=>4, 1=>4]) | |
| # Can estimate total effect T=>O without observing U? | |
| u = ι[:T] | |
| v = ι[:O] | |
| ∅ = Set{Int}() |
This file contains hidden or 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
| using Kalman | |
| using Kalman.GaussianDistributions | |
| using Statistics, LinearAlgebra | |
| # prior for time 0 | |
| x0 = 0.0 | |
| P0 = floatmax(x0) | |
| # observation operator | |
| H = 1.0 |
This file contains hidden or 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
| using GLMakie | |
| using Random | |
| # mixture distribution | |
| X(c) = rand() < c ? sqrt(rand()) : 1 - sqrt(rand()) | |
| # sample | |
| Random.seed!(1); | |
| A = [0:0.01:1;; X.(0:0.01:1)]; |
This file contains hidden or 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
| 0.0 0.0 | |
| -0.032984387220723596 0.030216400626819087 | |
| 0.005532055967160396 -0.06303492443179701 | |
| 0.04716487617405366 0.06151822897388728 | |
| -0.08816371845816047 -0.01559492041364278 | |
| 0.0844812855043274 -0.05374007858781831 | |
| -0.02848102330289795 0.10594798706320867 | |
| -0.054631054889518714 -0.10518877181328493 | |
| 0.1190544569384441 0.04347849672678073 | |
| -0.12429436989984163 0.05130690904254036 |
NewerOlder