Strategies

Configuring your strategy

The strategies directory is where the user should place their own strategy file, written in Python. Here are the steps to create and use your own strategy:

  1. Create your strategy file:

    • Open the root directory of ETradeBot in your favorite Python IDE.

    • In the strategies directory, create a new Python file for your strategy.

    • The name of the file will be the name of your strategy. For example, if you name your file my_strategy.py, then your strategy will be called my_strategy. The name of your strategy file must be unique from any other strategy files in the strategies directory.

    • Write your strategy in the form of a function which returns a pd.Series where the index is the ticker symbols and the values are the percent decimal portfolio weightings of each ticker. Your strategy’s logic should be written in the function body and return a pd.Series with the ticker symbols and percent decimal portfolio weightings.

    • Your strategy must return a pd.Series like below:

    def my_strategy():
        # Your trading strategy logic goes here.
        return pd.Series({
            'AAPL': 0.5,
            'GOOG': 0.3,
            'AMZN': 0.2
        })
    
    • An example strategy is provided here purely for demonstration purposes only. The example strategy included in the strategies directory is not intended to be used as a trading strategy.

  2. Set the strategy name in run_main.bat when configuring the batch file on the next page:

    • In the run_main.bat file, set the STRATEGY_NAME variable to the name of your strategy file (without the .py extension).

    • Example code:

    STRATEGY_NAME = 'my_strategy'
    
    • By default, strategy_name in main.py is set to example_strategy which is only intended as a demonstration.

That’s it! You should now have your strategy ready to use with ETradeBot.