简单的金融时间序列分析软件包。

openseries的Python项目详细描述


CircleCILicensePyPI versionCoverage

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,这是一个从列表datesvalues中的原始数据构造的数据帧。在

目录

这些是描述的文件/模块。

ModuleDescription
series.pyDefines the class OpenTimeSeries for managing and analyzing a single timeseries. The module also defines a function ^{} that can be used to chain two timeseries objects together.
frame.pyDefines 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.pyA Python SDK to interact with the Captor Open API.
datefixer.pyA module with date utilities.
helpfilewriter.pyA module that allows printing a description of a Python class.
openseries.jsonThe jsonschema of the OpenTimeSeries class.
plotly_layouts.jsonA module setting Plotly defaults used in the ^{} methods.
plotly_captor_logo.jsonA module with a link to the Captor logo used in the ^{} methods.
risk.pyModule with methods used to calculate VaR, CVaR and drawdowns.
sim_price.pyModule to simulate OpenTimeSeries from different stochastic processes.
stoch_processes.pyModule to generate stochastic processes used in the ^{} module.
sweden_holidays.pyModule that defines a Swedish business calendar.

下面是用于构造OpenTimeSeries对象的类方法。

^{tb2}$

此表中的非数字或“helper”属性仅适用于OpenTimeSeries类。

AttributetypeApplies toDescription
^{}^{}^{}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类。

AttributetypeApplies toDescription
^{}^{}^{}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.

此表中是应用于OpenTimeSeriesOpenFrame类的非数字或“helper”属性。

AttributetypeApplies toDescription
^{}^{}^{}, ^{}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类。

MethodApplies toDescription
^{}^{}Class method that defines the ^{} attribute and a ^{} business day calendar.
^{}^{}Method to validate the OpenTimeSeries input against the openseries.json jsonschema.
^{}^{}Method to export the OpenTimeSeries ^{} to a json file.
^{}^{}Method to create the ^{} pandas.DataFrame from the ^{} and ^{}.
^{}^{}Method to change the pandas.DataFrame column MultiIndex.
^{}^{}Adjusts the series performance with a ^{} factor.

此表中的方法仅适用于OpenFrame类。

MethodApplies toDescription
^{}^{}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.

此表中的方法同时适用于OpenTimeSeriesOpenFrame类。

MethodApplies toDescription
^{}^{}, ^{}Aligns the series dates to a business calendar. Defaults to Sweden.
^{}^{}, ^{}Resamples the series to a specific frequency.
^{}^{}, ^{}Fills ^{} in a value series with the preceding non-Nan value.
^{}^{}, ^{}Replaces ^{} in a return series with a 0.0 ^{}.
^{}^{}, ^{}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.

下面是单个OpenTimeSeriesOpenFrame中所有系列可用的数值属性。

AttributetypeApplies toDescription
^{}^{}^{}, ^{}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.

下面的方法与上面的数值属性相同。

它们只是接受不同日期或长度输入以返回子集时段属性的方法。

MethodtypeApplies toDescription
^{}^{}, ^{}^{}, ^{}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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从远程安卓应用程序打开/关闭嵌套   java在每个请求上获取memcache变量导致问题   如何在java中使用itext获取pdf文件的标题   java如何使用firebase令牌发送通知?   java不能在spring数据聚合中包含嵌套字段   用于调度作业的java Cron表达式   java当我使用TabActivity 安卓时,TabActivity类型已被弃用   加密Java Bouncy Castle加密使用AES加密   awt Java,将GUI与ActionListener类分离   如何在Java中创建一个根据输入返回枚举的方法?   java什么是Gxt 3.1.1实现对话框的方法。Gxt 3.0.0是否支持getHideButton()?   java如何解决构建错误?   java XWPF POI如何设置段落中的文本而不使用换行符