Skip to content

A web application that calculates the highest momentum stock and utilizes a trading bot to send trades to the TD Ameritrade platform through tda-api API.

Notifications You must be signed in to change notification settings

johnhou13579/Flask-Web-Trading-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Web-Trading-Bot

What is this repository?

A web application that calculates the highest momentum stock and utilizes a trading bot to send trades to the TD Ameritrade platform through tda-api API. Bot originally referenced, tweaked, and backtested on Quantopian.

What technologies is used in this web app?

Backend: Python/Flask, Flask-SQLAlchemy
Frontend: Bulma, Jinja2
Database: SQLite `
API: TD Ameritrade API, tda-api

What strategy is used?

We assume that the user will run the strategy on companies that they would have held long term otherwise. This algorithm suggests which company has the highest momentum amongst those. Portfolio rebalance backtested to perform most optimzally bi-monthly. Risk lies in having entire portfolio within one stock and huge drawdown. However, since we would have held long term without rebalance, we would have expected similar drawdowns.

Backtest Example on Quantopian

Since our plan is to hold stocks we find value in long term, we decided to implement a momentum based strategy that would alternate between stocks that we would have held long term regardless. Since this backtest also shows tremendous spikes from certain comapnies, future results may not show as promising returns due to overfitting. Regardless, we find value in these companies and would have held them long term.

Start date2014-01-03
End date2020-09-11
Total months80
Backtest
Annual return 93.96%
Cumulative returns 8290.412%
Annual volatility 57.039%
Sharpe ratio 1.44
Calmar ratio 1.61
Stability 0.94
Max drawdown -58.344%
Omega ratio 1.34
Sortino ratio 2.31
Skew 1.49
Kurtosis 26.22
Tail ratio 1.27
Daily value at risk -6.86%
Gross leverage 0.94
Daily turnover 3.74%
Alpha 0.67
Beta 0.60
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 58.34 2020-02-19 2020-03-18 2020-06-08 79
1 46.41 2018-09-14 2018-10-29 2019-12-23 332
2 39.84 2015-12-29 2016-02-09 2016-04-22 84
3 32.36 2017-02-27 2017-05-08 2018-01-26 240
4 32.10 2020-08-31 2020-09-08 NaT NaN
Stress Events mean min max
Apr14 -0.01% -5.57% 5.81%
Oct14 0.29% -1.46% 2.56%
Fall2015 -0.08% -5.89% 6.89%
New Normal 0.33% -23.15% 50.11%
Top 10 long positions of all time max
AMD-351 96.52%
TSLA-39840 96.41%
AMZN-16841 95.73%
SPXL-37514 95.46%
AAPL-24 95.15%
Top 10 short positions of all time max
Top 10 positions of all time max
AMD-351 96.52%
TSLA-39840 96.41%
AMZN-16841 95.73%
SPXL-37514 95.46%
AAPL-24 95.15%

Performance Relative to Common Risk Factors

Summary Statistics
Annualized Specific Return 81.75%
Annualized Common Return 6.45%
Annualized Total Return 93.96%
Specific Sharpe Ratio 1.43
Exposures Summary Average Risk Factor Exposure Annualized Return Cumulative Return
basic_materials 0.00 0.00% 0.00%
consumer_cyclical 0.54 3.68% 27.35%
financial_services 0.00 0.00% 0.00%
real_estate 0.00 0.00% 0.00%
consumer_defensive 0.00 0.00% 0.00%
health_care 0.00 0.00% 0.00%
utilities 0.00 0.00% 0.00%
communication_services 0.00 0.00% 0.00%
energy 0.00 0.00% 0.00%
industrials 0.00 0.00% 0.00%
technology 0.65 11.39% 105.71%
momentum 1.99 -1.86% -11.79%
size 1.92 -2.39% -14.96%
value -0.89 0.23% 1.55%
short_term_reversal -0.41 0.16% 1.10%
volatility 1.09 -3.88% -23.24%

png

png

png

png

png

About

A web application that calculates the highest momentum stock and utilizes a trading bot to send trades to the TD Ameritrade platform through tda-api API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published