final-project-justinfranken

final-project-justinfranken created by GitHub Classroom

https://github.com/iame-uni-bonn/final-project-justinfranken

Science Score: 18.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

final-project-justinfranken created by GitHub Classroom

Basic Info
  • Host: GitHub
  • Owner: iame-uni-bonn
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 178 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 2 years ago · Last pushed over 2 years ago
Metadata Files
Readme Changelog License Citation

README.md

TradingStratTester

image

Table of Content:

Introduction

This project assesses trading strategies across different asset classes and frequencies, offering users ample flexibility to experiment with various combinations of financial assets, frequencies, and strategies. Users can adjust global variables in 'src/tradingstrattester/config.py' to explore different assets, strategies, and simulation parameters such as timing for buying, selling, or holding, as well as initial depot value, starting assets, and transaction costs.

Instructions on modifying the 'config.py' file:

In the 'config.py' file, users can adjust the results of the trading strategy comparisons. You can locate the 'config.py' file in the following directory:

src / tradingstrattester / config.py

Subsequently, instructions on modifying the lists and variables will be provided.

Downloading financial data configurations

We download finanical data directly from Yahoo Finance using the python library yfinance.

FREQUENCIES + STARTDATE and ENDDATE:

The python library yfinance is providing the following possible frequencies:

| Frequency | Maximum possible history from today | Variable Name | :---: | :---: | :---: | | 1 Minute | 7 days | "1m" | | 2 Minute | 59 days | "2m" | | 5 Minute | 59 days | "5m" | | 15 Minute | 59 days | "15m" | | 30 Minute | 59 days | "30m" | | 60 Minute | 729 days | "60m" | | 1 Day | Infinity | "1d" | | 5 Days | Infinity | "5d" | | 1 Week | Infinity | "1wk" | | 1 Months | Infinity | "1mo" | | 3 Months | Infinity | "3mo" |

To change FREQUENCIES, STARTDATE or ENDDATE change the corresponding objects. Initial FREQUENCIES, STARTDATE and ENDDATE (in the format 'YYYY-MM-DD') configurations are the following

python FREQUENCIES = ["60m", "1d", "1wk"] START_DATE = "2018-01-01" END_DATE = "2024-03-01"

ASSETS:

Please input valid symbols corresponding to each asset, as listed on Yahoo Finance. To modify ASSETS, adjust the corresponding object. The initial configuration for ASSETS is as follows

python ASSETS = ["DB", "KO", "^GSPC", "EURUSD=X", "CL=F"]

Simulating depot configurations

Modifying the following objects will result in changes to the simulation's outcomes.

STRATEGIES:

Following trading strategies are implemented:

  1. Crossover Strategy ('crossovergen'): The crossover strategy identifies market shifts by generating bearish signals when the current open surpasses its close and the previous open is lower than its close, and bullish signals when the current open is lower than its close and the previous open exceeds its close.
  2. Relative Strength Index (RSI) ('RSIgen'): The RSI is a momentum indicator and helps to identify overbought (above 70) or oversold (below 30) conditions in an asset, guiding potential buying or selling opportunities accordingly. The RSI has the following form: $$RSI = 100 - \left[ {100} \over 1 + {{\text{Avg. gain}} \over {\text{Avg. loss}}} \right].$$

  3. Bollinger Bands (BB) ('BBgen'): BB's are a volatility indicator comprising a moving average and two bands laying above and below it, based on standard deviations. They dynamically adjust to market conditions, expanding during periods of high volatility and contracting during low volatility. When prices intersect with the upper Bollinger Band, it signals a sell opportunity, while intersecting with the lower band suggests a buy opportunity.

  4. Moving Average Convergence Divergence (MACD) ('MACDgen'): The MACD line is generated by $MACD = \text{12-Period EMA} - \text{26-Period EMA}$ where EMA stands for exponential moving average. Bullish signals occurre when the MACD line crosses above the signal line, and bearish signals when it crosses below, where a threshold considering standard deviation of the MACD line is included.

  5. Random ('randomgen'): This strategy generates random buy (15%), sell (15%) or do nothing (70%) signals based on a random number generator.

Please input only valid strategy names in STRATEGIES, as listed above. To modify STRATEGIES, adjust the corresponding object. The initial configuration for STRATEGIES is as follows

python STRATEGIES = ["_random_gen", "_crossover_gen", "_RSI_gen", "_BB_gen", "_MACD_gen"]

UNITSTRAT and UNITVAR:

In this project, the following unit trading strategies are available to determine the quantity of units traded for a buy or sell signal:

  1. fixed trade units ('fixedtradeunits'): Trade a fixed amount of units determined in UNIT_VAR (e.g. 100),
  2. percentage to value trades ('percentagetovaluetrades'): Calculate the number of units to trade by applying a fixed percentage of the current portfolio value determined by UNITVAR (e.g., 0.05).
  3. volatility unit trades ('volatilityunittrades'): Calculate the number of units to trade by applying a fixed percentage of the current portfolio value determined by UNIT_VAR (e.g., 0.075), multiplied by the standard deviation of the past 50 trades.

Please input only valid strategy names for UNITSTRAT as listed above and floats or ints for UNITVAR. To modify UNITSTRAT or UNITVAR, adjust the corresponding object. The initial configuration for UNITSTRAT and UNITVAR is as follows

python UNIT_STRAT = "percentage_to_value_trades" UNIT_VAR = 0.05

Simulating depot variables (INITIALDEPOTCASH, STARTSTOCKPRCT, TAC):

The following objects directly impact the simulated depot used to assess the performance of strategies across various asset/frequency combinations:

  1. INITIALDEPOTCASH (int / float): This parameter sets the initial total value of the simulated portfolio.
  2. STARTSTOCKPRCT (int / float): This parameter determines the initial number of assets (rounded down to the nearest whole integer) to be placed in the portfolio.
  3. TAC (int / float): This parameter defines the transaction costs per trade. The calculation is as follows: $\text{tac per period} = \text{trade units} * tac$.

The initial configurations of these simulating depot variables are as follows:

python INITIAL_DEPOT_CASH = 10000 START_STOCK_PRCT = 0.25 TAC = 0.001

Get Started

Once you've cloned this repository, you can begin by creating and activating the environment. This can be done by navigating to the directory containing 'environment.yml' and executing the following command.

console $ conda/mamba env create -f environment.yml $ conda activate tst

In order to create the project type the following into your console, while being in the project directory:

console $ pytask

Project template

The project which will then be generated is structured as follows:

  • bld: The build directory contains our analysis results and plots.
    • analysis: The storage consists of pickle files containing the signaling and simulated portfolio outcomes for each individual strategy.
    • data: Storage for the downloaded financial data files.
    • plots: Directory comprising subdirectories corresponding to distinct output plots: assetsanddepotvalue, indicatorbars, and unitsandcash.
  • src: The source directory contains all of our python files for generating analysis results.
    • analysis: Python files containing essential functions, initiating the analysis results.
    • data_management: Python file containing essential functions to download data from Yahoo Finance.
    • final: Python files which generate outcomes for the 'pytask' command.
    • config.py: Configurations file to change outcomes of that project. See "Instructions on modifying the 'config.py'" file for more information.
  • test: The test directory contains files to test the functions used for our analysis.
    • analysis: Python files for testing the essential analysis functions.
    • data_management: Python file which tests the data_management functions.

[!CAUTION] To ensure the proper functionality of this project, it is necessary to have an internet connection. This allows the project template structure to download financial data directly from Yahoo Finance. Please note that no pre-downloaded financial data will be available on this GitHub page.

Credits

This project was created with cookiecutter and the econ-project-templates.

We furthmore used the open-source package yfinance to download financial data from Yahoo Finance.

Owner

  • Name: IAME, Universität Bonn
  • Login: iame-uni-bonn
  • Kind: organization
  • Location: Bonn, Germany

Institute for Applied Microeconomics

Citation (CITATION)

@Unpublished{tradingstrattester2024,
    Title  = {This project tests several different trading strategies on test depots using real data of different asset classes.},
    Author = {Justin Franken},
    Year   = {2024},
    Url    = {https://github.com/justinfranken/tradingstrattester}
}

GitHub Events

Total
Last Year

Dependencies

.github/workflows/main.yml actions
  • actions/checkout v3 composite
  • codecov/codecov-action v3 composite
  • mamba-org/provision-with-micromamba main composite
environment.yml pypi
  • kaleido ==0.1.0.post1
  • pdbp *
pyproject.toml pypi