當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。