https://github.com/tbeason/financialportfolios.jl
Julia package for working with simple portfolios of financial assets
https://github.com/tbeason/financialportfolios.jl
finance julia julialang portfolio-management
Last synced: 6 months ago
JSON representation
Julia package for working with simple portfolios of financial assets
- Host: GitHub
- URL: https://github.com/tbeason/financialportfolios.jl
- Owner: tbeason
- License: other
- Created: 2020-04-30T06:47:16.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-12T16:18:09.000Z (almost 4 years ago)
- Last Synced: 2025-05-07T04:02:40.988Z (6 months ago)
- Topics: finance, julia, julialang, portfolio-management
- Language: Julia
- Homepage:
- Size: 18.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# FinancialPortfolios.jl

[](https://github.com/tbeason/FinancialPortfolios.jl/actions?query=workflow%3ACI)
[](http://codecov.io/github/tbeason/FinancialPortfolios.jl?branch=master)A minimalist Julia package for working with simple portfolios of financial assets. Really only provides the barebones.
### Example
Example without rebalancing.
```julia
using FinancialPortfolios, DataFrames, DictionariesstockA = 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.
```julia
using FinancialPortfolios, DataFrames, Dictionariesmonths = 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 weightsfunction 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
endrunportfolio!(FP,df)
```