Building a Data-Driven Sales Analysis Dashboard with Dash, Plotly, and Logistic Regression

In today’s dynamic financial landscape, data-driven decisions are pivotal for successful sales strategies. The ability to visualise and analyse data before or during a sale can significantly impact outcomes. In this comprehensive blog post, we’ll explore how to build an interactive web application using the Dash framework and Plotly visualisation library. We’ll also dive into how logistic regression, a powerful machine learning technique, can enhance trading predictions.

Introduction to the dashboard

The code we’re discussing in this blog post showcases a combination of Dash, Plotly, and logistic regression in a dashboard for sales dealers. This tool empowers sales dealers to make informed decisions by providing real-time visualisations, predictive insights, and interactive components.

One component of the dashboard is a margin predictor. Using logistic regression, we can predict the percentage chance that a client will take a deal based on the margin offered. A margin that’s too wide may dissuade a client from trading, as the rate is further from the market than competitors.

Sales Dashboard
Sales Dashboard, clockwise from top left: Recent Trades, Breakdown of Products sold, Breakdown of trades that were captured vs missed, Recent Missed Trades

Data handling and machine learning

The initial sections of the code involve data preprocessing and machine learning model training. The dataset is imported into Pandas Dataframes and subjected to one-hot encoding for categorical variables TenorMargin. Logistic regression, a classification algorithm, is trained to predict trade acceptance based on features such as encoded tenor values and margins.. Logistic regression, a classification algorithm, is trained to predict trade acceptance based on features such as encoded tenor values and margins.

The logistic regression model is fitted using the encoded tenor and margin columns and the target variable MissedTrades:

# Target variable, the missed deals
MissedTrades = df['Missed']

# Fit logistic regression model
model = LogisticRegression(), MissedTrades)

Predicting trade acceptance probability

Central to the code is the calculate_acceptance_chance() function, driven by logistic regression. This function estimates the likelihood of trade acceptance based on user-input margin and tenor values. It involves encoding the tenor, preparing input data, and employing the trained model for prediction.

def calculate_acceptance_chance(margin, tenor):
    # Encode the tenor value
    tenor_encoded = pd.get_dummies([tenor], prefix=' Tenor').reindex(columns=df_encoded.columns, fill_value=0)

    # Create the input data for prediction with encoded tenors and the margin
    input_data = pd.concat([tenor_encoded, pd.DataFrame({'Near All-in Mgn': [margin]})], axis=1)

    # Predict acceptance probability
    acceptance_prob = model.predict_proba(input_data)[0][1]

    # Calculate percentage chance
    percentage_chance = (1 - acceptance_prob) * 100

    return percentage_chance

Interactive visualisation for informed decision-making

The dashboard was built using Dash and Plotly. These provide a wide selection of interactive components for in-depth data exploration. I used:

  • Dropdowns for selecting currency pairs and filtering the data
  • Date range picker for selecting specific time periods of the data
  • Bar charts, pie charts, and scatter plots for visualisations

These visualisations, dynamically updated based on user input, offer traders insights into trade trends, missed trade analysis, product sales distribution, and more.

A breakdown on the number of missed trades over the month of January with a trend line

Empowering sales with insights

The combination of logistic regression with the interactive dashboard transforms the dashboard from just a visual representation app into an interactive space where sales dealers can input a margin and tenor to predict trade acceptance likelihood. This predictive capability can guide sales dealers in making informed decisions, thereby optimising their strategies for better outcomes.

The ability to input a number of pips and choose a tenor, with the output being the percentage chance of acceptance from the client


This blog post showcases the integration of Dash, Plotly, and logistic regression in a dashboard that could be used by sales dealers. By combining interactive visualisations with predictive modelling, sales teams are equipped with a powerful tool for data-driven decisions. This comprehensive approach not only exemplifies the potential of predictive technology in finance, but also highlights the opportunities for synergy between data science and sales potential. Whether you’re an aspiring data scientist or a seasoned sales dealer, exploring and expanding upon this code can elevate your understanding and capabilities at the intersection of finance and technology.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *