Code Monkey home page Code Monkey logo

algo-trading's Introduction

Algotrading strategies for ETFs

About

  • several trading strategies based on indicators such as RSI and SMA
  • allows backtesting of the strategies using historical data
  • runs on Python 3.10 with backtrader framework

Installation

Running a simulation

Download data

Downloads historical prices of ETFs from the defined ETF universe

python downloader.py

Execute the simulation

This example strategy invests all capital in the ETF with the lowest RSI(2) score. The RSI is calculated at the market close, the trading is done at the market open.

python minRsi.py

Sample output

Information about annualized returns, yearly returns, sharpe ration, max drawdown, executed trades etc

2023-06-30, Positions: 1, cash 362572
2023-06-30,   Selected stock: SHY.csv (RSI 33)
2023-06-30,  selling 
2023-06-30,  buying size 4483.393466
2023-07-03,  SELL EXECUTED at price 178.61, cost 358073.83183599793, com 12.63016898182004
2023-07-03,  BUY EXECUTED at 80.82, cost 362347.8599006582, com 12.682175096523036
2023-07-03,   OPERATION PROFIT, GROSS 2788.1390731461133, NET2762.9763200500333
2023-07-03, Positions: 1, cash 365292
2023-07-03,   Selected stock: SHY.csv (RSI 16)
Final Portfolio Value: 368,736
Annualized return: 18.607256 percent
OrderedDict([('sharperatio',
              0.8688111333582026)])
OrderedDict([('maxdrawdown',
              22.0152934121263),
             ('maxdrawdownperiod', 247)])
OrderedDict([(2015, 0.05122567838026293),
             (2016, 0.06276456157714883),
             (2017, 0.22561824592017454),
             (2018,
              -0.015572732841336534),
             (2019, 0.19185511924085952),
             (2020, 0.6097033355248196),
             (2021, 0.2080663609335569),
             (2022,
              -0.03148034329036109),
             (2023, 0.2186399935846095)])

plot1

Support

Ideas? Suggestions? Feel free to contact me at [email protected]

algo-trading's People

Contributors

qbajas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

webclinic017

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.