当前位置: 首页>>代码示例>>Python>>正文


Python pandas.ols方法代码示例

本文整理汇总了Python中pandas.ols方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.ols方法的具体用法?Python pandas.ols怎么用?Python pandas.ols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas的用法示例。


在下文中一共展示了pandas.ols方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_window_ols_full

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def test_window_ols_full(ols_data):
    y, x = ols_data['y'], ols_data['x']
    res1 = _window_ols(y, x, window_type='full_sample')
    res2 = _window_ols(y, x)
    res3 = pd.ols(y=y, x=x, window_type='full_sample')
    assert_ols_equal(res1, res2)
    assert_ols_equal(res1, res3) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_dynamic.py

示例2: test_window_ols_rolling

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def test_window_ols_rolling(ols_data):
    y, x = ols_data['y'], ols_data['x']
    res1 = _window_ols(y, x, window_type='rolling', window=100)
    res2 = pd.ols(y=y, x=x, window_type='rolling', window=100)
    assert_ols_equal(res1, res2) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_dynamic.py

示例3: test_window_ols_expanding

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def test_window_ols_expanding(ols_data):
    y, x = ols_data['y'], ols_data['x']
    res1 = _window_ols(y, x, window_type='expanding')
    res2 = pd.ols(y=y, x=x, window_type='expanding')
    assert_ols_equal(res1, res2) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_dynamic.py

示例4: test_solve_rect

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def test_solve_rect(self):
        if not _have_statsmodels:
            raise nose.SkipTest("no statsmodels")

        b = Series(np.random.randn(N), self.frame.index)
        result = pmath.solve(self.frame, b)
        expected = ols(y=b, x=self.frame, intercept=False).beta
        self.assert_(np.allclose(result, expected)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_math.py

示例5: __init__

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def __init__(self, y_data, x_data, lookback):
        TechnicalIndicator.__init__(self)
        self.y_data = y_data
        self.x_data = x_data
        self.lookback = lookback
        self.value = 'PAIR_%s_%s_%s' %(y_data, x_data, lookback)
        self.ols = self.value
        self.hedge_ratio = 'HEDGE_RATIO_%s_%s_%s' %(y_data, x_data, lookback)
        self.spread = 'SPREAD_%s_%s_%s' %(y_data, x_data, lookback)
        self.zscore = 'ZSCORE_%s_%s_%s' %(y_data, x_data, lookback)
        self.logger.info('Initialized - %s' %self) 
开发者ID:edouardpoitras,项目名称:NowTrade,代码行数:13,代码来源:technical_indicator.py

示例6: results

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def results(self, data_frame):
        y_value = data_frame[self.y_data]
        x_value = data_frame[self.x_data]
        if self.lookback >= len(x_value):
            return ([self.value, self.hedge_ratio, self.spread, self.zscore], \
                    [pd.Series(np.nan), pd.Series(np.nan), pd.Series(np.nan), pd.Series(np.nan)])
        ols_result = pd.ols(y=y_value, x=x_value, window=self.lookback)
        hedge_ratio = ols_result.beta['x']
        spread = y_value - hedge_ratio * x_value
        data_frame[self.value] = ols_result.resid
        data_frame[self.hedge_ratio] = hedge_ratio
        data_frame[self.spread] = spread
        data_frame[self.zscore] = (spread - \
                                   pd.rolling_mean(spread, self.lookback)) / \
                                   pd.rolling_std(spread, self.lookback) 
开发者ID:edouardpoitras,项目名称:NowTrade,代码行数:17,代码来源:technical_indicator.py

示例7: equations

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def equations(self):
        eqs = {}
        for col, ts in iteritems(self.y):
            # TODO: Remove in favor of statsmodels implemetation
            model = pd.ols(y=ts, x=self.x, window=self._window,
                           window_type=self._window_type,
                           min_periods=self._min_periods)

            eqs[col] = model

        return eqs 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:13,代码来源:dynamic.py

示例8: get_alpha_beta

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ols [as 别名]
def get_alpha_beta(self, bm_rets):
        if isinstance(bm_rets, pd.Series):
            bm = CumulativeRets(bm_rets)
        elif isinstance(bm_rets, CumulativeRets):
            bm = bm_rets
        else:
            raise ValueError('bm_rets must be series or CumulativeRetPerformace not %s' % (type(bm_rets)))

        bm_freq = guess_freq(bm_rets)
        if self.pds_per_year != bm.pds_per_year:
            tgt = {'B': 'dly', 'W': 'weekly', 'M': 'monthly', 'Q': 'quarterly', 'A': 'annual'}.get(bm_freq, None)
            if tgt is None:
                raise ValueError('No mapping for handling benchmark with frequency: %s' % bm_freq)
            tmp = getattr(self, tgt)
            y = tmp.rets
            y_ann = tmp.ltd_ann
        else:
            y = self.rets
            y_ann = self.ltd_ann

        x = bm.rets.truncate(y.index[0], y.index[-1])
        x_ann = bm.ltd_ann

        model = pd.ols(x=x, y=y)
        beta = model.beta[0]
        alpha = y_ann - beta * x_ann
        return pd.Series({'alpha': alpha, 'beta': beta}, name=bm_freq) 
开发者ID:bpsmith,项目名称:tia,代码行数:29,代码来源:ret.py


注:本文中的pandas.ols方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。