Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Dec 18, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from amor71 December 18, 2023 11:19
Comment on lines -378 to -386
indicator_calculator = StockDataFrame(df)
sma_100 = indicator_calculator["close_100_sma"]
if df.empty or df.close[-1] < sma_100[-1]:
return False

return (
self.portfolio.loc[self.portfolio.symbol == symbol].volatility
>= 1 - self.volatility_threshold
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trend.apply_filters_symbol refactored with the following changes:

Comment on lines -460 to +451
filter = future.result()
if filter:
if filter := future.result():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trend.apply_filters_for_short refactored with the following changes:

Comment on lines -238 to +241
if (
self.portfolio.loc[
self.portfolio.symbol == symbol
].volatility.values
< 1 - self.volatility_threshold
):
return False

return True
return (
self.portfolio.loc[self.portfolio.symbol == symbol].volatility.values
>= 1 - self.volatility_threshold
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trend.apply_filters_symbol refactored with the following changes:

Comment on lines -254 to +252
if (
self.portfolio.loc[
self.portfolio.symbol == symbol
].volatility.values
< 1 - self.volatility_threshold
):
return False

return True
return (
self.portfolio.loc[self.portfolio.symbol == symbol].volatility.values
>= 1 - self.volatility_threshold
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trend.apply_filters_symbol_for_short refactored with the following changes:

Comment on lines -278 to +268
filter = future.result()
if filter:
if filter := future.result():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trend.apply_filters refactored with the following changes:

Comment on lines -109 to +115
std = {}
for symbol in symbols:
if symbol in _daiy_data:
std[symbol] = statistics.pstdev(
_daiy_data[symbol]["low"]
)

unsorted = [
std = {
symbol: statistics.pstdev(_daiy_data[symbol]["low"])
for symbol in symbols
if symbol in _daiy_data
}
if unsorted := [
x
for x in unsorted
if x.ticker in symbols
and x.day["o"] < (x.prevDay["l"] - std[x.ticker])
]

if len(unsorted) > 0:
]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GapDown.run refactored with the following changes:

Comment on lines -3 to +4
df["ema_short"] = ta.EMA({"close": df.close}, timeperiod=int(16))
df["ema_long"] = ta.EMA({"close": df.close}, timeperiod=int(50))
df["ema_short"] = ta.EMA({"close": df.close}, timeperiod=16)
df["ema_long"] = ta.EMA({"close": df.close}, timeperiod=50)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pre_calculated refactored with the following changes:

Comment on lines -327 to +329
rc_dict: Dict[str, float] = {}
for _, row in new_df.iterrows():
rc_dict[row.symbol] = float(row.qty)

rc_dict: Dict[str, float] = {
row.symbol: float(row.qty) for _, row in new_df.iterrows()
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TrendFollow.load_symbol_position refactored with the following changes:

return (
True
if time(hour=14, minute=30)
>= now.time()
>= time(hour=9, minute=30)
else False
)
return time(hour=14, minute=30) >= now.time() >= time(hour=9, minute=30)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Gold.is_buy_time refactored with the following changes:

Comment on lines -217 to +240
if trading_api:
retry = 3
while retry > 0:
try:
portfolio_value = float(
trading_api.get_account().portfolio_value
)
break
except ConnectionError as e:
tlog(
f"[{symbol}][{now}[Error] get_account() failed w/ {e}, retrying {retry} more times"
)
await asyncio.sleep(0)
retry -= 1

if not portfolio_value:
tlog(
"f[{symbol}][{now}[Error] failed to get portfolio_value"
)
return False, {}
else:
if not trading_api:
raise Exception(
f"{self.name}: both portfolio_value and trading_api can't be None"
)

retry = 3
while retry > 0:
try:
portfolio_value = float(
trading_api.get_account().portfolio_value
)
break
except ConnectionError as e:
tlog(
f"[{symbol}][{now}[Error] get_account() failed w/ {e}, retrying {retry} more times"
)
await asyncio.sleep(0)
retry -= 1

if not portfolio_value:
tlog(
"f[{symbol}][{now}[Error] failed to get portfolio_value"
)
return False, {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ShortTrapBuster.run refactored with the following changes:

Comment on lines -243 to +266
if trading_api:
retry = 3
while retry > 0:
try:
portfolio_value = float(
trading_api.get_account().portfolio_value
)
break
except ConnectionError as e:
tlog(
f"[{symbol}][{now}[Error] get_account() failed w/ {e}, retrying {retry} more times"
)
await asyncio.sleep(0)
retry -= 1

if not portfolio_value:
tlog(
"f[{symbol}][{now}[Error] failed to get portfolio_value"
)
return False, {}
else:
if not trading_api:
raise Exception(
f"{self.name}: both portfolio_value and trading_api can't be None"
)

retry = 3
while retry > 0:
try:
portfolio_value = float(
trading_api.get_account().portfolio_value
)
break
except ConnectionError as e:
tlog(
f"[{symbol}][{now}[Error] get_account() failed w/ {e}, retrying {retry} more times"
)
await asyncio.sleep(0)
retry -= 1

if not portfolio_value:
tlog(
"f[{symbol}][{now}[Error] failed to get portfolio_value"
)
return False, {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ShortTrapBusterV2.run refactored with the following changes:

Comment on lines -78 to +101
if trading_api:
retry = 3
while retry > 0:
try:
portfolio_value = float(
trading_api.get_account().portfolio_value
)
break
except ConnectionError as e:
tlog(
f"[{symbol}][{now}[Error] get_account() failed w/ {e}, retrying {retry} more times"
)
await asyncio.sleep(0)
retry -= 1

if not portfolio_value:
tlog(
"f[{symbol}][{now}[Error] failed to get portfolio_value"
)
return False, {}
else:
if not trading_api:
raise Exception(
f"{self.name}: both portfolio_value and trading_api can't be None"
)

retry = 3
while retry > 0:
try:
portfolio_value = float(
trading_api.get_account().portfolio_value
)
break
except ConnectionError as e:
tlog(
f"[{symbol}][{now}[Error] get_account() failed w/ {e}, retrying {retry} more times"
)
await asyncio.sleep(0)
retry -= 1

if not portfolio_value:
tlog(
"f[{symbol}][{now}[Error] failed to get portfolio_value"
)
return False, {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SwingMamaFama.run refactored with the following changes:

Comment on lines -110 to -113
# scale-out
# sell if not picking up.
pass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function VWAPScalp.run refactored with the following changes:

This removes the following comments ( why? ):

# sell if not picking up.
# scale-out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants