cyberkyne commited on
Commit
1a56c89
Β·
verified Β·
1 Parent(s): 0fcb14a

Upload 22 files

Browse files
Dockerfile CHANGED
@@ -22,6 +22,7 @@ RUN wget -q https://julialang-s3.julialang.org/bin/linux/x64/1.11/julia-${JULIA_
22
  ENV JULIA_DEPOT_PATH=/app/.julia
23
  ENV JULIA_NUM_THREADS=4
24
  ENV JULIA_PROJECT=/app/src
 
25
 
26
  WORKDIR /app
27
 
@@ -32,12 +33,7 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt
32
  # ── Copy project files ────────────────────────────────
33
  COPY . .
34
 
35
- # ── Step 1: Resolve + precompile Julia packages ───────
36
- # Use a script file β€” avoids both Docker keyword parsing issues
37
- # and REPL-mode error isolation of the printf pipe approach.
38
- RUN julia --project=/app/src /app/src/setup_pkg.jl
39
-
40
- # ── Step 2: Warmup β€” JIT-compile all hot paths ────────
41
  RUN julia --project=/app/src /app/src/warmup.jl
42
 
43
  # ── Step 3: Pre-warm juliacall Python↔Julia bridge ────
@@ -48,6 +44,7 @@ ENV GRADIO_SERVER_NAME=0.0.0.0
48
  ENV GRADIO_SERVER_PORT=7860
49
  ENV JULIA_PROJECT=/app/src
50
  ENV JULIA_DEPOT_PATH=/app/.julia
 
51
 
52
  EXPOSE 7860
53
  CMD ["python", "app.py"]
 
22
  ENV JULIA_DEPOT_PATH=/app/.julia
23
  ENV JULIA_NUM_THREADS=4
24
  ENV JULIA_PROJECT=/app/src
25
+ ENV JULIA_BINDIR=/usr/local/julia/bin
26
 
27
  WORKDIR /app
28
 
 
33
  # ── Copy project files ────────────────────────────────
34
  COPY . .
35
 
36
+ # ── Step 1: Warmup β€” JIT-compile all hot paths ────────
 
 
 
 
 
37
  RUN julia --project=/app/src /app/src/warmup.jl
38
 
39
  # ── Step 3: Pre-warm juliacall Python↔Julia bridge ────
 
44
  ENV GRADIO_SERVER_PORT=7860
45
  ENV JULIA_PROJECT=/app/src
46
  ENV JULIA_DEPOT_PATH=/app/.julia
47
+ ENV JULIA_BINDIR=/usr/local/julia/bin
48
 
49
  EXPOSE 7860
50
  CMD ["python", "app.py"]
app.py CHANGED
@@ -58,7 +58,7 @@ def run_extraction(pdf_files, progress=gr.Progress()):
58
  hf_files = []
59
 
60
  for i, pdf_file in enumerate(pdf_files):
61
- path = Path(pdf_file.name)
62
  progress(i/len(pdf_files), desc=f"{path.name}")
63
  log.append(f"\nπŸ“– [{i+1}/{len(pdf_files)}] {path.name}")
64
  try:
 
58
  hf_files = []
59
 
60
  for i, pdf_file in enumerate(pdf_files):
61
+ path = Path(pdf_file.name if hasattr(pdf_file, "name") else pdf_file)
62
  progress(i/len(pdf_files), desc=f"{path.name}")
63
  log.append(f"\nπŸ“– [{i+1}/{len(pdf_files)}] {path.name}")
64
  try:
pipeline/julia_bridge.py CHANGED
@@ -37,6 +37,10 @@ def _init_julia():
37
  return
38
 
39
  logger.info("Initializing Julia runtime…")
 
 
 
 
40
  try:
41
  from juliacall import Main as jl
42
  _jl = jl
 
37
  return
38
 
39
  logger.info("Initializing Julia runtime…")
40
+ # Tell juliapkg to use the system Julia installed in the Docker image
41
+ os.environ.setdefault("JULIA_BINDIR", "/usr/local/julia/bin")
42
+ os.environ.setdefault("JULIA_PROJECT", str(JULIA_SRC))
43
+ os.environ.setdefault("JULIA_DEPOT_PATH", "/app/.julia")
44
  try:
