Open sefati opened 4 years ago
Hi @sefati, thank you for reporting this issue and sorry for taking too long to answer!
Could you please share the setran.csv
file so that I can see what the problem is? Based on the error code you provided, I can guess that the error is that your index values (the ones from the CSV file) are not dates, and in trendet.identify_df_trends
I suppose that the index will be a datetime one. So on, I guess that can also be improved with maybe converting the str date to datetime, raising an error if the index is not datetime, etc.
As soon as you share with me the CSV file I will start working on it! Remember to STAR the repo if you found it useful and FOLLOW ME at GitHub so as to get notified of all the updates!
It is an algorithm bug. This error happens when trends overlap. The algorithm compares the overlap locations and calculates what is the predominant trend. However, the algorithm tries to get an attribute "days" at the interval indices, absurd and wrong of course.
Traceback (most recent call last): File "d:/xx/trend_data/trendet_demo2.py", line 62, in <module> res = trendet.identify_df_trends(df=get_data(), column='Close') File "D:\xx\Python37\lib\site-packages\trendet\identification.py", line 612, in identify_df_trends if (up['to'] - up['from']).days < (down['to'] - down['from']).days: AttributeError: 'int' object has no attribute 'days'
Hi again @jackure, as I told you in the other issue, could you please share with me the data you are using so as to reproduce that error and fix it as soon as possible?
Thank you! Remember to star the repo if you found it useful and follow me at GitHub so as to get notified of all the updates!
I am having this exact problem..
Its 2024. Was this issue resolved? Still getting the same error.
I got the same problem:
I tried to use AAPL data to define trend for the last two years. I set up window_size = 5 it gave, an error below. I changed it to 10, it ran ok. Then, changed the ticker to AMZAN it gave me the error for 5 and 10.
Please, let me know if you have any suggestions
AttributeError Traceback (most recent call last) File G:\My Drive\development\swing\main.py:392 385 print('script is completed') 390 if name == 'main': --> 392 main() 402 # WMA https://corporatefinanceinstitute.com/resources/career-map/sell-side/capital-markets/weighted-moving-average-wma/
File G:\My Drive\development\swing\main.py:284, in main() 280 df['day'] = df['timestamp'].dt.strftime('%Y-%m-%d') 281 # trend_df = alpaca_paral_data_col([ticker], start_date_ms, end_date_ms, timespan = 'day', multiplier=1) 282 # print(f'{ticker} i = {i} trend_df\n', trend_df.head()) 283 # trend_df = sf.trend_define(ticker, start_date_ms, end_date_ms) --> 284 trend_df = sf.trend_define_trendet(ticker, start_date_ms, end_date_ms) 285 print(f'{ticker} i = {i} trend_df\n', trend_df.head()) 286 df = df.merge(trend_df[['ticker', 'day', 'trend']], on=['ticker', 'day'], how='inner')
File G:\My Drive\development\swing\swing_functions.py:197, in trend_define_trendet(ticker, start_date_ms, end_date_ms) 195 trend_df = alpaca_paral_data_col([ticker], start_date_ms, end_date_ms, timespan = 'day', multiplier=1) 196 trend_df['close'] = trend_df['close'].astype('float64') --> 197 trend_df = trendet.identify_df_trends(df=trend_df, 198 column='close', 199 window_size=5, 200 identify='both')#.rename(columns={'Up Trend': 'trend'}) 201 trend_df['trend'] = trend_df['Up Trend'].notnull().replace({True: 'uptrend', False: None}) 202 trend_df['Down Trend'] = trend_df['Down Trend'].notnull().replace({True: 'downtrend', False: None})
File ~\Anaconda3\envs\VENV_SWING_P3_9_11\lib\site-packages\trendet\identification.py:589, in identify_df_trends(df, column, window_size, identify) 587 for down in results['Down Trend']: 588 if down['from'] < up['from'] < down['to'] or down['from'] < up['to'] < down['to']: --> 589 if (up['to'] - up['from']).days > (down['to'] - down['from']).days: 590 flag = True 591 else:
AttributeError: 'int' object has no attribute 'days'
Hi, I'm using this great python library. I was wondering why I come up with this error:
'int' object has no attribute 'days'
my code is here:Can you please answer me to solve this issue (or just my problem) ?