Skip to content

bisennikky/Backtest-Web-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

******* Python Trading Strategy Backtesting Application*********
# Overview
 This application allows users to perform backtests on trading strategies using historical data. It is built using Flask, with a simple web interface for submitting strategies and viewing results. The application supports:
Moving Average Crossover Strategy
Stop Loss Application
Users can load financial data, apply strategies, and visualize the results through interactive plots.

# Features
Python Script Development: The core logic of the application is written in Python, and includes data processing, strategy execution, and result plotting.
Strategy Automation: Strategies such as moving average crossover and stop loss are implemented and automated within the application.
Data Management: Data is loaded from Feather format files, processed, and results are stored in an SQLite database.
Open Source Contribution: The project is designed for extendability, allowing developers to add more trading strategies and data management techniques.

# Project Structure

├── app.py               # Main Flask application
├── templates
│   ├── index.html       # Homepage with form for input
│   └── results.html     # Page displaying backtest results
├── static               # Static files (CSS, JS)
├── data
│   └── data.feather     # Feather file containing historical data
├── sqlite.db            # SQLite database for storing backtest results
└── README.md            # This file



# Setup and Installation
  Requirements:
    Python 3.x
    Flask
    Pandas
    Plotly
    SQLite3
    Feather (for handling .feather files)


# Database Setup
  The database is initialized automatically when you run the application. The database stores the results of the backtest.

# Loading Data:
  The application expects historical trading data in .feather format. The data file should contain at least the following columns:
  Close: The closing price of the asset
  date: The corresponding date for the price
  Place the .feather file in the data/ folder with the name data.feather.

# Backtesting Strategies
  The following strategies are available:
  Moving Average Crossover: This strategy uses short-term and long-term moving averages to generate buy/sell signals.
  Short-term: 5-day moving average
  Long-term: 20-day moving average
  Stop Loss: This strategy applies a stop-loss condition, where a position is sold if the price falls by a certain percentage (default: 2%).

# Using the Web Interface
  Go to the homepage and fill out the form:
  Select the derivative (financial asset)
  Choose the expiry date in the format YYYY-MM-DD
  Select one or more timeframes (e.g., 'Daily', 'Weekly')
  Choose a strategy (Moving Average Crossover or Stop Loss)
  Submit the form to run the backtest. The results page will display:
  Total profit or loss from the backtest
  Number of trades made
  An interactive graph showing the price data and strategy signals



# Storing Results:
  Backtest results are stored in an SQLite database (sqlite.db) with the following structure:
  
  id	derivative	expiry_date	timeframes	strategy	total_profit	trades
  1	   XYZ	    01/08/2024	  Daily	moving_average_crossover	500.00	10




# Error Handling
  If data is missing or incorrectly formatted, appropriate error messages will be displayed.
  If a strategy is unknown or unsupported, a "400 - Bad Request" error is returned.
  Contribution
  This project is designed to be extendable. You can add additional strategies or modify existing ones to suit more trading models.

# Fork the repository.
  Add your strategy or modification.
  Submit a pull request with a detailed description.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published