Member-only story

Building a Simple Yet Profitable Automated Trading Algorithm

ZodiacTrader
3 min readJan 23, 2025

--

In today’s fast-paced financial markets, algorithmic trading has become increasingly accessible to individual investors. While complex trading systems power major hedge funds, you can create a surprisingly effective automated trading strategy with just basic Python knowledge. This guide will walk you through building a profitable trading bot that can operate 24/7 without emotional bias.

Python offers powerful tools to create automated trading systems. Let’s explore how to build one that’s both effective and maintainable.

import yfinance as yf
import pandas as pd
import numpy as np
from datetime import datetime, timedelta

class SMACrossoverTrader:
def __init__(self, symbol, cash=10000, short_window=20, long_window=50):
self.symbol = symbol
self.cash = cash
self.position = 0
self.short_window = short_window
self.long_window = long_window
self.trades = []

def fetch_data(self, start_date, end_date):
"""Fetch historical data from Yahoo Finance"""
stock = yf.Ticker(self.symbol)
df = stock.history(start=start_date, end=end_date)
return df

def calculate_signals(self, df):
"""Calculate trading signals based on SMA crossover"""
# Calculate short and long-term moving averages
df['SMA_short'] =…

--

--

ZodiacTrader
ZodiacTrader

No responses yet