Adding rows

You should always quote your code here with backticks ```, like this:

m = 1
n = R[1:30]
for t = [1:33][1]
local n
m = m + t
n = t
R2 = sum(R[m])
end
printmat(R2)

It makes it much easier to read :grinning: Have a look at this thread when you get a chance.

I’m not sure I’m following but if you have some returns data in a Matrix R and then the names of the assets in a vector assets, you can do this:

# Create fake data
R = rand(Float64, (50,30))
assets = ["company$i" for i in 1:30]

rets = [(company=i[2], ret=sum(i[1][1:33])) for i in zip(eachcol(R), assets)]

julia> sorted_assets = [sort(rets, by=last, rev=true)[i][1] for i in 1:30]
30-element Array{String,1}:
 "company18"
 "company11"
 "company6"
 "company29"
 "company7"
 "company5"
 "company1"
 "company30"
 â‹®
 "company15"
 "company3"
 "company26"
 "company21"
 "company20"
 "company2"
 "company22"
 "company14"

That being said, I would probably use DataFrames.jl to do this kind of work. The documentation for that package is good and it will probably allow you to get up and running with these kinds of operations faster than if you just use base Julia.

2 Likes