45
  from juliacall import Main as jl
46
  _jl = jl
src/Optimizer.jl CHANGED
@@ -92,11 +92,18 @@ function _run(sig_fn,run_bt,cfg,o,h,l,c,v,params,tf)
92
  try
93
  sigs = sig_fn(o,h,l,c,v,params)
94
  return run_bt(o,h,l,c,v,sigs,tf,cfg)
95
- catch e
96
- # Return an invalid result
97
- r = run_bt(o,h,l,c,v,zeros(Int,length(c)),tf,cfg)
98
- r.is_valid = false; r.error_msg = string(e)
99
- return r
 
 
 
 
 
 
 
100
  end
101
  end
102
 
 
92
  try
93
  sigs = sig_fn(o,h,l,c,v,params)
94
  return run_bt(o,h,l,c,v,sigs,tf,cfg)
95
+ catch e1
96
+ # Strategy failed β€” run with flat signals to get a valid struct back
97
+ try
98
+ r = run_bt(o,h,l,c,v,zeros(Int,length(c)),tf,cfg)
99
+ r.is_valid = false
100
+ r.error_msg = string(e1)
101
+ return r
102
+ catch e2
103
+ # Even the fallback failed β€” return manually constructed invalid result
104
+ return run_bt(o[1:2],h[1:2],l[1:2],c[1:2],v[1:2],
105
+ zeros(Int,2),tf,cfg) # will hit n<50 guard β†’ is_valid=false
106
+ end
107
  end
108
  end
109
 
src/Project.toml CHANGED
@@ -1,6 +1,2 @@
1
- [deps]
2
- Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3
- Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
4
-
5
  [compat]
6
  julia = "1.11"
 
 
 
 
 
1
  [compat]
2
  julia = "1.11"
src/QuantEngine.jl CHANGED
@@ -27,7 +27,7 @@ export
27
  momentum, roc, highest, lowest,
28
  crossover, crossunder,
29
  # Engine
30
- BacktestConfig,
31
  # High-level
32
  full_backtest_pipeline
33
 
 
27
  momentum, roc, highest, lowest,
28
  crossover, crossunder,
29
  # Engine
30
+ BacktestConfig, run_backtest,
31
  # High-level
32
  full_backtest_pipeline
33
 
src/warmup.jl CHANGED
@@ -1,3 +1,5 @@
 
 
1
  push!(LOAD_PATH, @__DIR__)
2
  include(joinpath(@__DIR__, "QuantEngine.jl"))
3
  using .QuantEngine
@@ -5,29 +7,40 @@ using Statistics, Random
5
 
6
  println("Warming up all Julia hot paths...")
7
 
8
- n=500; c=100.0.*exp.(cumsum(randn(n).*0.005))
9
- h=c.*(1.0.+abs.(randn(n)).*0.005); l=c.*(1.0.-abs.(randn(n)).*0.005)
10
- o=c.*(1.0.+randn(n).*0.002); v=abs.(randn(n)).*2000.0.+1000.0
 
 
 
11
 
12
- _=sma(c,20); println(" sma βœ“")
13
- _=ema(c,20); println(" ema βœ“")
14
- _=rsi(c,14); println(" rsi βœ“")
15
- _=macd(c); println(" macd βœ“")
16
- _=atr(h,l,c,14); println(" atr βœ“")
17
- _=bbands(c,20,2.0); println(" bbands βœ“")
18
- _=donchian(h,l,20); println(" donchian βœ“")
19
- _=adx(h,l,c,14); println(" adx βœ“")
20
- _=stoch(h,l,c); println(" stoch βœ“")
21
- _=zscore(c,20); println(" zscore βœ“")
22
- println("All indicators warmed βœ“")
 
 
 
 
 
 
23
 
24
- code = """
 
 
25
  function get_param_grid() :: Dict{String, Vector{Float64}}
26
  return Dict("period" => [10.0, 20.0, 30.0])
27
  end
28
  function generate_signals(open_p, high, low, close, volume, params)
29
- n = length(close)
30
- p = Int(round(get(params, "period", 20.0)))
31
  ma = sma(close, p)
32
  signals = zeros(Int, n)
33
  for i in (p+1):n
@@ -37,11 +50,13 @@ function generate_signals(open_p, high, low, close, volume, params)
37
  return signals
38
  end
39
  """
 
 
 
 
 
 
 
 
