FinancialPortfolios.FinancialPortfolios
— ModuleFinancialPortfolios
A minimalist Julia package for working with simple portfolios of financial assets.
FinancialPortfolios.FinancialPortfolio
— TypeFinancialPortfolio
A (possibly named) collection of portfolio weights. Weights can be a dictionary-like object matching asset identifiers with weights or just a vector of weights.
Example
w = [0.5, 0.25, 0.25]
FP_vec = FinancialPortfolio(w)
nm = ["a", "b", "c"]
plain_dict = Dict(Iterators.zip(nm,w))
FP_plaindict = FinancialPortfolio(plain_dict)
using Dictionaries
fancy_dict = dictionary(plain_dict)
FP_fancydict = FinancialPortfolio(fancy_dict)
Base.keys
— Methodkeys(fp::FinancialPortfolio)
Recover the names or identifiers of the assets in the portfolio.
FinancialPortfolios.checkupdate!
— Methodcheckupdate!(fp::FinancialPortfolio,ret)
Updates the weights of the portfolio in place. Returns the period portfolio return.
If ret
does not contain an entry for one of the existing portfolio positions, this function assumes the position was closed.
positions
must be an object like Dict
or Dictionaries.AbstractDictionary
.
Example
w = Dict(["stockA"=>0.8,"stockB"=>0.2])
r = Dict(["stockA"=>0.1])
FP = FinancialPortfolio(w)
checkupdate!(FP,r)
FP
FinancialPortfolios.copyandnormalize
— MethodFinancialPortfolios.copyandnormalize(x)
Normalize portfolio weights to sum to 1. Used during construction.
FinancialPortfolios.normalize!
— MethodFinancialPortfolios.normalize!(fp::FinancialPortfolio)
Normalize portfolio weights to sum to 1. Used during update!
.
FinancialPortfolios.portfolioreturn
— Methodportfolioreturn(fp::FinancialPortfolio,ret)
Compute the weighted portfolio return. If the portfolio weights have names or identifiers, the returns should as well. The portfolio is allowed to contain only a subset of the supplied asset returns, but not the other way around.
Example
w = [0.5, 0.25, 0.25]
r = [0.1, 0.1, -0.1]
FP = FinancialPortfolio(w)
portfolioreturn(FP,r)
FinancialPortfolios.positions
— Methodpositions(fp::FinancialPortfolio)
Recover the weights of the assets in the portfolio (as a fraction of total value).
FinancialPortfolios.update!
— Methodupdate!(fp::FinancialPortfolio,ret)
Updates the weights of the portfolio in place. Returns the period portfolio return.
The portfolio is allowed to contain only a subset of the supplied asset returns, but not the other way around.
Example
w = [0.5, 0.25, 0.25]
r = [0.1, 0.1, -0.1]
FP = FinancialPortfolio(w)
update!(FP,r)
FP