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


Python var_model.VAR类代码示例

本文整理汇总了Python中statsmodels.tsa.vector_ar.var_model.VAR的典型用法代码示例。如果您正苦于以下问题:Python VAR类的具体用法?Python VAR怎么用?Python VAR使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_select_order

    def test_select_order(self):
        result = self.model.fit(10, ic='aic', verbose=True)
        result = self.model.fit(10, ic='fpe', verbose=True)

        # bug
        model = VAR(self.model.endog)
        model.select_order()
开发者ID:Wombatpm,项目名称:statsmodels,代码行数:7,代码来源:test_var.py

示例2: extract

 def extract(self, instance):
     assert(isinstance(instance, Instance))
     params = VAR(instance.eeg_data.T).fit(self.lags).params
     # hstack will collapse all entries into one big vector 
     features = np.hstack(params.reshape( (np.prod(params.shape),1) ))
     self.assert_features(features)
     # features = a 1d ndarray 
     return features
开发者ID:vincentadam87,项目名称:gatsby-hackathon-seizure,代码行数:8,代码来源:ARFeatures.py

示例3: load_results_statsmodels

def load_results_statsmodels(dataset):
    results_per_deterministic_terms = dict.fromkeys(dt_s_list)
    for dt_s_tup in dt_s_list:
        endog = data[dataset]
        exog = generate_exog_from_season(dt_s_tup[1], len(endog))
        model = VAR(endog, exog)
        results_per_deterministic_terms[dt_s_tup] = model.fit(
                maxlags=4, trend=dt_s_tup[0], method="ols")
    return results_per_deterministic_terms
开发者ID:ChadFulton,项目名称:statsmodels,代码行数:9,代码来源:test_var_jmulti.py

示例4: vars_test

def vars_test():
    dt = get_dataframe()
    name_list = ["date", "tBalance_all", "total_purchase", "total_redeem", "total_diff"]
    # print(dt["total_purchase"])
    time = dt["date"]
    mdata = dt[["tBalance_all", "total_purchase", "total_redeem"]]
    mdata.index = pandas.DatetimeIndex(time)
    data = np.log(mdata).diff().dropna()
    model = VAR(data)
    results = model.fit(2)
    results.summary()

    results.plot()
开发者ID:744996162,项目名称:ali_match,代码行数:13,代码来源:vars.py

示例5: TestVARResultsLutkepohl

class TestVARResultsLutkepohl(object):
    """
    Verify calculations using results from Lutkepohl's book
    """

    def __init__(self):
        self.p = 2

        if not have_pandas():
            return

        sdata, dates = get_lutkepohl_data("e1")

        names = sdata.dtype.names
        data = data_util.struct_to_ndarray(sdata)
        adj_data = np.diff(np.log(data), axis=0)
        # est = VAR(adj_data, p=2, dates=dates[1:], names=names)

        self.model = VAR(adj_data[:-16], dates=dates[1:-16], names=names, freq="Q")
        self.res = self.model.fit(maxlags=self.p)
        self.irf = self.res.irf(10)
        self.lut = E1_Results()

    def test_approx_mse(self):
        if not have_pandas():
            raise nose.SkipTest

        # 3.5.18, p. 99
        mse2 = np.array([[25.12, 0.580, 1.300], [0.580, 1.581, 0.586], [1.300, 0.586, 1.009]]) * 1e-4

        assert_almost_equal(mse2, self.res.forecast_cov(3)[1], DECIMAL_3)

    def test_irf_stderr(self):
        if not have_pandas():
            raise nose.SkipTest

        irf_stderr = self.irf.stderr(orth=False)
        for i in range(1, 1 + len(self.lut.irf_stderr)):
            assert_almost_equal(np.round(irf_stderr[i], 3), self.lut.irf_stderr[i - 1])

    def test_cum_irf_stderr(self):
        if not have_pandas():
            raise nose.SkipTest

        stderr = self.irf.cum_effect_stderr(orth=False)
        for i in range(1, 1 + len(self.lut.cum_irf_stderr)):
            assert_almost_equal(np.round(stderr[i], 3), self.lut.cum_irf_stderr[i - 1])

    def test_lr_effect_stderr(self):
        if not have_pandas():
            raise nose.SkipTest

        stderr = self.irf.lr_effect_stderr(orth=False)
        orth_stderr = self.irf.lr_effect_stderr(orth=True)
        assert_almost_equal(np.round(stderr, 3), self.lut.lr_stderr)