40
 
41
- result = full_backtest_pipeline(
42
- code, "WarmupTest",
43
- o, h, l, c, v, "1h", "TEST";
44
- n_windows=2, max_combos=3, min_trades=1,
45
- )
46
- println("full_backtest_pipeline: is_valid=$(result[\"is_valid\"]) viable=$(result[\"is_viable\"])")
47
- println("\nβœ… Julia warmup complete β€” all hot paths compiled.")
 
1
+ # warmup.jl β€” JIT-compile all hot paths at build time.
2
+ # Failures are non-fatal: print warning and exit 0.
3
  push!(LOAD_PATH, @__DIR__)
4
  include(joinpath(@__DIR__, "QuantEngine.jl"))
5
  using .QuantEngine
 
7
 
8
  println("Warming up all Julia hot paths...")
9
 
10
+ n=500
11
+ c=100.0.*exp.(cumsum(randn(n).*0.005))
12
+ h=c.*(1.0.+abs.(randn(n)).*0.005)
13
+ l=c.*(1.0.-abs.(randn(n)).*0.005)
14
+ o=c.*(1.0.+randn(n).*0.002)
15
+ v=abs.(randn(n)).*2000.0.+1000.0
16
 
17
+ # Warm indicators
18
+ for (name, fn) in [
19
+ ("sma", ()-> sma(c,20)),
20
+ ("ema", ()-> ema(c,20)),
21
+ ("rsi", ()-> rsi(c,14)),
22
+ ("macd", ()-> macd(c)),
23
+ ("atr", ()-> atr(h,l,c,14)),
24
+ ("bbands", ()-> bbands(c,20,2.0)),
25
+ ("donchian",()-> donchian(h,l,20)),
26
+ ("adx", ()-> adx(h,l,c,14)),
27
+ ("stoch", ()-> stoch(h,l,c)),
28
+ ("zscore", ()-> zscore(c,20)),
29
+ ]
30
+ try; fn(); println(" $name βœ“")
31
+ catch e; println(" $name βœ— $e"); end
32
+ end
33
+ println("Indicators warmed βœ“")
34
 
35
+ # Warm full pipeline (non-fatal)
36
+ try
37
+ code = """
38
  function get_param_grid() :: Dict{String, Vector{Float64}}
39
  return Dict("period" => [10.0, 20.0, 30.0])
40
  end
41
  function generate_signals(open_p, high, low, close, volume, params)
42
+ n = length(close)
43
+ p = Int(round(get(params, "period", 20.0)))
44
  ma = sma(close, p)
45
  signals = zeros(Int, n)
46
  for i in (p+1):n
 
50
  return signals
51
  end
52
  """
53
+ result = full_backtest_pipeline(
54
+ code, "WarmupTest", o, h, l, c, v, "1h", "TEST";
55
+ n_windows=2, max_combos=3, min_trades=1,
56
+ )
57
+ println("Pipeline warmup: is_valid=$(result[\"is_valid\"]) βœ“")
58
+ catch e
59
+ println("Pipeline warmup skipped (non-fatal): $e")
60
+ end
61
 
62
+ println("\nβœ… Julia warmup complete.")
 
 
 
 
 
 
src/warmup_bridge.py CHANGED
@@ -9,6 +9,7 @@ import sys
9
 
10
  os.environ["JULIA_PROJECT"] = "/app/src"
11
  os.environ["JULIA_DEPOT_PATH"] = "/app/.julia"
 
12
 
13
  print("Pre-warming juliacall bridge...")
14
  try:
 
9
 
10
  os.environ["JULIA_PROJECT"] = "/app/src"
11
  os.environ["JULIA_DEPOT_PATH"] = "/app/.julia"
12
+ os.environ["JULIA_BINDIR"] = "/usr/local/julia/bin"
13
 
14
  print("Pre-warming juliacall bridge...")
15
  try: