質問編集履歴
1
エラー全文を記入しました。よろしくお願い致します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,7 +38,39 @@
|
|
38
38
|
```
|
39
39
|
とするとエラーがでる。
|
40
40
|
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
|
41
|
+
---------------------------------------------------------------------------
|
42
|
+
TypeError Traceback (most recent call last)
|
43
|
+
<ipython-input-56-21cb90a97e71> in <module>()
|
44
|
+
2 signal=trend_signal(returns,100,3)
|
45
|
+
3 #signal.index=pd.to_datetime(signal.index)
|
46
|
+
----> 4 trade_friday=signal.resample("W-FRI").mean().resample("B").ffill()#.mean()の記載はないが記載しないと将来使えないよと注意が出る。
|
47
|
+
5 trade_rets=trade_friday.shift(1)*returns
|
48
|
+
6 #trade_rets.index=pd.to_object(trade_tets.index)
|
41
49
|
|
50
|
+
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)
|
51
|
+
5520 axis=axis, kind=kind, loffset=loffset,
|
52
|
+
5521 convention=convention,
|
53
|
+
-> 5522 base=base, key=on, level=level)
|
54
|
+
5523 return _maybe_process_deprecations(r,
|
55
|
+
5524 how=how,
|
56
|
+
|
57
|
+
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\resample.py in resample(obj, kind, **kwds)
|
58
|
+
997 """ create a TimeGrouper and return our resampler """
|
59
|
+
998 tg = TimeGrouper(**kwds)
|
60
|
+
--> 999 return tg._get_resampler(obj, kind=kind)
|
61
|
+
1000
|
62
|
+
1001
|
63
|
+
|
64
|
+
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\resample.py in _get_resampler(self, obj, kind)
|
65
|
+
1114 raise TypeError("Only valid with DatetimeIndex, "
|
66
|
+
1115 "TimedeltaIndex or PeriodIndex, "
|
67
|
+
-> 1116 "but got an instance of %r" % type(ax).__name__)
|
68
|
+
1117
|
69
|
+
1118 def _get_grouper(self, obj, validate=True):
|
70
|
+
|
71
|
+
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
|
72
|
+
---------------------------------------------------------------------------
|
73
|
+
|
42
74
|
インデックスがobjectだからダメなのかと思い。
|
43
75
|
```ここに言語を入力
|
44
76
|
signal=trend_signal(returns,100,3)
|
@@ -49,7 +81,30 @@
|
|
49
81
|
```
|
50
82
|
とするとエラーがでる。
|
51
83
|
ValueError: Cannot add integral value to Timestamp without freq.
|
84
|
+
---------------------------------------------------------------------------
|
85
|
+
ValueError Traceback (most recent call last)
|
86
|
+
<ipython-input-57-eb0ae3dff6b9> in <module>()
|
87
|
+
7
|
88
|
+
8 #次に、この戦略のリターンをリターンインデックスに変換して、グラフを描きます。
|
89
|
+
----> 9 to_index(trade_rets).plot()
|
90
|
+
10
|
91
|
+
11 #分からないのでstop!
|
52
92
|
|
93
|
+
<ipython-input-49-03cae7f6c268> in to_index(rets)
|
94
|
+
5 def to_index(rets):
|
95
|
+
6 index=(1+rets).cumprod()
|
96
|
+
----> 7 first_loc=max(index.notnull().idxmax()-1,0)
|
97
|
+
8 index.values[first_loc]=1
|
98
|
+
9 return index
|
99
|
+
|
100
|
+
pandas/_libs/tslib.pyx in pandas._libs.tslib._Timestamp.__sub__()
|
101
|
+
|
102
|
+
pandas/_libs/tslib.pyx in pandas._libs.tslib._Timestamp.__add__()
|
103
|
+
|
104
|
+
ValueError: Cannot add integral value to Timestamp without freq.
|
105
|
+
---------------------------------------------------------------------------
|
106
|
+
|
107
|
+
|
53
108
|
まだまだ勉強不測で対処方が全く対処が分からないです。
|
54
109
|
分かる方がいらっしゃいましたら御教示いただきたく宜しくお願いたします。
|
55
110
|
|