开发者ID:slojo404,项目名称:statsmodels,代码行数:55,代码来源:test_var.py

示例6: test_lag_order_selection

def test_lag_order_selection():
    if debug_mode:
        if "lag order" not in to_test:
            return
        else:
            print("\n\nLAG ORDER SELECTION", end="")
    for ds in datasets:
        for dt in dt_s_list:
            if debug_mode:
                print("\n" + dt_s_tup_to_string(dt) + ": ", end="")
            endog_tot = data[ds]
            exog = generate_exog_from_season(dt[1], len(endog_tot))
            model = VAR(endog_tot, exog)
            obtained_all = model.select_order(10, trend=dt[0])
            for ic in ["aic", "fpe", "hqic", "bic"]:
                err_msg = build_err_msg(ds, dt,
                                        "LAG ORDER SELECTION - " + ic.upper())
                obtained = getattr(obtained_all, ic)
                desired = results_ref[ds][dt]["lagorder"][ic]
                assert_allclose(obtained, desired, rtol, atol, False, err_msg)
开发者ID:ChadFulton,项目名称:statsmodels,代码行数:20,代码来源:test_var_jmulti.py

示例7: test_var_constant

def test_var_constant():
    # see 2043
    import datetime
    from pandas import DataFrame, DatetimeIndex

    series = np.array([[2., 2.], [1, 2.], [1, 2.], [1, 2.], [1., 2.]])
    data = DataFrame(series)

    d = datetime.datetime.now()
    delta = datetime.timedelta(days=1)
    index = []
    for i in range(data.shape[0]):
        index.append(d)
        d += delta

    data.index = DatetimeIndex(index)

    model = VAR(data)
    with pytest.raises(ValueError):
        model.fit(1)
开发者ID:lbybee,项目名称:statsmodels,代码行数:20,代码来源:test_var.py

示例8: __init__

    def __init__(self):
        self.p = 2
        sdata, dates = get_lutkepohl_data('e1')

        data = data_util.struct_to_ndarray(sdata)
        adj_data = np.diff(np.log(data), axis=0)
        # est = VAR(adj_data, p=2, dates=dates[1:], names=names)

        self.model = VAR(adj_data[:-16], dates=dates[1:-16], freq='Q')
        self.res = self.model.fit(maxlags=self.p)
        self.irf = self.res.irf(10)
        self.lut = E1_Results()
开发者ID:Wombatpm,项目名称:statsmodels,代码行数:12,代码来源:test_var.py

示例9: test_var_constant

def test_var_constant():
    # see 2043
    import datetime
    from pandas import DataFrame, DatetimeIndex

    series = np.array([[2., 2.], [1, 2.], [1, 2.], [1, 2.], [1., 2.]])
    data = DataFrame(series)

    d = datetime.datetime.now()
    delta = datetime.timedelta(days=1)
    index = []
    for i in range(data.shape[0]):
        index.append(d)
        d += delta

    data.index = DatetimeIndex(index)

    #with pytest.warns(ValueWarning):  #does not silence warning in test output
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=ValueWarning)
        model = VAR(data)
    with pytest.raises(ValueError):
        model.fit(1)
开发者ID:N-Wouda,项目名称:statsmodels,代码行数:23,代码来源:test_var.py

示例10: test2

