Stock Markets Analytics Zoomcamp 2024

Homework 4: Trading Simulation Statistics

Distribution of scores and reported study time for this homework.

Submissions

31

Median total score

7

Average total score

7

Score distribution

All values are points.

Questions score

Min
1
Median
7.0
Max
7
Q1
5.0
Avg
5.9
Q3
7.0

Learning in public score

Min
-
Median
0.0
Max
7
Q1
0.0
Avg
1.3
Q3
1.0

Total score

Min
1
Median
7.0
Max
14
Q1
5.0
Avg
7.2
Q3
8.0

Time distribution

All values are hours reported by students.

Lectures

Min
0.5
Median
3.0
Max
40.0
Q1
2.0
Avg
5.9
Q3
5.0

Homework

Min
2.0
Median
5.0
Max
30.0
Q1
3.0
Avg
6.4
Q3
6.0

Question breakdown

Correctness and answer distribution per question.

1. [Find New Best CAGR]

27 / 31 correct (87.1%)

1 1.1405 0 (0.0%)
2 1.1376 27 (87.1%)
3 1.1453 2 (6.5%)
4 1.1326 1 (3.2%)

2. [Less Features is More]

28 / 31 correct (90.3%)

1 1.1351 0 (0.0%)
2 1.1395 2 (6.5%)
3 1.1321 28 (90.3%)
4 1.1415 1 (3.2%)

3. [Predicting Strong Future Growth]

21 / 31 correct (67.7%)

1 1.1055 21 (67.7%)
2 1.1145 5 (16.1%)
3 1.1225 2 (6.5%)
4 1.1277 3 (9.7%)

4. [EXPLORATORY] Describe Your Ideal Strategy

31 / 31 correct (100.0%)

