print(result) "Part 6 of NotADev"

Search for a command to run...

No comments yet. Be the first to comment.
In this series, I will venture the down a path of development using various languages, mainly Python, and utilise AI for the majority if not all of the code generation.
When I first sat down to create the Single File AI-Agent (SFA), my goal was ambitious yet straightforward: to streamline the process of security analysis for smart contracts by using a fully localised AI-driven system. The inspiration for this projec...
The Need for Rigorous Validation As Solidsight matured, accuracy became paramount. One key improvement was ensuring generated Mermaid diagrams were accurate and meaningful, addressing the occasional production of invalid placeholder diagrams by the L...

Rationale for Session Management As Solidsight's capabilities expanded, managing historical analysis data became increasingly important. The next logical step was introducing structured session management, allowing users to revisit previous analyses ...

Expanding the Tool's Capabilities Smart contract analyses can vary greatly in complexity and purpose. Realising this, I added support for multiple LLM models, allowing users to tailor analyses according to specific needs. This flexibility transformed...

Overview Versions 4 and 5 saw significant strides in workflow optimisation, making the SFA more practical and user-friendly. Efficiency and redundancy elimination became central to these iterations. Duplicates A key feature introduced was a robust du...

Motivation for Change Although Solidsight was becoming powerful, its plain text outputs lacked readability. To address this, I integrated the Rich library, significantly enhancing the visual appeal and clarity of the command-line interface. Implemen...

In the last article, I talked about how I collaborated with ChatGPT to introduce new features to my trading model, such as Recursive Feature Elimination (RFE), XGBoost, and hyperparameter tuning. With these enhancements, the next challenge was ensuring that my trading script could properly make use of the newly trained model. In this article, I'll discuss how I worked with ChatGPT to overcome the challenges of integrating the updated model into the trading logic.
With the upgraded model featuring 17 new indicators, including the Average Directional Index (ADX), Momentum (MOM), and Rate of Change (ROC), it became apparent that my existing trading script needed significant changes to handle the expanded feature set. This was not just a simple update; it required a comprehensive alignment between the feature engineering used during model training and the real-time data preparation for trading decisions.
One of the most crucial aspects was ensuring consistency in feature names and their order. I noticed that, when the trading script tried to make predictions using real-time market data, it frequently ran into errors because the features did not match those expected by the model. The model would raise an error due to either missing features or incorrect ordering, resulting in frustrating setbacks.
After explaining these challenges to ChatGPT, it proposed a solution to ensure feature alignment throughout the scripts. Here's a snippet showing how I extracted and prepared the features for real-time predictions:
# Extracting features in the same order as during training
features_df = pd.DataFrame([features], columns=FEATURE_COLUMNS)
features_df = features_df.fillna(0) # Handling any missing values
# Making prediction
prediction_proba = model.predict_proba(features_df)
buy_proba = prediction_proba[0][1]
sell_proba = prediction_proba[0][0]
To maintain consistency, I had to revisit the feature engineering steps I used during model training and replicate them exactly in the trading script. This meant incorporating calculations for all 17 features, such as the Exponential Moving Average (EMA), Bollinger Bands, and others, ensuring the order was identical.
Below is a snippet that shows the feature calculation in real-time within the trading script, which mirrors what was done during training:
# Calculate features for real-time data
latest_data['ema50'] = talib.EMA(latest_data['close'], timeperiod=50)
latest_data['ema200'] = talib.EMA(latest_data['close'], timeperiod=200)
latest_data['adx'] = talib.ADX(latest_data['high'], latest_data['low'], latest_data['close'], timeperiod=14)
latest_data['mom'] = talib.MOM(latest_data['close'], timeperiod=10)
# ... calculate other features as well
Once I had ensured the features were calculated consistently, ChatGPT suggested a way to handle any potential discrepancies by checking for missing or unordered features and then adjusting accordingly. This helped prevent runtime errors and allowed the model to predict as expected.
Another improvement ChatGPT helped me make was incorporating recent market activity to improve the accuracy of predictions. The idea was to add a "run rate" feature that considered recent volume trends and volatility. This helped the bot become more context-aware, allowing it to factor in the recent momentum of the market when making decisions. Here’s a simplified example of how this was integrated:
# Calculate recent volume trend
latest_data['volume_change'] = latest_data['volume'].pct_change(periods=3)
# Calculate rolling volatility
latest_data['volatility'] = latest_data['close'].rolling(window=10).std()
These additional metrics allowed the model to weigh recent market conditions more heavily, giving it a better edge in predicting buy and sell opportunities.
Throughout this process, I faced multiple errors. The infamous "feature mismatch" error returned multiple times, and the challenge of handling NaN values or incomplete data meant I had to be meticulous. ChatGPT was instrumental in suggesting techniques such as filling missing values with zeros or calculating forward fill methods to handle incomplete data, ensuring no features were left undefined.
Here is an example of how I handled missing values to avoid model errors:
# Handle missing values
features_df = features_df.fillna(0) # Replace NaN values with zero to avoid prediction errors
ChatGPT's approach to problem-solving here was iterative: each time an error was encountered, it would analyse the traceback, suggest corrections, and propose enhancements. It felt like a collaborative debugging session, and over time, these iterative fixes made my bot much more resilient to runtime issues.
After many rounds of testing and troubleshooting, the new trading script, combined with the enhanced model, was finally able to operate smoothly. The bot could now consistently make predictions using all 17 features, providing a more comprehensive analysis of the market. The integration of recent market activity indicators added an extra layer of context, further improving the bot's decision-making abilities.
The improvements in prediction accuracy were evident—the bot was now making fewer false-positive trades and identifying profitable opportunities with more reliability. The journey was challenging, but having ChatGPT as a guide made all the difference, providing insights and coding solutions whenever I encountered roadblocks.
Stay tuned for the next article, where I'll share how I worked on optimizing the bot's transaction logic, minimizing transaction costs, and further improving overall profitability.