trend_return doesn't accumulate either of return types
See original GitHub issueWhich version are you running? The lastest version is on Github. Pip is for major releases.
pandas_ta 0.2.23b0
Describe the bug
I tried log=False, cumulative = True
and in another case log=True, cumulative = True
, but there are no cumulative returns in returns column for log returns or percent returns
To Reproduce I can’t attach my CSV here because couldn’t find any option in this bug report, but I think this will work the same way for any SP500 daily data you have
import pandas as pd
import pandas_ta as ta
df = pd.read_csv("E:\Dropbox\Trading\Quotes\^spx_d.csv", sep=",")
df.set_index(pd.DatetimeIndex(df["Date"]), inplace=True)
MAstr = ta.trend_return(df['Close'], trend= df['Close'] > ta.sma(df['Close'], 50), log=False, cumulative = True)
print('\n MAstr \n',MAstr)
print('\n MAstr > 0 \n',MAstr[MAstr.CPTR_Trades>0])
print('\n MAstr <0 \n', MAstr[MAstr.CPTR_Trades<0])
OUTPUT:
MAstr
CPTR TR_PCTRET CPTR_Trends CPTR_Trades
Date
1920-01-02 0.0 NaN 0 0
1920-01-03 0.0 0.0 0 0
1920-01-05 0.0 0.0 0 0
1920-01-06 0.0 0.0 0 0
1920-01-07 0.0 0.0 0 0
... ... ... ...
2020-10-26 0.0 0.0 0 0
2020-10-27 0.0 0.0 0 0
2020-10-28 0.0 0.0 0 0
2020-10-29 0.0 0.0 0 0
2020-10-30 0.0 0.0 0 0
[26803 rows x 4 columns]
MAstr > 0
CPTR TR_PCTRET CPTR_Trends CPTR_Trades
Date
1920-03-06 0.0 0.0 0 1
1920-07-01 0.0 0.0 0 1
1920-07-16 0.0 0.0 0 1
1920-08-20 0.0 0.0 0 1
1920-08-23 0.0 0.0 0 1
... ... ... ...
2020-04-16 0.0 0.0 0 1
2020-04-23 0.0 0.0 0 1
2020-09-29 0.0 0.0 0 1
2020-10-02 0.0 0.0 0 1
2020-10-06 0.0 0.0 0 1
[814 rows x 4 columns]
MAstr <0
CPTR TR_PCTRET CPTR_Trends CPTR_Trades
Date
1920-04-19 0.045541 -0.018319 1 -1
1920-07-15 0.007444 -0.009390 1 -1
1920-07-22 0.009505 0.004739 1 -1
1920-08-21 0.004813 0.004813 1 -1
1920-10-27 0.040070 -0.006881 1 -1
... ... ... ...
2020-04-17 0.026794 0.026794 1 -1
2020-09-17 0.191401 -0.008412 1 -1
2020-10-01 0.013547 0.005293 1 -1
2020-10-05 0.017976 0.017976 1 -1
2020-10-23 0.031166 0.003446 1 -1
[814 rows x 4 columns]
Expected behavior As MAstr shows, no cumulative data, because 0 in the end, although there are trades
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
TypeScript multiple return types with identical parameters
Ok, this is the right way if you want to have proper types: type CustomType = { lowercase: TypeOfTheProperty }; // Sorry I...
Read more >typescript-eslint/explicit-function-return-type.md at main - GitHub
This rule enforces that functions do have an explicit return type annotation. Examples. ❌ Incorrect. // Should indicate that no value is returned...
Read more >It's All About Interest Rates - RiverFront Investment Group
adjusted trend return of large cap stocks is 6.4% (including reinvested dividends). As of the latest data we have, large caps.
Read more >14080: Multiple Return Types for Same SSN/EIN
It is possible to have multiple returns for the same SSN or EIN in Drake Tax as long as they have different return...
Read more >Return multiple values from a function in Kotlin - Techie Delight
Returning an array. Another approach is to accumulate your values inside an array and return it from the function. Note that this doesn't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you. To be honest I’ve not checked that yet, because I stacked with other part of the code not related to yours 😃 But if it worked on your side, it should work on my side 😃
Thank you.
Hello @AlexStox,
I assume by no response that the solution provided was sufficient. Thus I will be closing this issue in a few days.
Kind Regards, KJ