tool9
=====
A tool for portfolio management analysis
based on the codes for master thesis:
"How bond risk affects risk parity portfolios"
provides
------
classes
- RRP: construct a risk parity portfolio. (Typo, should be RPP but not RRP)
functions
- period: return the effective date period of one column
- describe: return basic statistical descriptions
- and so on
construct a risk parity portfolio. (Typo, should be RPP but not RRP)
construct a risk parity portfolio ('RPP') or fixed ratio portfolio ('FRP')
(when ratio_fixed provided).
- must input logr, reset_months.
- if use FRP, input ratio_fixed.
- if use RRP, input risk, corr(more than 2 assets, UnfinishedFeature).
- if use fixed leverate, input leverage_fixed.
- if have target risk, input target_risk, risk and corr.
- first_reset_date and leverage_limit is optional.
- use new_[input] to renew input and construct new portfolio.
Attributes:
[input]
- ratio_fixed: list, a fixed ratio of assets, construct FRP if provided.
- logr: log return of assets, pd.DataFrame with column be asset name,
index be datetime.
- risk: risk of assets, pd.DataFrame with column name be risk name,
index be datetime.
- corr: correlation between assets for each observation, pd.DataFrame
with column name be asset name, outer index be datetime, inner
index be asset name.
- first_reset_date: string or datetime, reset at the begining of day.
- reset_months: int, number of months between two reset date.
- reset_shift_mode: determine whether take the first trading day after or
before the planed reset date as real reset date.
- target_risk: int, if target_risk is provided, the leverage of portfolio
will be set so that portfolio risk will equal to the target_risk.
- leverage_fixed: number, !!if provided, the leverage of portfolio will
not change and always be it.
- leverage_limit: number, if provided, leverage won't be higher than it.
- get_actual: default False, get actual ratio, portfolio risk and actual
portfolio risk.
[output]
- sample_month_interval: total months in sample period.
- reset_times: times of reset.
- reset_date: pd.DatetimeIndex, the date of reset dates.
- logr_p: portfolio log return, pd.DataFrame with column name be asset
name, index be datetime.
- ratio: retio of assets, pd.DataFrame with column name be asset name,
index be datetime.
- ratio_actual: actual ratio of assets, pd.DataFrame with column name be
asset name, index be datetime.
- risk_p: portfolio risk, pd.DataFrame with column name be 'portfolio',
index be datetime.
- risk_p_actual: actual portfolio risk, pd.DataFrame with column name be
'portfolio', index be datetime.
- leverage: leverage of portfolio, pd.DataFrame with column name be
'leverage', index be datetime.
return the effective date period of one column
period(col, data)
return: [start, end]
describe(col, data)
(no included)
ni(col, data)
log returns of protfolio, main input. because of the characteristic of logarithm, all the performances reflect the relatively performances in log returns, but not absolute performances.
(sum log return)
profit(lr)
(yearly sharpe ratio (no risk free rate) for returns)
(not log returns here)
sr(lr)
(value at risk for log returns)
var(lr, *level)
(expected shortfall for log returns)
es(lr, *level)
(cumulative log returns drawdown)
attention: only this function returns a series
drawdown(lr)
(maximum cumulative log returns drawdown)
maxdrawdown(lr)
(all the performances for log returns)
performance(lr, level)
portfolio_risk(data_corr, data_vol, data_ratio)
period_4_plot(start, end, n)