価格の移動平均を取得しようとしていますが、Moving_Average
クラスで属性エラーが発生し続けます。
'Moving_Average' object has no attribute 'days'
ここに私が持っているものがあります:
class Moving_Average:
def calculation(self, alist:list,days:int):
m = self.days
prices = alist[1::2]
average = [0]* len(prices)
signal = ['']* len(prices)
for m in range(0,len(prices)-days+1):
average[m+2] = sum(prices[m:m+days])/days
if prices[m+2] < average[m+2]:
signal[m+2]='SELL'
elif prices[m+2] > average[m+2] and prices[m+1] < average[m+1]:
signal[m+2]='BUY'
else:
signal[m+2] =''
return average,signal
def print_report(symbol:str,strategy:str):
print('SYMBOL: ', symbol)
print('STRATEGY: ', strategy)
print('Date Closing Strategy Signal')
def user():
strategy = '''
Which of the following strategy would you like to use?
* Simple Moving Average [S]
* Directional Indicator[D]
Please enter your choice: '''
if signal_strategy in 'Ss':
days = input('Please enter the number of days for the average')
days = int(days)
strategy = 'Simple Moving Average {}-days'.format(str(days))
m = Moving_Average()
ma = m.calculation(gg, days)
print(ma)
gg は、日付と価格を含むリストです。
[2013-10-01,60,2013-10-02,60]
出力は次のようになります。
Date Price Average Signal
2013-10-01 60.0
2013-10-02 60.0 60.00 BUY