I am currently trying to carry out the following line of code:
z = y-(X_array*HedgeRatio)
with the variables having the following attributes:
Hedge Ratio = 0.489552919785
Hedge Ratio type = <type 'numpy.float64'>
y type = <class 'pandas.core.frame.DataFrame'>
X_array type = <type 'numpy.ndarray'>
y length = 1554
X_array length = 1554
But when it executes I get the following long error message:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-161-6dd37e0445e9> in <module>()
1 #for i in get_symb_list(symbs):
----> 2 MRAnalysis(symbs,'2010/01/01')
<ipython-input-160-be6f6d5b64d0> in MRAnalysis(symbList, start_date)
63
64 #create new spread series by subtracting (X variable price multiplied by hedge ratio) from y price series
---> 65 z = y-(X_array*HedgeRatio)
66
67 #plot spread series showing mean of series
C:\Python27\lib\site-packages\pandas\core\ops.pyc in f(self, other, axis, level, fill_value)
838 # casted = self._constructor_sliced(other,
839 # index=self.columns)
--> 840 casted = pd.Series(other, index=self.columns)
841 return self._combine_series(casted, na_op, fill_value,
842 axis, level)
C:\Python27\lib\site-packages\pandas\core\series.pyc in __init__(self, data, index, dtype, name, copy, fastpath)
216 raise_cast_failure=True)
217
--> 218 data = SingleBlockManager(data, index, fastpath=True)
219
220 generic.NDFrame.__init__(self, data, fastpath=True)
C:\Python27\lib\site-packages\pandas\core\internals.pyc in __init__(self, block, axis, do_integrity_check, fastpath)
3381 block = make_block(block,
3382 placement=slice(0, len(axis)),
-> 3383 ndim=1, fastpath=True)
3384
3385 self.blocks = [block]
C:\Python27\lib\site-packages\pandas\core\internals.pyc in make_block(values, placement, klass, ndim, dtype, fastpath)
2099
2100 return klass(values, ndim=ndim, fastpath=fastpath,
-> 2101 placement=placement)
2102
2103
C:\Python27\lib\site-packages\pandas\core\internals.pyc in __init__(self, values, placement, ndim, fastpath)
75 raise ValueError('Wrong number of items passed %d,'
76 ' placement implies %d' % (
---> 77 len(self.values), len(self.mgr_locs)))
78
79 @property
ValueError: Wrong number of items passed 1554, placement implies 1
I am confused as I thought pandas Dataframes and numpy arrays could "talk" to eachother and that I would get a DataFrame or Series with the calculations outlined carried out row by row.
The length of the numpy array and the DataFrame included in the line of code both have the same length.
Could someone please highlight where I am going wrong and what I have misunderstood.