def test2():
    mdata = statsmodels.datasets.macrodata.load_pandas().data
    dates = mdata[["year", "quarter"]].astype(int).astype(str)
    quarterly = dates["year"] + "Q" + dates["quarter"]

    mdata = mdata[["realgdp", "realcons", "realinv"]]
    mdata.index = pandas.DatetimeIndex(quarterly)
    data = np.log(mdata).diff().dropna()

    model = VAR(data)
    results = model.fit(2)
    results.summary()
    results = model.fit(maxlags=50, ic="aic")
    # print(results.summary())

    lag_order = results.k_ar
    print results.forecast(data.values[-lag_order:], 30)
    # print(results)
    # print model.select_order(15)

    # results.plot()
    # results.plot_acorr()

    pass
开发者ID:744996162,项目名称:ali_match,代码行数:24,代码来源:vars.py

示例11: __init__

    def __init__(self):
        self.p = 2

        if not have_pandas():
            return

        sdata, dates = get_lutkepohl_data("e1")

        names = sdata.dtype.names
        data = data_util.struct_to_ndarray(sdata)
        adj_data = np.diff(np.log(data), axis=0)
        # est = VAR(adj_data, p=2, dates=dates[1:], names=names)

        self.model = VAR(adj_data[:-16], dates=dates[1:-16], names=names, freq="Q")
        self.res = self.model.fit(maxlags=self.p)
        self.irf = self.res.irf(10)
        self.lut = E1_Results()
开发者ID:slojo404,项目名称:statsmodels,代码行数:17,代码来源:test_var.py

示例12: test_constructor

 def test_constructor(self):
     # make sure this works with no names
     ndarr = self.data.view((float, 3))
     model = VAR(ndarr)
     res = model.fit(self.p)
开发者ID:Wombatpm,项目名称:statsmodels,代码行数:5,代码来源:test_var.py

示例13: dates_from_str

import pandas as pd
import numpy as np
import statsmodels.api as sm
import pylab
from statsmodels.tsa.base.datetools import dates_from_str
from statsmodels.tsa.vector_ar.var_model import VAR

mdata = sm.datasets.macrodata.load_pandas().data
dates = mdata[['year', 'quarter']].astype(int).astype(str)
quarterly = dates["year"] + "Q" + dates["quarter"]
quarterly = dates_from_str(quarterly)

mdata = mdata[['realgdp','realcons','realinv']]
mdata.index = pd.DatetimeIndex(quarterly)
data = np.log(mdata).diff().dropna() # log difference

# make a VAR model
model = VAR(data)
results = model.fit(2)
print results.summary()
results.plot()
results.plot_acorr() #autocorrelation 

model.select_order(15)
results = model.fit(maxlags=15, ic='aic')

irf = results.irf(10)
irf.plot(orth=True) #Orthogonalization

pylab.show()
开发者ID:shimaXX,项目名称:workspace,代码行数:30,代码来源:var_example.py

示例14: VAR

sr_bm = np.sqrt(252)*sharpe(rets_bm)
print mn_bm, sd_bm, sr_bm
#calc beta's alpha's 


#do forecast of returns, correlation. Use to Weight
rets.iloc[:,0:10].plot()
###DETOUR TO VAR FORECASTING

from statsmodels.tsa.vector_ar.var_model import VAR, VARResults, VARProcess
import statsmodels
statsmodels.version.version

#Check for NA's in data - have to reduce number of series used as full 30
#gave singular matrix
v1 = VAR(rets_train[series_red], freq='D')
v1.select_order(maxlags=30)
results = v1.fit(5) #From fitted
# results.summary()
results.plot()
# results.plot_acorr()
# plt.show()

#Make forecast for 3months
test_index = rets_test.index
fc_range = pd.date_range(start=test_index[0], periods=2, freq='3M')
fc_periods = len(rets_test[fc_range[0]:fc_range[1]])
lag_order = results.k_ar
fc = results.forecast(rets_train[series_red].values,fc_periods)
fc.shape
fc[:,-1]
开发者ID:GBelzoni,项目名称:BigGits,代码行数:31,代码来源:CAPM.py


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