简单的金融时间序列分析软件包。
openseries的Python项目详细描述
OpenSeries系列
这是一个项目,我们在这个项目中保留了对单个资产或一组资产执行时间序列分析的工具。在
要安装:
pip install openseries
要从“原始”字典构造OpenTimeSeries对象,请执行以下操作:
^{pr2}$或者使用设计用于获取Captor基金的NAV时间序列的类方法构造:
capirisc = 'SE0009807308'
bonds = OpenTimeSeries.from_open_nav(isin=capirisc)
并打印其几何年回报率和波动率:
print(f'Return : {bonds.geo_ret:.2%}\nVolatility: {bonds.vol:.2%}.')
要比较时间序列,OpenFrame的构造如下:
basket = OpenFrame([series, bonds])
用于处理时间序列的助手方法可以这样链接:
basket.trunc_frame().value_nan_handle().to_cumret()
一个新的投资组合时间序列可以从这样一个OpenFrame中构建:
basket.weights = [0.6, 0.4]
portfolio = OpenTimeSeries.from_df(basket.make_portfolio('porfolio'))
basket.add_timeseries(portfolio)
最后,绘图很简单。这将在浏览器窗口中绘制时间序列:
basket.plot_series(tick_fmt='.1%')
为了使用Pandas库中可用的一些工具,OpenTimeSeries和{a7}类有一个属性tsdf
,这是一个从列表dates
和values
中的原始数据构造的数据帧。在
目录
- Modules described
- Methods to construct OpenTimeSeries
- OpenTimeSeries non-numeric properties
- OpenFrame non-numeric properties
- Non-numeric properties for both classes
- OpenTimeSeries only methods
- OpenFrame only methods
- Methods for both classes
- Numeric properties for both classes
- Numeric methods with period arguments for both classes
这些是描述的文件/模块。
Module | Description |
---|---|
series.py | Defines the class OpenTimeSeries for managing and analyzing a single timeseries. The module also defines a function ^{ |
frame.py | Defines the class OpenFrame for managing a group of timeseries, and e.g. calculate a portfolio timeseries from a rebalancing strategy between timeseries. |
captor_open_api_sdk.py | A Python SDK to interact with the Captor Open API. |
datefixer.py | A module with date utilities. |
helpfilewriter.py | A module that allows printing a description of a Python class. |
openseries.json | The jsonschema of the OpenTimeSeries class. |
plotly_layouts.json | A module setting Plotly defaults used in the ^{ |
plotly_captor_logo.json | A module with a link to the Captor logo used in the ^{ |
risk.py | Module with methods used to calculate VaR, CVaR and drawdowns. |
sim_price.py | Module to simulate OpenTimeSeries from different stochastic processes. |
stoch_processes.py | Module to generate stochastic processes used in the ^{ |
sweden_holidays.py | Module that defines a Swedish business calendar. |
下面是用于构造OpenTimeSeries对象的类方法。
^{tb2}$此表中的非数字或“helper”属性仅适用于OpenTimeSeries类。
Attribute | type | Applies to | Description |
---|---|---|---|
^{ | ^{ | ^{ | Captor database identifier for the timeseries. |
^{ | ^{ | ^{ | Captor database identifier for the instrument associated with the timeseries. |
^{ | ^{ | ^{ | Dates of the timeseries. Not edited by any method to allow reversion to original. |
^{ | ^{ | ^{ | Values of the timeseries. Not edited by any method to allow reversion to original. |
^{ | ^{ | ^{ | Currency of the timeseries. Only used if conversion/hedging methods are added. |
^{ | ^{ | ^{ | Domestic currency of the user / investor. Only used if conversion/hedging methods are added. |
^{ | ^{ | ^{ | Indicates if series should be in its local currency or the domestic currency of the user. Only used if conversion/hedging methods are added. |
^{ | ^{ | ^{ | An identifier field. |
^{ | ^{ | ^{ | ISIN code of the associated instrument. If any. |
^{ | ^{ | ^{ | Field used in outputs. Derived from name as default. |
^{ | ^{ | ^{ | Field identifies a series of values, "Price(Close)", or a series of returns, "Return(Total)". |
此表中的非数字或“helper”属性仅适用于OpenFrame类。
Attribute | type | Applies to | Description |
---|---|---|---|
^{ | ^{ | ^{ | A list of the OpenTimeSeries that make up an OpenFrame. |
^{ | ^{ | ^{ | A list of the level zero column names in the OpenFrame pandas.DataFrame. |
^{ | ^{ | ^{ | A list of the level one column names in the OpenFrame pandas.DataFrame. |
^{ | ^{ | ^{ | Number of columns in the OpenFrame pandas.DataFrame. |
^{ | ^{ | ^{ | Weights used in the method ^{ |
^{ | ^{ | ^{ | First dates of all the series in the OpenFrame. |
^{ | ^{ | ^{ | Last dates of all the series in the OpenFrame. |
^{ | ^{ | ^{ | Number of items in each of the series in the OpenFrame. |
此表中是应用于OpenTimeSeries和OpenFrame类的非数字或“helper”属性。
Attribute | type | Applies to | Description |
---|---|---|---|
^{ | ^{ | ^{ | First date of the series. |
^{ | ^{ | ^{ | Last date of the series. |
^{ | ^{ | ^{ | Number of items in the series. |
^{ | ^{ | ^{ | The Pandas DataFrame which gets edited by the class methods. |
^{ | ^{ | ^{ | A calendar object used to generate business days. |
^{ | ^{ | ^{ | Date when the maximum drawdown occurred. |
^{ | ^{ | ^{ | The number of observations in an average year for all days in the data. |
^{ | ^{ | ^{ | Length of timeseries expressed as np.float64 fraction of a year with 365.25 days. |
此表中的方法仅适用于OpenTimeSeries类。
Method | Applies to | Description |
---|---|---|
^{ | ^{ | Class method that defines the ^{ |
^{ | ^{ | Method to validate the OpenTimeSeries input against the openseries.json jsonschema. |
^{ | ^{ | Method to export the OpenTimeSeries ^{ |
^{ | ^{ | Method to create the ^{ |
^{ | ^{ | Method to change the pandas.DataFrame column MultiIndex. |
^{ | ^{ | Adjusts the series performance with a ^{ |
此表中的方法仅适用于OpenFrame类。
Method | Applies to | Description |
---|---|---|
^{ | ^{ | Truncates the OpenFrame to a common period. |
^{ | ^{ | Adds a given OpenTimeSeries to the OpenFrame. |
^{ | ^{ | Deletes an OpenTimeSeries from the OpenFrame. |
^{ | ^{ | Calculates a new series that is the relative performance of two others. |
^{ | ^{ | Calculates a portfolio timeseries from series and weights. |
^{ | ^{ | Calculates and adds a series of rolling correlations between two other series. |
^{ | ^{ | Calculates the Beta and a Ordinary Least Squares fitted series from two others. |
此表中的方法同时适用于OpenTimeSeries和OpenFrame类。
Method | Applies to | Description |
---|---|---|
^{ | ^{ | Aligns the series dates to a business calendar. Defaults to Sweden. |
^{ | ^{ | Resamples the series to a specific frequency. |
^{ | ^{ | Fills ^{ |
^{ | ^{ | Replaces ^{ |
^{ | ^{ | Converts a return series into a value series or resets a value series to start from 1.0. |
^{ | ^{ | Converts a value series into a percentage return series. |
^{ | ^{ | Converts a value series into a series of differences. |
^{ | ^{ | Converts a value series into a logarithmic return series. |
^{ | ^{ | Returns the series simple return for a specific calendar period. |
^{ | ^{ | Opens a HTML Plotly plot of the series in a browser window. |
^{ | ^{ | Returns detailed drawdown characteristics. |
^{ | ^{ | Converts the series into drawdown series. |
^{ | ^{ | Returns a pandas.DataFrame with rolling returns. |
^{ | ^{ | Returns a pandas.DataFrame with rolling volatilities. |
^{ | ^{ | Returns a pandas.DataFrame with rolling VaR figures. |
^{ | ^{ | Returns a pandas.DataFrame with rolling CVaR figures. |
^{ | ^{ | Returns the start and end dates of a range from specific period definitions. Used by the below numeric methods and not meant to be used independently. |
下面是单个OpenTimeSeries或OpenFrame中所有系列可用的数值属性。
Attribute | type | Applies to | Description |
---|---|---|---|
^{ | ^{ | ^{ | Returns most of the properties in one go. |
^{ | ^{ | ^{ | Arithmetic annualized log return. |
^{ | ^{ | ^{ | Geometric annualized return. |
^{ | ^{ | ^{ | Annualized time weighted return. |
^{ | ^{ | ^{ | Simple return from first to last observation. |
^{ | ^{ | ^{ | Annualized volatility. Pandas .std() is the equivalent of stdev.s([...]) in MS excel. |
^{ | ^{ | ^{ | Ratio of geometric return and annualized volatility. |
^{ | ^{ | ^{ | Downside 95% Value At Risk, "VaR". The equivalent of percentile.inc([...], 1-level) over returns in MS Excel. For other confidence levels use the corresponding method. |
^{ | ^{ | ^{ | Downside 95% Conditional Value At Risk, "CVaR". For other confidence levels use the corresponding method. |
^{ | ^{ | ^{ | Most negative percentage change. |
^{ | ^{ | ^{ | Most negative month. |
^{ | ^{ | ^{ | Maximum drawdown. |
^{ | ^{ | ^{ | Max drawdown in a single calendar year. |
^{ | ^{ | ^{ | The share of percentage changes that are positive. |
^{ | ^{ | ^{ | Implied annualized volatility from the Downside VaR using the assumption that returns are normally distributed. |
^{ | ^{ | ^{ | Skew of the return distribution. |
^{ | ^{ | ^{ | Kurtosis of the return distribution. |
^{ | ^{ | ^{ | Z-score as (last return - mean return) / standard deviation of returns. |
^{ | ^{ | ^{ | A correlation matrix. |
下面的方法与上面的数值属性相同。
它们只是接受不同日期或长度输入以返回子集时段属性的方法。
Method | type | Applies to | Description |
---|---|---|---|
^{ | ^{ | ^{ | Arithmetic annualized log return. |
^{ | ^{ | ^{ | Geometric annualized return. |
^{ | ^{ | ^{ | Annualized time weighted return. |
^{ | ^{ | ^{ | Simple return from first to last observation. |
^{ | ^{ | ^{ | Annualized volatility. Pandas .std() is the equivalent of stdev.s([...]) in MS excel. |
^{ | ^{ | ^{ | Ratio of geometric return and annualized volatility. |
^{ | ^{ | ^{ | Downside Value At Risk, "VaR". The equivalent of percentile.inc([...], 1-level) over returns in MS Excel. Default is 95% confidence level. |
^{ | ^{ | ^{ | Downside Conditional Value At Risk, "CVaR". Default is 95% confidence level. |
^{ | ^{ | ^{ | Most negative percentage change. |
^{ | ^{ | ^{ | Most negative month. |
^{ | ^{ | ^{ | The share of percentage changes that are positive. |
^{ | ^{ | ^{ | Implied annualized volatility from the Downside VaR using the assumption that returns are normally distributed. |
^{ | ^{ | ^{ | Skew of the return distribution. |
^{ | ^{ | ^{ | Kurtosis of the return distribution. |
^{ | ^{ | ^{ | Z-score as (last return - mean return) / standard deviation of returns. |
^{ | ^{ | ^{ | A position target weight from the ratio between a VaR implied volatility and a given target volatility. |
- 项目
标签: