This bot was built to enable developers a chance to interact with the specific libraries and develop their skills from the Ground floor. You will find different ways to optimize the code that you are able to view, and I look forward to witnessing if this code actually grows.
First to start, here are some details about the 'risk strategy.py' file:
- Reads in risk parameters from
risk_params.json - Dynamically updates risk parameters based on profit/loss
- Calculates position sizes based on current price and equity
- Validates trades against risk limits before placing orders
- Rebalances positions to maintain sector allocation limits
- Sends summary reports to Teams channel
RiskManagementclass:validate_trade- Checks trades against risk limitscalculate_quantity- Computes position size for ordersrebalance_positions- Rebalances portfolio allocationupdate_risk_parameters- Adjusts risk params based on PnLreport_profit_and_loss- Calculates total P&L
- Helper methods:
get_current_price- Fetches latest price datasend_teams_message- Sends summary to Teams
PortfolioManagerclass - Tracks portfolio holdings- Alpaca API wrapper - Interfaces with brokerage
- Initialize
RiskManagementwith Alpaca API and risk parameters - Before placing each order:
- Calculate quantity using
calculate_quantity - Validate trade with
validate_trade
- Calculate quantity using
- Periodically rebalance portfolio with
rebalance_positions - Update risk parameters based on profit/loss
- Send summary report to Teams channel