AutoStocks: Automated Stock Reporting System
AutoStocks: Automated Stock Reporting System
A
Project Report
on
AUTOSTOCKS: AUTOMATED WEEKLY STOCKS REPORTING
SYSTEM
for the award of
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE & ENGINEERING
Submitted by -
SOURAV KUMAR (21105128012)
RITIK (21105128046)
ANUSHKA SAUMYA (21105128024)
1
Dedicated to
My Parents, Teachers, and Friends.
2
DECLARATION
I declare that the project entitled “AutoStocks: Automated Weekly Reporting System for
Stocks, Crypto, and Mutual Funds” is our work conducted at B. P. Mandal College of
Engineering Madhepura (Bihar), approved by the Committee. I have attended more than
90 days of attendance with the Supervisors at the B. P. Mandal College of Engineering,
Madhepura.
I further declare that, to the best of our knowledge, the report does not contain the work
which has been submitted for the award of the degree either in the University or in any
other University/Deemed University without proper citations.
2 RITIK 21105128046
Dated: ………………….
Place: MADHEPURA
3
B. P. Mandal College of Engineering
Madhepura (Bihar) - 852128
Affiliated to
Bihar Engineering University Patna, (Bihar), India.
CERTIFICATE
This is to certify that the project report entitled “AUTOSTOCKS: AUTOMATED WEEKLY
REPORTING SYSTEM FOR STOCKS, CRYPTO, AND MUTUAL FUNDS” is a piece of
project work done by SOURAV Kumar (21105128012) , RITIK (21105128012) ,
ANUSHKA SAUMYA (21105128024) under our guidance and supervision for the
completion of 8th Semester, Bachelor of Engineering of B. P. Mandal College of Engineering,
Madhepura, Bihar (India). The candidate has put in the required attendance of more than 90
days with me. To the best of our knowledge and brief the project.
Date
Place
4
B. P. Mandal College of Engineering
Madhepura (Bihar) - 852128
Affiliated to
Bihar Engineering University Patna, (Bihar), India.
ACKNOWLEDGEMENT
We express our sincere thanks to our respected project supervisor Prof. Praveen Kumar,
Assistant Professor, Department of Computer Science and Engineering, B. P. MANDAL
COLLEGE OF ENGINEERING, MADHEPURA for her guidance, encouragement and
motivation towards real-time research work right from the beginning of the research up to
the completion of this dissertation. It was a pleasure to work under his supervision. She
was always available with new ideas and suggestions during the difficult phases of our
dissertation. All the help is gratefully acknowledged. We sincerely thank Prof. Murlidhar
Prasad Singh, as the Head of the Department of Computer Science & Engineering, for
their kind support and permission to use the facilities available in the institute. We would
like to extend our thanks to all the lab assistants who have been there whenever we needed
the resources.
Our thanks go to all the staff of the Department of Computer Science and Engineering.
B. P. MANDAL COLLEGE OF ENGINEERING, MADHEPURA for their continuous
support throughout the dissertation work. Last, but not least. We also want to give a
warm thanks to all our classmates and non-technical staff. Without their thankful hand
we could never complete our dissertation successfully.
5
ABSTRACT
This project report presents the development of an end-to-end automated stock reporting system,
designed to streamline the generation and delivery of customized market reports for users based on
their preferences. The system is built around a modular three-pipeline architecture, each
addressing a key part of the data lifecycle—from user interaction and data fetching to analytics and
final report delivery.
The platform accepts user input (email, phone number, asset preferences) via a simple Flask-based
frontend, processes stock/crypto/mutual fund data using scheduled APIs, performs technical
analytics, and ultimately generates a comprehensive, stylized PDF report sent via email. All of this
occurs with minimal human intervention, enabling users—traders, investors, or analysts—to receive
timely and actionable insights directly in their inboxes.
Technologically, the system leverages GitHub Actions for scheduled task automation,
PostgreSQL on Render for backend database support, and multiple financial APIs for real-time
data ingestion. The second pipeline processes and visualizes asset trends using tools like Plotly,
Matplotlib, and custom-built logic for calculating indicators (e.g., moving averages, RSI). The final
pipeline handles the generation of PDFs using weasyprint, complete with visualizations,
personalized summaries, and final delivery via Gmail API email automation.
This report outlines the project’s motivation, the current gap in customizable market reporting, and
the benefits of a modular, automated approach. It discusses the challenges faced—such as secure
credential management, API handling, and rendering issues—as well as the methodologies used to
overcome them. Special emphasis is given to system architecture, deployment using Render, and
CI/CD pipelines configured via GitHub workflows.
Future iterations of the platform may include a video report generator and publisher pipeline
(under development), AI-driven stock recommendations, and a mobile app for real-time
notifications and interactive dashboards.
Overall, the system stands as a scalable, production-ready solution aimed at simplifying and
accelerating financial decision-making through automation and smart integration.
6
Table of Contents
8
Introduction
In today’s fast-paced financial landscape, individual investors and enthusiasts often lack the time,
tools, or technical expertise to track and analyze market data across multiple asset classes like
stocks, cryptocurrencies, and mutual funds. Traditional platforms either provide generic dashboards,
require manual data collection, or are hidden behind expensive paywalls. To bridge this gap, we
developed a fully automated, customizable, and scalable web-based system that generates and
delivers personalized market intelligence reports directly to users’ inboxes.
This project introduces a three-pipeline architecture, each dedicated to a core responsibility: user
interaction, data aggregation and analytics, and report generation with automated delivery.
The entire flow is designed to be hands-free, requiring the user only to select the desired financial
assets once, after which the system continuously fetches live data, applies analytics, and delivers
insightful, chart-rich PDF reports daily or weekly.
Built using a range of technologies—Flask, PostgreSQL, GitHub Actions, Matplotlib, Plotly, API
integrations, weasyprint, and Render hosting—the system ensures not only data reliability and
report quality but also high automation through CI/CD and scheduling tools. The architecture is
modular, making it easy to expand with future capabilities like AI-based forecasting, auto-generated
videos, or voice assistant integration.
With a strong focus on usability, automation, and precision, this project offers an innovative
approach to democratizing financial insights. The following chapters delve into each component
in detail—from the user interface and backend processing logic to the report structure and
deployment pipeline—making this document a comprehensive guide to building end-to-end, real-
time market intelligence systems.
AIM AND OBJECTIVE
AIM: -
OBJECTIVE:
To create a user-friendly frontend for users to select their preferred stocks, cryptos, or mutual
funds and input contact details like email or phone number.
To build backend pipelines capable of fetching and aggregating real-time data using reliable
APIs, and applying analytical techniques such as moving averages, RSI, and time-series
visualizations.
To generate dynamic PDF reports using templated layouts enriched with charts, tables, and
summaries, and automate their delivery to users through email.
To schedule and automate the complete workflow—from data fetching to report generation to
email delivery—using tools like GitHub Actions jobs.
To ensure secure storage of user preferences and data using PostgreSQL hosted on Render, with
reliable authentication and backup mechanisms.
To make the system extensible for future integration with modules like video generation, AI-
driven predictions, or voice-based insights.
To ensure that the platform runs with minimal human supervision by incorporating fault
detection, error handling, and retry mechanisms in each pipeline.
To maintain the open-source nature of the project and provide detailed documentation and
flowcharts so other developers or users can contribute or deploy their own version.
10
TECH STACK WE USED
Python & Flask
Python serves as the core programming language for this project, handling the backend logic and
data processing tasks. Flask, a lightweight and flexible web framework, powers the user interface
and API endpoints. Flask's Jinja2 templating engine is used to render HTML pages, while
extensions like Flask-WTF are employed for secure form handling and CSRF protection.
[Link]
[Link] hosts the deployed Flask application and manages scheduled tasks using its built-in
cron job feature. The platform supports free-tier deployment and integrates well with continuous
delivery pipelines. Gunicorn is used as the WSGI server to run the Flask app in production.
PostgreSQL
PostgreSQL is used as the primary relational database to store user data and analytics. It runs on
Render’s managed PostgreSQL service. Database connectivity is managed using psycopg2 or
SQLAlchemy, with configuration handled securely via environment variables.
Visualization
Matplotlib and Plotly are used to create dynamic charts and graphs that visualize financial trends.
These visual assets are saved as image files and embedded within the final PDF reports.
PDF Generation
PDF reports are generated using libraries such as weasyprint or FPDF. HTML CSS supports
complex and customizable layouts, while FPDF offers simpler integration through its HTML
mix-in. These reports contain a mix of visual charts and analytical summaries.
Email Sending
Python’s smtplib and Gmail API is used to automate the delivery of weekly PDF reports via
email. When using Gmail API, secure OAuth credentials are stored and managed according to
best practices.
11
Chapter 1: Introduction
The development of the AutoStocks system is informed by existing solutions and technologies in
the domain of financial data analysis and automated reporting. This chapter reviews relevant
systems and the technological landscape, highlighting the niche AutoStocks aims to fill.
A variety of tools exist for financial reporting and portfolio tracking, each with its strengths and
limitations when considered for personalized, automated retail investor reports.
The automation of financial reporting leverages a mature ecosystem of tools and programming
libraries, particularly within Python.
A key differentiator for AutoStocks is its focus on customization and full automation, addressing
a common pain point for individual investors.
Off-the-shelf solutions and generic market reports "rarely allow fully customized
portfolios and automated distribution" Investors often have unique combinations of assets
and prefer reports tailored to their holdings and delivered on their schedule.
"Customization is crucial: users should receive only the metrics and charts relevant to
their selected assets". This personalized approach enhances the relevance and utility of
the reports.
Automating the entire process, from data fetching to email delivery, saves users
significant time and effort, aligning with the trend where "automation allows for quick
and efficient scenario analysis" and routine tracking.
The literature and existing tool landscape reveal a strong interest in automating financial data
analysis. However, many solutions are either too broad, too expensive, not fully automated, or
lack deep personalization for individual retail investors.
.
Chapter 3: System Design and Architecture
o Web Frontend: The user-facing interface for subscription and asset selection.
o Database: Persistent storage for user profiles, asset selections, and potentially
cached data.
o Analytics Engine: Backend services responsible for data fetching, processing, and
financial calculations.
1. User Interface (UI): A Flask-based web application presents an HTML form for
users to input their email address and select their desired financial assets (stocks,
cryptocurrencies, mutual funds).
2. Data Capture & Validation: User input is validated and then stored in a
PostgreSQL database.
1. Scheduled Trigger: A cron job (via GitHub Actions or Render Cron) initiates this
pipeline at regular intervals (e.g., weekly).
2. Data Retrieval: The system reads user preferences and selected asset lists from the
database. It then queries external financial APIs (Alpha Vantage, CoinMarketCap,
Yahoo Finance) to fetch historical and recent price data for these assets.
3. Data Processing & Analysis: The raw data undergoes cleaning (handling missing
values, aligning time series). Financial analytics are then computed, including
returns, moving averages, RSI, MACD, and other relevant technical indicators,
using Python libraries like Pandas and ta.
4. Visualization Preparation: Data for charts (e.g., price trends, indicator plots) is
prepared.
1. Report Compilation: Using the analytics and chart data from Pipeline 2, a
structured PDF report is generated. This involves populating a pre-designed
template with text summaries, tables of metrics, and embedded charts.
2. Emailing: The generated PDF report is attached to an email and sent to the user's
registered email address using Gmail SMTP.
This pipeline is triggered automatically after the completion of Pipeline 2
analytics.
3.3. Key Technologies Used
The AutoStocks system leverages a combination of open-source tools and cloud services to
deliver its functionality.
Backend:
o Python 3.x: The primary programming language for all backend logic, chosen for
its extensive libraries and suitability for data analysis and web development.
o Flask: A lightweight Python web framework used to build the user interface and
API endpoints for Pipeline 1.
Frontend:
Data APIs:
o Pandas: For data manipulation and analysis, particularly with time-series data.
o Matplotlib (or Plotly): For creating static charts and graphs to be embedded in the
PDF reports.
Automation & Deployment:
o GitHub Actions: For CI/CD (automating testing and deployment to Render) and
for scheduling the execution of Pipeline 2 and Pipeline 3 (data aggregation,
analytics, report generation, and emailing).
o [Link]: The cloud platform for hosting the Flask web application and the
PostgreSQL database.
Emailing:
o smtplib (Python standard library) / Gmail API: For sending emails with PDF
attachments.
1. Ingestion: User data (email, asset choices) is ingested via the Flask web form. Financial
market data is ingested from external APIs. Updated asset lists are ingested by a
scheduled script.
2. Storage: User subscription data and selected assets are stored persistently in the
PostgreSQL database. Fetched market data might be temporarily stored or processed in
memory during pipeline execution.
3. Transformation: Raw market data is cleaned, aligned, and transformed into calculated
metrics and indicators.
4. Output: The primary output is the personalized PDF report, delivered via email. Logs are
generated for monitoring.
Secrets Management: API keys, database credentials, and email service passwords are
managed securely using GitHub Secrets for automation workflows and environment
variables on Render for the deployed application. They are not hardcoded.
HTTPS: The web application deployed on Render runs over HTTPS, encrypting data in
transit between the user and the server.
Input Validation: User inputs (email format, asset tickers) are validated on both client and
server sides to prevent common injection vulnerabilities and ensure data integrity.
Pipeline 1 forms the initial touchpoint for users with the AutoStocks system. It is responsible for
capturing user preferences, managing their data securely, handling initial notifications, and
ensuring the system has an up-to-date list of available financial assets for users to choose from.
The user-facing component of Pipeline 1 is a web application built using the Flask
microframework in Python. Its primary purpose is to provide a simple and intuitive interface for
users to subscribe to the AutoStocks service.
o User's Email Address: The primary identifier for the user and the destination for
the weekly reports.
o Asset Selections: Users can select the stocks, cryptocurrencies, and mutual funds
they wish to track. This is implemented using a multi-select dropdown or a series
of checkboxes, populated dynamically with available assets.
o (Optional) Phone Number: This field might be included for future notification
features but is not essential for the core email reporting service.
The form is styled using HTML5 and CSS3 (potentially with a framework like Bootstrap for
responsiveness) to ensure a clean layout and usability across different devices. Minimal
JavaScript is used for client-side validation (e.g., checking email format) and enhancing user
experience (e.g., dynamic search within asset selection).
User subscription data and asset preferences are stored persistently in a PostgreSQL database,
hosted as a managed service on [Link].
An assets_master_list table might also exist to store all available tickers and their types (stock,
crypto, mutual fund), which is used to populate the selection form and validate user choices.
Data Persistence:
The Flask application interacts with the PostgreSQL database using a Python library
like psycopg2 (for direct SQL execution) or an ORM like SQLAlchemy (for a more
abstracted approach). Upon successful form validation, a new record is inserted into
the users table. Database connection details (host, port, username, password, database
name) are securely managed as environment variables on Render.
To ensure that users can select from a current list of financial instruments, a background process
regularly updates the master list of available stocks, cryptocurrencies, and mutual funds.
1. Fetches lists of popular or all available assets from reliable sources or APIs (e.g.,
exchange listings, financial data providers).
Confirmation Message:
This email serves to:
o Reiterate the email address provided and potentially the selected assets.
o Inform the user about the reporting schedule (e.g., "You will receive your first
weekly report next Sunday.").
This pipeline ensures a smooth onboarding experience and lays the foundation for the subsequent
automated reporting pipelines by capturing essential user data and preferences.
1. Frontend:
The user interacts with the website built using HTML, CSS, and JavaScript, providing a
responsive and interactive UI.
2. Backend:
The backend is powered by Flask, which handles routing, logic, and communication
between frontend and the server.
3. GitHub Actions:
Used for automating updates and deployment, ensuring the website content remains current
without manual intervention.
4. SMTP Email System:
When a user interacts (e.g., submits a form or request), an automatic email is triggered and
sent to the user using SMTP.
5. Database:
All user data is securely stored in a central database, which can later be accessed for
processing and generating reports or further actions.
Chapter 5: Pipeline 2 – Data Aggregation, Analytics, and Visualization
Reliable and timely financial data is the cornerstone of this pipeline. AutoStocks integrates with
several public APIs to source data for stocks, cryptocurrencies, and mutual funds.
1. Alpha Vantage: This API is a primary source, offering free (with rate limits)
access to historical and real-time data for stocks (e.g., TIME_SERIES_DAILY),
cryptocurrencies (Digital & Crypto Currencies endpoints), and even some mutual
fund NAVs. An API key is required and managed securely.
The system queries these APIs based on the asset tickers/symbols selected by each subscribed
user, as retrieved from the PostgreSQL database. Python's requests library or specific client
libraries for these APIs are used for making HTTP requests. Careful management of API keys
and adherence to rate limits (e.g., by introducing small delays between calls if necessary) are
crucial for sustained operation. Error handling is implemented to gracefully manage API
unavailability or invalid ticker responses.
Raw data obtained from APIs often requires preprocessing and cleaning before it can be used for
analysis. This stage ensures data quality and consistency.
Handling Missing Values: Financial data can have gaps due to market holidays (for
stocks and mutual funds), delisted assets, or API inconsistencies. Small gaps in time
series data (e.g., a single missing day's NAV for a mutual fund due to a bank holiday) are
handled using techniques like forward-fill (ffill) or backward-fill (bfill) in Pandas. If
significant data is missing for an asset, it might be excluded from that week's report for
that user, with a note.
Date Alignment and Timezone Management: When dealing with multiple assets,
especially across different classes (e.g., stocks trading on specific exchange hours vs.
24/7 crypto markets), it's important to align data on a common date index. All timestamps
are typically converted to a uniform timezone (e.g., UTC) for consistency.
Data Type Conversions: Price data is ensured to be in numeric (float) format for
calculations. Dates are parsed into datetime objects.
Outlier Detection (Basic): Spurious spikes or drops in data might indicate errors. Basic
checks (e.g., unusually large day-over-day percentage changes) can be implemented, and
such data points might be flagged or smoothed, though complex outlier removal is
beyond the initial scope.
All cleaned data is typically loaded into Pandas DataFrames for efficient manipulation
and analysis.
Once the data is clean, various financial metrics and technical indicators are computed for each
asset.
Returns:
o Overall Period Return: (End Price / Start Price) - 1 for the week.
o Simple Moving Averages (SMA): E.g., 50-day and 200-day SMAs (or shorter
periods like 10-day, 20-day for weekly reports) are calculated
using [Link](window=N).mean().
o Relative Strength Index (RSI): A momentum oscillator measuring the speed and
change of price movements. Calculated using [Link].
o Bollinger Bands: Bands plotted two standard deviations away from a simple
moving average, indicating volatility. Calculated
using [Link].
Other indicators from the ta library can be added as needed. The results of these
computations are typically added as new columns to the Pandas DataFrame for
each asset.
5.4. Generating Visualizations (Charts)
Visual representations of data and trends are key components of the financial report. Python
libraries like Matplotlib or Plotly are used to generate these charts, which are then saved as
image files (e.g., PNG) for embedding into the PDF.
Types of Charts:
o Price/NAV Time Series Chart: Line chart showing the asset's price or NAV over
the reporting period (e.g., last 7 days, last 30 days), possibly with overlays like
moving averages.
o Indicator Charts: Separate plots below the price chart for indicators like RSI or
MACD.
The entire Pipeline 2 workflow—from fetching user data to computing analytics and generating
chart images—is automated and scheduled.
Cron Job: A GitHub Actions workflow is configured with a cron trigger to run at a
specific time each week (e.g., every Sunday morning).
Workflow Execution: The workflow checks out the latest code, sets up the Python
environment, installs dependencies, and then executes the main Python script responsible
for Pipeline 2's operations. This script iterates through all subscribed users, processing
their selected assets.
Output Handling: The computed analytics and paths to the saved chart image files are
stored, ready to be picked up by Pipeline 3 for report generation. This could be by writing
to a temporary structured file (JSON), updating specific fields in the database, or passing
data directly if Pipeline 2 and 3 run in the same workflow execution.
Error handling throughout this pipeline is critical. Failures in fetching data for one asset should
not stop the processing for other assets or other users. Comprehensive logging captures the
progress and any issues encountered.
Connect to Database: Establish a secure connection to the PostgreSQL database containing user
and asset data.
Fetch User & Asset Data: Retrieve subscribed users and their chosen stock, crypto, or mutual
fund tickers.
Fetch Financial Data: Pull historical prices, fundamentals, and news for each asset using APIs
like yfinance and GoogleNews.
Analytics & ML Forecast: Clean data, calculate key metrics, and forecast short-term trends
using time-series models.
LLM Summary: Use an LLM to convert raw data and forecasts into short, human-like insights
per asset.
Generate Charts: Create visualizations such as price trends and technical indicators using
Matplotlib.
Create PDF Report: Compile personalized financial reports with analytics, charts, news, and
summaries.
Send Email: Email the generated PDF report to each user via Gmail SMTP.
Automation & Orchestration: Automate the entire workflow weekly using GitHub Actions
with robust error handling.
Chapter 6: Pipeline 3 – PDF Report Generation and Delivery
Pipeline 3 is the final stage in the AutoStocks workflow, responsible for transforming the
analyzed data and visualizations from Pipeline 2 into a professional, human-readable PDF report.
This report is then automatically delivered to the subscribed user's email inbox.
A well-designed report template is crucial for presenting financial insights effectively. The PDF
report aims to be concise, informative, and easy to understand.
1. Header: Includes the "AutoStocks Weekly Report" title, the reporting period (e.g.,
"Week ending [Date]"), and the user's email address (for personalization). A
simple logo could also be included.
Asset Name/Ticker.
Key Metrics Table: Start price, end price, percentage change for the week,
and perhaps key indicator values (e.g., current RSI, SMA values).
4. Returns Histogram (Optional): A chart showing the distribution of returns for one
or more key assets.
5. Footer: May include page numbers and a disclaimer (e.g., "Data for informational
purposes only.").
Styling:
Consistent styling is applied using fonts (e.g., Helvetica, Arial), appropriate font sizes for
headings and body text, and clear color schemes for charts (ensuring readability). The
layout prioritizes clarity and professional presentation.
6.2. PDF Generation (Weasyprint/FPDF)
Python libraries are used to programmatically generate the PDF documents. Weasyprint is a
powerful choice for complex layouts, while FPDF can be simpler for more straightforward
designs.
Library Choice: The selection between Weasyprint and FPDF depends on the desired
complexity and control over the PDF layout. Weasyprint offers more advanced features
with its "Platypus" high-level templating system, while FPDF is known for its ease of
use, especially if an HTML-like cell-based layout is sufficient.
o Add Text: Place headings, paragraphs of summary text, and table data onto the
PDF pages. Font styles, sizes, and alignments are controlled programmatically.
o Draw Tables: Create tables to display key metrics for each asset in an organized
manner.
o Insert Images: Embed the chart images (PNG files) generated in Pipeline 2 at
specific locations within the PDF document, ensuring appropriate scaling and
resolution.
The script iterates through each user's analyzed data and selected assets,
dynamically populating the PDF template. Each user receives a PDF tailored to
their specific subscriptions.
Once the personalized PDF report is generated, it is automatically emailed to the user.
o Subject: A clear and informative subject line, e.g., "Your AutoStocks Weekly
Financial Report."
o Body: A brief polite message, e.g., "Dear User, please find your weekly
AutoStocks report attached."
The generation and delivery of reports (Pipeline 3) are integrated into the automated weekly
schedule, typically following the completion of Pipeline 2.
Triggering:
Pipeline 3 can be a subsequent step within the same GitHub Actions workflow that runs
Pipeline 2. Once analytics are complete and charts are saved, the PDF generation and
emailing scripts are executed for each user.
Data Handoff:
The analytics results and paths to chart image files from Pipeline 2 are passed to the
Pipeline 3 scripts. This could be via temporary files, database entries, or in-memory data
structures if part of a single execution context.
Error Handling:
Robust error handling is implemented. If PDF generation fails for a user (e.g., a missing
chart file), that user's report might be skipped for the week, and the error logged. If email
sending fails (e.g., SMTP server issue), the system might attempt a retry or log the failure
for administrator review. The failure of one user's report should not prevent others from
being processed and sent.
This pipeline ensures that users receive their personalized financial insights in a convenient and
professional format directly in their inbox, fulfilling the core promise of the AutoStocks system.
Chapter 7: Deployment, Hosting, and CI/CD
[Link] is chosen as the Platform-as-a-Service (PaaS) provider for hosting the AutoStocks
web application and its associated database. Render simplifies infrastructure management,
allowing the focus to remain on application development.
3. Private Networking: Render's services within the same account and region can
typically communicate over a private network, enhancing security and reducing
latency between the web application and the database.
GitHub Actions is the backbone of automation for AutoStocks, handling Continuous Integration,
Continuous Deployment, and the scheduling of backend data processing and reporting pipelines.
o Installing dependencies.
o Running linters (e.g., Flake8, Ruff) to check code style and quality.
o Running automated tests (e.g., using Pytest) to ensure code correctness and
prevent regressions.
If any of these steps fail, the CI build is marked as failed, alerting developers to
issues before they are merged or deployed.
o Execute the Python scripts responsible for fetching data, performing analytics,
generating PDFs, and sending emails.
o Utilize GitHub Secrets for API keys and other sensitive credentials needed by
these backend scripts.
GitHub Secrets: API keys for financial data services (Alpha Vantage, CoinMarketCap),
email credentials (if used by scheduled tasks), and the Render API key (for CD) are
stored as encrypted secrets in the GitHub repository settings. GitHub Actions workflows
can securely access these secrets at runtime, and they are automatically redacted from
logs.
Render Environment Variables: Database credentials, email credentials (for the Flask
app's confirmation emails), and any other runtime secrets for the live application are
stored as environment variables in the Render dashboard for the Web Service and any
Cron Jobs run on Render.
This comprehensive approach to deployment and automation ensures that the AutoStocks system
is not only functional but also maintainable, scalable, and can be updated efficiently with
minimal manual intervention.
Chapter 8: Testing and Validation
Thorough testing and validation are crucial to ensure the AutoStocks system functions correctly,
reliably, and securely. This chapter outlines the testing strategy, types of tests conducted, and the
process for validating the system's outputs.
A multi-faceted testing approach is adopted, combining automated tests for core functionalities
and regression prevention with manual checks for user experience and end-to-end validation.
The primary tool for automated testing in Python is Pytest.
Functional Testing:
Ensures that each feature of the application works as intended from the user's perspective
or as per its defined role in the pipeline.
A variety of test cases are designed to cover the different aspects of the AutoStocks system:
TC1.1 (Valid Signup): Simulate submitting the signup form with valid
email and asset selections. Verify that a new user record is created in the
database and a confirmation email (mocked or sent to a test inbox) is
triggered.
TC1.4 (Asset List Update): Test the script that updates the master asset
list, ensuring it fetches and stores data correctly (can be tested in
isolation).
TC2.1 (Valid Ticker): Test the data fetching function for a known valid
stock, crypto, or mutual fund ticker. Verify that data is returned in the
expected format. (May involve mocking API responses to make tests
deterministic and avoid actual API calls during CI).
TC2.2 (Invalid Ticker): Test with an invalid ticker. Verify graceful error
handling (e.g., logging the error, skipping the asset).
TC2.3 (API Rate Limit/Error): Simulate an API error or rate limit. Verify
that the system handles this (e.g., retries, logs, continues with other
assets).
TC2.5 (Indicator Calculation - e.g., RSI): Provide sample price data and
verify that the calculated RSI matches a manually computed or known
reference value.
TC2.6 (Chart File Creation): Run the chart generation logic for sample
data. Verify that an image file (e.g., PNG) is created and is not empty.
(Deep inspection of chart content is harder to automate fully but file
existence is a good start).
TC3.1 (PDF Creation): Run the PDF generation script with sample
analytics data. Verify that a PDF file is produced.
TC3.3 (Email with Attachment): Test the email sending routine. Verify
that an email is sent to a test inbox with the correct subject and a PDF
attachment. (Often involves mocking the smtplib interaction during
automated tests).
o TC4.1 (Full Weekly Cycle): Manually subscribe with a test email and a set of
assets. Trigger the weekly pipeline (or wait for its scheduled run). Verify that a
PDF report is received via email and that its content accurately reflects the
selected assets and recent market data.
o TC4.2 (Error Resilience): Intentionally introduce an error (e.g., make one API key
invalid). Observe if the system logs the error correctly, skips the problematic part,
and continues processing for other users or assets where possible.
Automated Tests: The automated test suite (run via Pytest in GitHub Actions) aims for
high code coverage of critical modules. Passing tests provide confidence that core logic
functions as expected and that new changes do not introduce regressions. Test results
(pass/fail, coverage reports) are reviewed as part of the development cycle.
Manual Validation: Manual end-to-end tests confirm the usability of the signup process
and the accuracy and presentation quality of the final PDF reports. Feedback from any
pilot users is also incorporated.
Issue Tracking: Any bugs or issues identified during testing are logged, prioritized, and
addressed.
By combining these testing methodologies, the AutoStocks system is validated to meet its
functional requirements and maintain a high level of quality and reliability.
Chapter 9: Results and Discussion
This chapter presents the outcomes of the AutoStocks project, discussing the performance of the
developed system, the nature of the reports generated, and any feedback received. It reflects on
the successful implementation of the core functionalities outlined in the project objectives.
The AutoStocks system, with its three-pipeline architecture, was developed and deployed
successfully. Performance benchmarks for a typical user scenario (e.g., tracking 5-10 assets)
indicate efficient operation:
o Webpage load times for the subscription form are minimal, ensuring a responsive
user experience.
o Form submission and database write operations are typically completed within a
few seconds.
o Automated asset list updates (run less frequently) depend on the number of assets
being fetched but are designed to run as background tasks without impacting user-
facing services.
o Data Fetch: For a portfolio of 5-10 assets, fetching data from APIs (Alpha
Vantage, CoinMarketCap, Yahoo Finance) generally takes between 5 to 20
seconds, depending on API response times and any necessary rate-limiting
pauses.
o Chart Generation: Generating 5-10 Matplotlib charts and saving them as PNGs
takes approximately 2-5 seconds.
o PDF Generation: Assembling a multi-page PDF report (e.g., 3-5 pages) with text
and embedded charts using ReportLab/FPDF is efficient, usually taking 1-3
seconds.
o Email Send: Connecting to Gmail SMTP and sending an email with the PDF
attachment typically takes 2-5 seconds.
Overall Weekly Pipeline Execution Time:
For a single user with a typical portfolio, the entire automated weekly pipeline (Pipelines
2 and 3) completes in well under a minute (often 15-30 seconds). The system is designed
to process users sequentially in the current iteration. For a larger number of users, the
total execution time would scale linearly, but individual report generation remains
efficient. The free-tier API rate limits are the primary constraint on processing a very
large number of unique assets rapidly.
These benchmarks demonstrate that the system is efficient for its intended use case of providing
weekly reports to individual users.
The generated PDF reports successfully deliver personalized financial insights as intended.
o Asset Sections:
[Link]: Similar table and NAV chart for the HDFC mutual fund.
o Formatting: The PDF is well-formatted with clear headings, readable fonts, and
legible charts. The information is presented concisely.
The output aligns with the project's goal of delivering customized, automated financial
summaries. (Placeholders for screenshots of a sample email and PDF page would be referenced
here in a full report).
9.3. User Feedback (if available/applicable for a college project)
Initial informal feedback on the concept and sample reports has been positive, with users
appreciating:
Suggestions for future enhancements included the ability to modify asset lists post-subscription
via the UI and potentially adding brief news summaries relevant to the selected assets (though
news integration was out of the initial scope). No major functional issues were reported in the
core report generation and delivery mechanism during preliminary testing.
9.4. Discussion
The AutoStocks system successfully demonstrates the feasibility of creating a fully automated
pipeline for personalized financial reporting using readily available APIs, Python libraries, and
cloud hosting services. The modular three-pipeline architecture proved effective for organizing
the development and allows for future expansion. The use of GitHub Actions for CI/CD and task
scheduling significantly streamlines operations and maintenance.
While the current system is designed for individual retail investors and operates within the
constraints of free-tier APIs, the architecture provides a solid foundation for potential future
scaling and feature additions. The project effectively addresses the problem of manual, time-
consuming financial tracking by providing a "set-and-forget" solution for users.
Chapter 10: Conclusion and Future Work
The AutoStocks project set out to address the need for automated, personalized financial
reporting for individual investors. This chapter summarizes the project's achievements, discusses
challenges encountered, and outlines exciting avenues for future development, including the
planned expansion into automated video content generation.
Fully Automated Workflow: An end-to-end system that allows users to subscribe with
their asset preferences and receive customized weekly PDF reports via email without
manual intervention.
Multi-Asset Support: The system capably handles data aggregation and analysis for a
diverse range of assets, including stocks, cryptocurrencies, and mutual funds.
Personalized Reporting: Reports are tailored to each user's specific asset selections,
providing relevant insights rather than generic market summaries.
Robust Technology Stack: Effective use of Python, Flask, PostgreSQL, financial data
APIs (Alpha Vantage, CoinMarketCap, Yahoo Finance), ReportLab/FPDF, Matplotlib,
and cloud services ([Link]).
User-Friendly Interface: A simple web interface for user subscription, making the service
accessible.
The project has successfully met its primary objectives of automating data collection, performing
financial analytics, generating structured reports, and delivering them via email, all while
ensuring a degree of reliability and security.
API Limitations: Free-tier API rate limits required careful management and error
handling to ensure the system could operate without frequent interruptions, especially
when fetching data for multiple users or a large number of assets.
Data Consistency Across APIs: Different APIs sometimes provide data in varying
formats or with different levels of granularity, necessitating robust data cleaning and
normalization steps.
PDF Formatting Complexity: Achieving a polished and professional layout for PDF
reports, especially with dynamic content and embedded charts, using libraries like
ReportLab, involved a learning curve.
Scope Management: Balancing the desire for extensive features with the practical
constraints of a project timeline required careful prioritization of core functionalities.
Overcoming these challenges provided valuable learning experiences in building and deploying
real-world data-driven applications.
The current AutoStocks system provides a solid foundation for numerous future enhancements
that could further increase its value and user base:
o Allowing users to log in to update their asset list, change report frequency (e.g.,
daily, monthly), or unsubscribe via the web UI.
o Adding more advanced financial analytics, such as portfolio risk metrics (Sharpe
ratio, Value-at-Risk), correlation analysis, and fundamental data.
Interactive Reports:
Mobile Application:
o Developing a companion mobile app (e.g., using React Native or Flutter) for
easier subscription, viewing reports, and receiving push notifications.
o Conceptual Workflow:
1. Data Collection: Similar to Pipeline 2, fetch key market data (e.g., top
gainers/losers, index movements).
o For a larger user base, investigate more scalable infrastructure (e.g., Docker
containers managed by Kubernetes, using message queues like RabbitMQ or
Kafka for decoupling pipeline stages) and optimized database interactions.
o Consider paid API tiers for higher rate limits and more reliable data access.