-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgbm.jl
More file actions
29 lines (22 loc) · 851 Bytes
/
Copy pathgbm.jl
File metadata and controls
29 lines (22 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Random
using Statistics
# Function to calculate percent returns
function returns(raw::Vector{Float64})
return [(raw[i] - raw[i-1]) / raw[i-1] for i in 2:length(raw)]
end
function vscore(raw::Vector{Float64}, OBS::Int=60, EPOCH::Int=5000, EXT::Int=20)
v = Float64[] # Result vector
for t in OBS:length(raw)-1
temp = raw[t+1-OBS : t+1]
ret = returns(temp)
s0 = temp[end] #raw value at time t
μ, σ = mean(ret), std(ret)
drift = μ + 0.5 * σ^2
# Simulate paths using broadcasting
noise = cumsum(randn(EPOCH, EXT), dims=2) # cumsum first
paths = s0 .* exp.(σ .* noise .+ drift .* (1:EXT)') # Then scale and apply drift
sum_exceed = count(>(s0), paths)
push!(v, sum_exceed / (EPOCH * EXT))
end
return (v .- mean(v)) ./ std(v)
end