Price Prediction & Market Analysis
Relevant source files
The following files were used as context for generating this wiki page:
Price Prediction & Market Analysis is a core intelligence module within MarketSage designed to provide users with deep financial insights into product listings. It leverages machine learning models and historical data tracking to evaluate whether a current price represents a good value, predict future price movements, and recommend the optimal time to purchase.
The system operates by aggregating data from multiple sources, including historical price points, market averages across platforms like Temu and AliExpress, and seasonal patterns. This information is processed through both heuristic-based analyzers and TensorFlow-powered neural networks to generate confidence-scored predictions and value ratings.
Sources: WHATAMI.txt:3-7, src/core/ai/PricePredictionEngine.ts:1-10, src/background/services/insight/priceAnalyzer.ts:1-15
System Architecture
The analysis pipeline is split between real-time heuristic evaluation and long-term predictive modeling. The PriceAnalyzer handles immediate market positioning, while the PricePredictionEngine utilizes deep learning for forecasting.
Analysis Flow
The following diagram illustrates how product data flows from the UI through the analysis services to produce insights.
Price Prediction Engine
The PricePredictionEngine is a TensorFlow.js-powered service that forecasts future prices. It uses a sequential neural network to process 15 specific features extracted from product history and market trends.
Model Architecture
The engine employs a multi-layer dense network:
- Input Layer: 15 features (price history, volatility, seasonal factors, competition).
- Hidden Layers: Two dense layers (64 and 32 units) with ReLU activation and L2 regularization to prevent overfitting.
- Dropout Layers: Applied at rates of 0.3 and 0.2 to improve model generalization.
- Output Layer: A single unit with linear activation for regression-based price forecasting.
Sources: src/core/ai/PricePredictionEngine.ts:75-103
Prediction Logic
The engine calculates an "Optimal Buy Time" based on the predicted price delta and the determined trend.
| Recommendation | Condition | Estimated Timeframe |
|---|---|---|
| wait | Decreasing trend & >10% expected drop | 1-2 weeks |
| buy_now | Increasing trend & >5% expected rise | Immediately |
| buy_soon | Stable trend or minor fluctuations | Next few days |
Sources: src/core/ai/PricePredictionEngine.ts:213-238
Market Analysis & Value Scoring
The PriceAnalyzer calculates the relative value of a product by comparing its current price against a calculated market average and seller metrics.
Value Score Calculation
The system generates a normalized score (0 to 1) using the following logic:
- Base Score: Calculated as
marketAverage / currentPrice. - Seller Adjustment: The score is adjusted by ±10% per rating point deviation from a baseline of 3.
- Normalization: The result is clamped between 0 and 1.
Sources: src/background/services/insight/priceAnalyzer.ts:55-68
Price Trends
Trends are determined by analyzing the three most recent price entries in the historical record.
User Interface & Feedback
The EnhancedInsightSection provides a comprehensive view of the analysis results, tailored to the user's security level (Basic, Enhanced, or Premium).
Insights Summary Components
- Price History: A chronological list of previous price points with timestamps.
- Market Intelligence: Alerts for significant drops, seasonal trends, and deal alerts.
- Competitor Comparison: (Premium/Enhanced) Live price data from competing retailers like Amazon or Best Buy.
Sources: src/popup/components/insight/EnhancedInsightSection.tsx:180-250, src/popup/components/insight/InsightSection.tsx:68-115
Implementation Example: Price Normalization
The system ensures data consistency by normalizing strings and currency before analysis.
static extractNumericPrice(priceText: string): number {
// Handle European formats and remove non-numeric separators
if (priceText.includes(',') && !priceText.includes('.')) {
priceText = priceText.replace(',', '.');
}
priceText = priceText.replace(/[^\d.,]/g, '');
const matches = priceText.match(/[\d.]+/);
return matches ? parseFloat(matches[0]) : 0;
}
Sources: src/common/utils/dataProcessing.ts:25-44
Data Models
PriceAnalytics Interface
The primary data structure returned by analysis services.
| Field | Type | Description |
|---|---|---|
currentPrice | number | The live price found on the page. |
marketAverage | number | Mean price across the platform/competitors. |
valueScore | number | Normalized rating of the deal quality. |
trend | rising|falling|stable | Direction of price movement. |
recommendations | string[] | Human-readable actionable advice. |
Sources: src/background/services/insight/priceAnalyzer.ts:4-13, src/common/types/index.ts:51-64
Summary
Price Prediction & Market Analysis provides a multi-layered evaluation of e-commerce listings. By combining TensorFlow-based forecasting with heuristic market comparison, MarketSage enables users to identify "Excellent" value opportunities and avoid purchasing during price peaks. The system relies heavily on cleaned historical data and real-time competitor tracking to maintain the accuracy of its recommendations.
Sources: src/core/ai/PricePredictionEngine.ts:1-5, src/background/services/insight/priceAnalyzer.ts:87-110