A minimalist Julia package for working with simple portfolios of financial assets. Really only provides the barebones.
Example without rebalancing.
using FinancialPortfolios, DataFrames, Dictionaries
stockA = 0.06/12 .+ 0.1/sqrt(12) .* randn(120)
stockB = 0.01/12 .+ 0.02/sqrt(12) .* randn(120)
df = DataFrame(stockA=stockA,stockB=stockB)
FP = FinancialPortfolio(dictionary(["stockA"=>0.8,"stockB"=>0.2])) # initial portfolio weights
df.portfolioreturns = [update!(FP,r) for r in eachrow(df)]
df
FP
Example with rebalancing every January.
using FinancialPortfolios, DataFrames, Dictionaries
months = repeat(1:12,10)
stockA = 0.06/12 .+ 0.1/sqrt(12) .* randn(120)
stockB = 0.01/12 .+ 0.02/sqrt(12) .* randn(120)
df = DataFrame(month=months,stockA=stockA,stockB=stockB)
FP = FinancialPortfolio(dictionary(["stockA"=>0.8,"stockB"=>0.2])) # initial portfolio weights
function runportfolio!(FP0,df0)
T = nrow(df0)
df0[!,:portfolioreturns] = missings(Float64,T)
FPreb = copy(FP0)
for row in eachrow(df0)
if row.month == 1 # rebalances each January
FP0 = copy(FPreb)
end
row.portfolioreturns = update!(FP0,row)
end
return FP0
end
runportfolio!(FP,df)