JuliaAcademy / JuliaAcademy/JuliaTutorials

Julia module memory and global variable issue

Open
#95 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
1.4k
Forks
655
PR merge metrics
No merged PRs in 30d

Description

How to add memory feature in this reserve calculation or add a global variable type in a Julia module structure-

Code-
function reserves_calc(projection::Projection)
max_t = policy_term(projection)* 12
annual_disc_rate = 0.08
#monthly_disc_rate = maximum(BasicTerm_ME.disc_rate(t,projection)) #0.0064

    res_l = zeros(max_t + 1)  # Preallocate array for inc_in_res

    for t in max_t:-1:0
        if t == max_t
            res_l[t+1] = 0#BasicTerm_ME.reserves(t, projection)
        elseif t > proj_len(projection)[] 
            res_l[t+1] = 0.0
        else
            res_l[t+1] = max(-10000000,(val_net_cashflow(t+1, projection) .+ res_l[t+2]) / (1 .+ maximum(disc_rate(t,projection))))#BasicTerm_ME.reserves(t, projection) #- BasicTerm_ME.reserves((t-1), projection)
        end
    end
    return res_l
end


function reserves(t,projection)#, projection::Projection)
    x = reserves_calc(projection)
    return x[t]
end    

I want to use the results of res_l array in reserves function without running reserves_calc function each time.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the reserves_calc and reserves functions shown in the issue, focusing on how res_l is created and accessed across calls. Check the Julia module scope and global-variable behavior relevant to this calculation. Done means reserves can reuse the computed res_l results without rerunning reserves_calc for every call, with the chosen state behavior demonstrated.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.