Skip to content

Commit

Permalink
added min quantity to sell to force sell and suggestion heap for docu…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
yeonholee50 committed Dec 23, 2024
1 parent 8b35984 commit 14faf95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion strategies/talib_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_data(ticker, mongo_client, period='1y'):
df = pd.DataFrame(data['data'])
df['Date'] = pd.to_datetime(df['Date'])
df.set_index('Date', inplace=True)
print("Data fetched from MongoDB")

return df
else:

Expand Down
18 changes: 10 additions & 8 deletions trading_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ def main():
decisions_and_quantities.append((decision, quantity, weight))

decision, quantity, buy_weight, sell_weight, hold_weight = weighted_majority_decision_and_median_quantity(decisions_and_quantities)

if portfolio_qty == 0.0 and buy_weight > sell_weight:
print(f"Suggestions for buying for {ticker} with a weight of {buy_weight}")
max_investment = portfolio_value * 0.10
quantity = min(int(max_investment // current_price), int(buying_power // current_price))
buy_quantity = min(int(max_investment // current_price), int(buying_power // current_price))


heapq.heappush(suggestion_heap, (-buy_weight, quantity, ticker))
heapq.heappush(suggestion_heap, (-buy_weight, buy_quantity, ticker))
print(f"Ticker: {ticker}, Decision: {decision}, Quantity: {quantity}, Weights: Buy: {buy_weight}, Sell: {sell_weight}, Hold: {hold_weight}")
"""
later we should implement buying_power regulator depending on vix strategy
Expand All @@ -197,10 +199,11 @@ def main():
if decision == "buy" and float(account.cash) > 15000 and (((quantity + portfolio_qty) * current_price) / portfolio_value) < 0.1:

heapq.heappush(buy_heap, (-(buy_weight-(sell_weight + (hold_weight * 0.5))), quantity, ticker))
elif (decision == "sell" or sell_weight > buy_weight) and portfolio_qty > 0:
elif (decision == "sell") and portfolio_qty > 0:
print(f"Executing SELL order for {ticker}")


print(f"Executing quantity of {quantity} for {ticker}")
quantity = min(quantity, 1)
order = place_order(trading_client, symbol=ticker, side=OrderSide.SELL, quantity=quantity, mongo_client=mongo_client) # Place order using helper

logging.info(f"Executed SELL order for {ticker}: {order}")
Expand All @@ -222,8 +225,7 @@ def main():

logging.info(f"Executed BUY order for {ticker}: {order}")

trading_client = TradingClient(API_KEY, API_SECRET)
account = trading_client.get_account()

elif suggestion_heap:
_, quantity, ticker = heapq.heappop(suggestion_heap)
print(f"Executing BUY order for {ticker}")
Expand All @@ -232,8 +234,8 @@ def main():

logging.info(f"Executed BUY order for {ticker}: {order}")

trading_client = TradingClient(API_KEY, API_SECRET)
account = trading_client.get_account()
trading_client = TradingClient(API_KEY, API_SECRET)
account = trading_client.get_account()


except:
Expand Down

0 comments on commit 14faf95

Please sign in to comment.