TimeseriesAnalysis#
- class qf_lib.analysis.timeseries_analysis.timeseries_analysis.TimeseriesAnalysis(returns_timeseries: QFSeries, frequency: Frequency)[source]#
Bases:
TimeseriesAnalysisDTOUsed for analysing a timeseries of returns. Calculates and aggregates different statistics of the timeseries, It contains the following fields:
returns_tms - series of simple returns
frequency
start_date
end_date
total_return
cagr - annualised return
annualised_vol
annualised_upside_vol
annualised_downside_vol
sharpe_ratio
omega_ratio
calmar_ratio
gain_to_pain_ratio
sortino_ratio
cvar - 5% CVaR expressed related to the specified frequency
annualised_cvar - annualised 5% CVaR
max_drawdown - maximum drawdown
avg_drawdown - average of the whole underwater chart
avg_drawdown_duration - average duration of a drawdown
best_return
worst_return
vavg_positive_return
avg_negative_return
skewness
kurtosis
kelly
- Parameters:
- populate_table(table: Table, name=None) None[source]#
Adds the data calculated in this analysis to the specified table. The table may be brand new or contain other analyses of the same kind.
- Parameters:
table – The table to add the data to.
name – Name to give this analysis in the columns.
- static table_for_df(df: QFDataFrame, frequency: Frequency = Frequency.DAILY) str[source]#
Returns a table similar to the one below:
Analysed period: start_date - end_date, using frequency data Name total_ret cagr vol up_vol down_vol … Asset1 63.93 28.27 19.15 14.06 14.35 … Asset2 66.26 29.19 20.74 14.86 15.54 … Asset3 66.26 29.19 20.74 14.86 15.54 … … … … … … … …
- Parameters:
df – DataFrame of returns or prices of assets to be analysed
frequency – (optional) frequency of the returns or price sampling in the DataFrame. By default daily frequency is used
- static values_in_table(ta_collection: TimeseriesAnalysis | Sequence[TimeseriesAnalysis], asset_names: None | str | Sequence[str] = None) str[source]#
Returns a string with all the measures in a form of table of the following format:
Asset1 Asset2 …
Nice_name1 value11 value21 … unit1 Nice_name2 value12 value22 … unit2 … … … … unitI Nice_nameN value12 value22 … unitN
- Parameters:
ta_collection – single TimeseriesAnalysis object or a collection of TimeseriesAnalysis objects
asset_names – names of assets corresponding to objects in ta_collection