Answer Count
See the Homework URL(in Question 4) 1
With a total capital of $100, my trading strategy involves splitting the funds equally, allocating 50% to high-frequency trades and the other 50% to slower, market-neutral strategies. The high-frequency trades will focus on risky assets and implement a 20% stop-loss to manage risk effectively. Profits and losses from both trading approaches will be shared equally to maintain the overall 50/50 portfolio balance. 1
https://github.com/DataTalksClub/stock-markets-analytics-zoomcamp/blob/main/cohorts/2024/homework%204.md 1
Increase or decrease the size of the bet according to the strength of the probability, so that stronger probabilities get more dollars invested. 1
After stock distributed dividend the price naturally drop and if pred=1 and price drop in one week after distributed dividend period invest doubled 1
See last notebook entry. 1
Strategy Overview Objective: Enhance the use of capital, improve efficiency, and optimize returns based on predictions. Key Components: Prediction combination, capital utilization, trade efficiency, risk management, and portfolio optimization. Specific Strategy Details 1. Prediction Combination Ensemble Predictions: Combine multiple prediction models to form a more robust prediction. Methods: Use weighted averages, voting systems, or stacking models. Implementation: Develop an ensemble model that considers the confidence level of each individual model's predictions. 2. Capital Utilization Dynamic Allocation: Adjust the investment amount based on the confidence level of predictions. Confidence Score: Allocate more capital to predictions with higher confidence scores. Risk-Adjusted Allocation: Allocate capital based on the expected risk and reward ratio. 3. Trade Efficiency Threshold-Based Trading: Only execute trades when predictions exceed a certain confidence threshold. Implementation: Set a minimum confidence score for executing trades to reduce the number of trades and focus on high-probability opportunities. Position Sizing: Use a position-sizing algorithm to determine the optimal amount to invest in each trade. Kelly Criterion: Use the Kelly formula to calculate the optimal size for each trade based on the edge and variance. 4. Risk Management Stop-Loss Orders: Implement stop-loss orders to limit potential losses on each trade. Dynamic Stop-Loss: Adjust stop-loss levels based on the volatility and confidence of the predictions. Take-Profit Orders: Set take-profit levels to lock in profits when certain targets are reached. Trailing Stop: Use trailing stops to secure profits while allowing the position to run. 5. Timing of Entry/Selling Optimal Entry Points: Use technical indicators (e.g., moving averages, RSI) to refine entry points. Entry Timing: Wait for confirmation signals from technical indicators before entering a trade. Exit Strategies: Implement rules for exiting trades based on price targets, technical indicators, or time-based rules. Time-Based Exit: Close positions after a predefined holding period if other exit conditions are not met. 6. Portfolio Optimization Diversification: Diversify investments across different assets to spread risk. Sector Diversification: Ensure exposure to multiple sectors to mitigate sector-specific risks. Rebalancing: Regularly rebalance the portfolio to maintain desired asset allocation and risk levels. Periodic Review: Conduct periodic reviews (e.g., monthly or quarterly) to adjust the portfolio based on performance and changing market conditions. 7. Market-Neutral Strategies Short Trades: Include short trades to profit from negative predictions and achieve a market-neutral strategy. Pair Trading: Identify pairs of correlated assets and execute long/short trades based on prediction differentials. Hedging: Use derivatives (e.g., options, futures) to hedge against market risks. Implementation: Develop a hedging strategy to protect the portfolio from significant market downturns. Implementation Plan Data Preparation: Gather and preprocess data for prediction models and technical indicators. Model Development: Train and validate multiple prediction models; develop ensemble model. Backtesting: Backtest the trading strategy on historical data to evaluate performance. Optimization: Optimize parameters for position sizing, stop-loss levels, and entry/exit rules. Live Trading: Implement the strategy in a live trading environment with continuous monitoring and adjustments. Continuous Improvement Performance Monitoring: Regularly monitor the performance of the strategy and make necessary adjustments. Machine Learning Updates: Continuously update prediction models with new data to improve accuracy. Strategy Review: Periodically review and refine the overall strategy based on market conditions and performance outcomes. 1
To maximize CAGR while minimizing risk and trade frequency, we can combine predictions from multiple models to form a consensus, investing more in trades with higher confidence levels. By setting higher thresholds for trades, we ensure only the most confident predictions are acted upon, reducing overtrading and transaction costs. Implementing stop-loss and take-profit orders helps manage risk, while technical indicators optimize trade timing. Diversifying the portfolio across different assets and geographies spreads risk effectively. Using market-neutral strategies like pairs trading hedges against market movements, aiming for profit from relative performance. Continuous monitoring and adjustment based on market conditions are essential for maintaining strategy effectiveness. 1
1. Enhanced Prediction Utilization: For the models we use, instead of outputting only binary 0/1 results, we can output probability scores (applicable to both decision and random forest classifiers). By utilizing probability scores, we can adjust our investment amounts based on the confidence level of the predictions. This approach allows for more nuanced capital allocation, rather than using a uniform investment amount for each prediction, similar to the “grid trading” or “turtle trading” methods. 2. Stop Loss Implementation: It appears that the current model environment does not have a clear stop loss rule. Without a stop loss, significant downturns could lead to severe losses. Therefore, we should establish a clear exit mechanism. For instance, we could implement a rule such as “exit the trade if the value decreases by 5%-10% from the entry point.” This would help mitigate potential losses and protect the trading capital. 1
I would hold the stock longer, about 30d, also would fit the model considering the profit of at least 2%. Would explore the best buy threshold considering a ROC curve. 1
https://docs.google.com/document/d/1lof5JTEfxc10G5_Elb_2d0RKMyiLtVpjSGhg7O0XvwI/edit?usp=sharing 1. Combining Predictions: 1.1. Use an ensemble approach where multiple models' predictions are combined to make a final decision. For instance, take a weighted average of predictions from different models and set a threshold for trading. # Example predictions from multiple models combined_prediction = (pred1 + pred2 + pred3 + pred4) / 4 final_prediction = combined_prediction > threshold 1.2. - Use an ensemble approach where predictions from multiple models are combined to make a final decision. - Set a threshold for trading based on the combined signal. - Implement a filter to only take trades when multiple models (e.g., at least 2 out of 4) give a signal simultaneously. # Example predictions from multiple models pred1 = model1.predict_proba(X)[:, 1] pred2 = model2.predict_proba(X)[:, 1] pred3 = model3.predict_proba(X)[:, 1] pred4 = model4.predict_proba(X)[:, 1] # Combine predictions and set threshold threshold = 0.5 combined_predictions = (pred1 > threshold) + (pred2 > threshold) + (pred3 > threshold) + (pred4 > threshold) # Only take trades if at least 2 out of 4 models give a signal final_prediction = combined_predictions >= 2 2. Capital Utilization: 2.1. Allocate a fixed percentage of the portfolio to each trade instead of a fixed amount. This ensures proportional risk and potential return. # Allocate 2% of portfolio per trade trade_amount = portfolio_value * 0.02 2.2. Reinvest profits from successful trades back into the portfolio. This means recalculating the trade amount after each trade based on the new portfolio value to compound gains over time. # Reinvest trade result and allocate 2% of portfolio per trade portfolio_value += trade_result trade_amount = portfolio_value * 0.02 2.3. Use grid positioning with volume increase at levels of probability signals of positive growth. trade1_amount = portfolio_value * 0.01 trade2_amount = portfolio_value * 0.02 trade3_amount = portfolio_value * 0.04 3. Optimizations: 3.1. Stop Loss: Set a stop loss to limit potential losses on each trade. stop_loss_price = entry_price * 0.95 # 5% stop loss 3.2. Portfolio Optimization: Diversify the portfolio to manage risk better and optimize for the best risk-adjusted returns. Recalculate the portfolio_value for each model annually or quarterly using a capital allocation model (risk parity, static allocation, Markowitz). 3.4. Short Trades: Include short trades to profit from downward movements and achieve a market-neutral strategy. 1
One idea could be to invest more money if the confidents score is higher. In addition, we should maximise potential losses by integrating a threshold. If we loose more than 10$, we sell an limit losses. 1
For my ideal trading strategy, I would aim to optimize capital utilization, reduce the number of trades, and include risk management techniques: Ensemble Predictions: Combine multiple model predictions (e.g., Random Forest, Decision Tree, Logistic Regression) using a weighted average or majority vote. Models with historically higher accuracy get higher weights, Risk Management: Cap the maximum capital allocated to a single trade to avoid overexposure (e.g., no more than 5% of the total portfolio per trade), Entry Timing: Implement a time-weighted entry strategy to avoid market noise. For instance, enter trades during low volatility periods, Exit Strategy: Use trailing stops to lock in profits while allowing for potential gains. Set stop-loss levels based on historical volatility and average true range (ATR) to minimize losses. 1
My ideal trading strategy aims to maximize returns while minimizing risk and trading costs. This strategy combines multiple prediction models, employs capital allocation techniques, and includes risk management features such as stop-loss orders. The strategy will focus on long and short positions to achieve market-neutrality and use portfolio optimization to diversify investments effectively. 1
Adjust the amount of money to be invested in each stock based on the volatility of stock returns in recent days. 1
Building upon the theory of Question 3, one way I would attempt to improve the trading strategy would be to invest in each strongly positive prediction (not just each positive prediction). Theoretically this would redirect capital to only those predictions that the model is strongest about, and would also achieve more efficiency by reducing the number of trades. 1
Define predictions: Use model predictions (e.g. pred5_clf_10, pred6_clf_best) to generate trading signals. Combine those signals from multiple models and require consensus for a trade. Capital allocation: a percentage of the portfolio to each operation, adjusting confidence levels. Entry/Exit Rules: Enter trades at the market open, use trailing stops, and set take profit levels. Risk Management: Implement stop loss at 2% below entry price and take profit with 5% profit. Rebalance the portfolio periodically to ensure diversification. 1
1. Use threshold where the predicted return is greater than 2% 2. Stop loss when fall into 3-5% 3. Take profit when reach 5% 1
Invest more is the probability of growth is higher 1
I choosed pred53_rf_best_rule_53. sim2_growth_capital_4y= 1.67 and sim2_CAGR= 1.137601 1
Model Selection: Focus on models like pred13_rf_best_rule_53 and pred16_rf_best_rule_57 due to their proven track record of superior performance metrics. These models have shown higher CAGR and net revenue per investment compared to others within the tested threshold range (0.51 to 0.59). pred16_rf_best_rule_57 appears to be potentially more advantageous compared to pred13_rf_best_rule_53 due to lower trading fees, fewer trades, and higher average net revenue per investment, suggesting it may yield higher profits overall. Utilizing High-Confidence Predictions: Focus on predictions with high confidence levels, such as those identified by is_strong_positive_growth_5d_future = 1, to initiate trades. This approach ensures we capitalize on opportunities with higher potential returns. Risk Management with Stop-Loss: Implement strict stop-loss rules derived from historical data and volatility analysis to mitigate downside risk. This involves setting predefined thresholds to automatically exit positions if losses exceed a certain percentage. Profit-Taking Strategies: Incorporate profit-taking strategies to lock in gains at predetermined levels. This proactive approach aims to secure profits during favorable market conditions, aligning with our model's predictions. Capital Allocation Based on Performance: Allocate capital dynamically based on the strength of predictions. Assign more significant amounts to predictions with proven historical performance or higher confidence levels, optimizing overall portfolio returns. Maximizing CAGR: Identify strategies with the highest Compound Annual Growth Rate (CAGR) based on our model's predictions. This involves backtesting to validate performance and selecting strategies with optimal growth potential over the long term. Prioritize strategies like pred6_clf_best, which shows robust performance over time. Cost-Efficiency: Evaluate strategies not only on profitability but also on cost efficiency. Minimize trading fees relative to gross revenue to enhance net returns per investment, ensuring sustainable profitability. Diversification and Hedging: Diversify investments across assets or sectors to spread risk and protect against market volatility. Additionally, explore hedging strategies to further mitigate specific risks identified by the model. Timing and Entry Points: Optimize timing for entry and exit points based on market conditions and model predictions. This approach enhances precision in trade execution and minimizes exposure to adverse market movements. 1
Pick stocks with comparatively better fundamentals and a comparatively higher probability of >1-2% growth in 5-10 days. accordingly pick the dep var to be 5-10-30 days growth. Distribute capital among the stocks according to probability of high growth in next 5-10-30 days. 1

Calculated: 13 October 2024, 16:30