Skip to content

# igrigorik/linguist forked from github/linguist

Updated Julia language with lexer and added tests

• Loading branch information...
1 parent 52b9274 commit 4f0b45728703ba2eb3ae895fcaf2c19c0f1bcb37 pao committed Apr 4, 2012
Showing with 42 additions and 1 deletion.
1. +1 −1 lib/linguist/languages.yml
2. +37 −0 test/fixtures/stockcorr.jl
3. +4 −0 test/test_blob.rb
2 lib/linguist/languages.yml
 @@ -601,7 +601,7 @@ JavaScript: Julia: type: programming - lexer: Text only + lexer: Julia primary_extension: .jl extensions: - .jl
37 test/fixtures/stockcorr.jl
 @@ -0,0 +1,37 @@ +## Test case from Issue #445 + +#STOCKCORR - The original, unoptimised code that simulates two correlated assets +function stockcorr() + + ## Correlated asset information + CurrentPrice = [78. 102.] # Initial Prices of the two stocks + Corr = [1. 0.4; 0.4 1.] # Correlation Matrix + T = 500 # Number of days to simulate = 2years = 500days + n = 100000 # Number of simulations + dt = 1/250 # Time step (1year = 250days) + Div=[0.01 0.01] # Dividend + Vol=[0.2 0.3] # Volatility + + ## Market Information + r = 0.03 # Risk-free rate + + ## Define storages + SimulPriceA = zeros(T,n) # Simulated Price of Asset A + SimulPriceA[1,:] = CurrentPrice[1] + SimulPriceB = zeros(T,n) # Simulated Price of Asset B + SimulPriceB[1,:] = CurrentPrice[2] + + ## Generating the paths of stock prices by Geometric Brownian Motion + UpperTriangle=chol(Corr) # UpperTriangle Matrix by Cholesky decomposition + + for i = 1:n + Wiener = randn(T-1,2) + CorrWiener = Wiener*UpperTriangle + for j = 2:T + SimulPriceA[j,i] = SimulPriceA[j-1,i]*exp((r-Div[1]-Vol[1]^2/2)*dt+Vol[1]*sqrt(dt)*CorrWiener[j-1,1]) + SimulPriceB[j,i] = SimulPriceB[j-1,i]*exp((r-Div[2]-Vol[2]^2/2)*dt+Vol[2]*sqrt(dt)*CorrWiener[j-1,2]) + end + end + + return (SimulPriceA, SimulPriceB) +end
4 test/test_blob.rb
 @@ -427,6 +427,9 @@ def test_language # Kotlin assert_equal Language['Kotlin'], blob("Foo.kt").language + + # Julia: http://julialang.org/ + assert_equal Language['Julia'], blob("stockcorr.jl").language end def test_lexer @@ -438,6 +441,7 @@ def test_lexer assert_equal Lexer['Text only'], blob("README").lexer assert_equal Lexer['Tea'], blob("foo.tea").lexer assert_equal Lexer['vhdl'], blob("foo.vhd").lexer + assert_equal Lexer['Julia'], blob("stockcorr.jl").lexer end def test_shebang_script

#### 0 comments on commit `4f0b457`

Please sign in to comment.
Something went wrong with that request. Please try again.