質問編集履歴

1

エラー全文を記入しました。よろしくお願い致します。

2018/10/28 09:21

投稿

yutakao
yutakao

スコア10

test CHANGED
File without changes
test CHANGED
@@ -78,6 +78,70 @@
78
78
 
79
79
  TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
80
80
 
81
+ ---------------------------------------------------------------------------
82
+
83
+ TypeError Traceback (most recent call last)
84
+
85
+ <ipython-input-56-21cb90a97e71> in <module>()
86
+
87
+ 2 signal=trend_signal(returns,100,3)
88
+
89
+ 3 #signal.index=pd.to_datetime(signal.index)
90
+
91
+ ----> 4 trade_friday=signal.resample("W-FRI").mean().resample("B").ffill()#.mean()の記載はないが記載しないと将来使えないよと注意が出る。
92
+
93
+ 5 trade_rets=trade_friday.shift(1)*returns
94
+
95
+ 6 #trade_rets.index=pd.to_object(trade_tets.index)
96
+
97
+
98
+
99
+ C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base, on, level)
100
+
101
+ 5520 axis=axis, kind=kind, loffset=loffset,
102
+
103
+ 5521 convention=convention,
104
+
105
+ -> 5522 base=base, key=on, level=level)
106
+
107
+ 5523 return _maybe_process_deprecations(r,
108
+
109
+ 5524 how=how,
110
+
111
+
112
+
113
+ C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\resample.py in resample(obj, kind, **kwds)
114
+
115
+ 997 """ create a TimeGrouper and return our resampler """
116
+
117
+ 998 tg = TimeGrouper(**kwds)
118
+
119
+ --> 999 return tg._get_resampler(obj, kind=kind)
120
+
121
+ 1000
122
+
123
+ 1001
124
+
125
+
126
+
127
+ C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\resample.py in _get_resampler(self, obj, kind)
128
+
129
+ 1114 raise TypeError("Only valid with DatetimeIndex, "
130
+
131
+ 1115 "TimedeltaIndex or PeriodIndex, "
132
+
133
+ -> 1116 "but got an instance of %r" % type(ax).__name__)
134
+
135
+ 1117
136
+
137
+ 1118 def _get_grouper(self, obj, validate=True):
138
+
139
+
140
+
141
+ TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
142
+
143
+ ---------------------------------------------------------------------------
144
+
81
145
 
82
146
 
83
147
  インデックスがobjectだからダメなのかと思い。
@@ -100,6 +164,52 @@
100
164
 
101
165
  ValueError: Cannot add integral value to Timestamp without freq.
102
166
 
167
+ ---------------------------------------------------------------------------
168
+
169
+ ValueError Traceback (most recent call last)
170
+
171
+ <ipython-input-57-eb0ae3dff6b9> in <module>()
172
+
173
+ 7
174
+
175
+ 8 #次に、この戦略のリターンをリターンインデックスに変換して、グラフを描きます。
176
+
177
+ ----> 9 to_index(trade_rets).plot()
178
+
179
+ 10
180
+
181
+ 11 #分からないのでstop!
182
+
183
+
184
+
185
+ <ipython-input-49-03cae7f6c268> in to_index(rets)
186
+
187
+ 5 def to_index(rets):
188
+
189
+ 6 index=(1+rets).cumprod()
190
+
191
+ ----> 7 first_loc=max(index.notnull().idxmax()-1,0)
192
+
193
+ 8 index.values[first_loc]=1
194
+
195
+ 9 return index
196
+
197
+
198
+
199
+ pandas/_libs/tslib.pyx in pandas._libs.tslib._Timestamp.__sub__()
200
+
201
+
202
+
203
+ pandas/_libs/tslib.pyx in pandas._libs.tslib._Timestamp.__add__()
204
+
205
+
206
+
207
+ ValueError: Cannot add integral value to Timestamp without freq.
208
+
209
+ ---------------------------------------------------------------------------
210
+
211
+
212
+
103
213
 
104
214
 
105
215
  まだまだ勉強不測で対処方が全く対処が分からないです。