/r/algotrading

Photograph via snooOG

A place for redditors to discuss quantitative trading, statistical methods, econometrics, programming, implementation, automated strategies, and bounce ideas off each other for constructive criticism. Feel free to submit papers/links of things you find interesting.

/r/AlgoTrading place for redditors to discuss quantitative trading, statistical methods, econometrics, programming, implementation, automated strategies and to bounce ideas off each other for constructive criticism. Feel free to submit papers/links of things you find interesting.

This sub is not for the promotion of your blog, youtube, channel, or firm.

*THIS DOES NOT CONSTITUTE INVESTMENT ADVICE, USE AT OWN RISK*

*SEARCH THE SUB/GOOGLE/STACK OVERFLOW BEFORE ASKING QUESTIONS FOUND ON THE FRONTPAGE OF THE ABOVE WILL BE REMOVED*

Good places to start with code examples:

STRATEGY
Big-Intro to quantstrat and trading systems
R & quanstrat video tutorial
portfolio optimization
Great blog with more advanced code and ideas from the "systematic investor" note: code here does not follow standard R conventions
Blog here with strategy examples from Ilya Kipnis
quantivity paper feed
How to learn algortihmic trading
Strategy books thread
Quantopian Lecture Series

How to get historical data for free
Daily Bar data for Stocks
Tick level Forex Data
Historical Bar Data for Crypto Currencies - Binance
Historical Bar Data for Crypto Currencies - BitMEX

Charts with live feeds for global exchanges
TradingView HTML5/web based charts

Math/Stats/Machine Learning
Introduction to Statistical Learning with applications in R
Elements of Statistical Learning

Production Systems
aleph-null: open source python ib
quick-fix
node.js to ib api
subreddit thread on systems

Paper Feeds
Quant news feed
Quantocracy blog feed

Live Chat Rooms

Official Discord: Official Discord for /r/AlgoTrading
Open Source Quantitative Finance: Open Source Quantitative Finance

R Language in Finance Discord IRC Version sync'd to discord irc.libera.chat #r-finance

Book Recommendations List of recommended books on Algo Trading

Big post of recommended books

Do's:

  • Submit Interesting papers, blog postings
  • Code/packages we love these!
  • strategies (even if they don't work a negative result is still useful)
  • Read the sidebar (intro to quantmod/quantstrat) will answer questions on how to download data, chart, build test and validate strategies.
  • Have a technical informative discussion
  • Submit business links and questions (e.g. contractual issues,licensing etc)
  • Submit tax optimization links and questions
  • Submit infrastructure links and questions
  • Submit compliance/regulatory links and questions

Don'ts:

  • Submit paysites for indicators/software/systems/whatever
  • Submit things without methodology or at least some guidance
  • Flame on other users, we're all here to learn so be constructive in your criticism
  • Downvote without posting why, Give your constructive criticism or don't critique at all
  • Post asking how to get started without viewing the links on the sidebar, or reviewing previous posts in the subreddit
  • Ask for career advice there is /r/financialcareers for that
  • Ask for educational advice, as each case is special and your thread has no value for practitioners, there are rankings of quant programs, computational finance, machine learning and stats out there
  • Submit software that is proprietary and not open source
  • Submit links/posts that are for the sole purpose of generating referrals/sales/$$, if it is not informative and useful then it does not belong here, shilling your products is not appreciated.
  • Submit posts that are summaries of other posts without additional content
  • Submit videos without accompanying assets (e.g. code)

FAQ's:

  • Q: "Hi guys im new how do I get started?"
  • A: Read the sidebar, if you have a precise specific question please google it and should you not find the answer then you can ask here.

  • Q: I am a student and want to know what courses to study to get into algo trading?

  • A: Algotrading is at the intersection of statistics/computer science/machine learning/mathematics/finance/economics.

  • Q: Where should I apply for a job?

  • A: /r/financialcareers for that

  • Q: I have bug ABC with language XYZ ?

  • A: http://quant.stackexchange.com/ or http://http://stackoverflow.com/

If you get spam filtered, message the mods and we will review and unblock as required.

/r/algotrading

1,771,322 Subscribers

1

Best API for the price for my timeframe when forward testing

The strategy that I’m currently backtesting makes evaluations immediately after the most recent 5m candle is completed and places new/updates existing orders accordingly. I used yfinance 5m candles for all of my backtesting which works fine.

I want to start reliably forward testing using the same timeframe - immediately reexecute the strategy after the most recent 5m candle has been completed and place new/update existing orders on Alpaca using a bracket or OCO order.

Yfinance has a delay of about 10-15 seconds before the latest 5m candles closing price is shown. Not sure how reliable this is considering it’s free.

I don’t need volume information, just HLC. Is yfinance my best bet for something free/inexpensive or is there something better for a low price?

1 Comment
2025/02/01
19:36 UTC

1

Backtesting Market Data and Event Driven backtesting

Question to all expert custom backtest builders here:

  • What market data source/API do you use to build your own backtester? Do you first query and save all the data in a database first, or do you use API calls to get the market data? If so which one?

  • What is an event driven backtesting framework? How is it different than a regular backtester? I have seen some people mention an event driven backtester and not sure what it means

2 Comments
2025/02/01
19:16 UTC

6

Free/cheap backtesting tools?

I don't know how to code, I use a backtesting tool but it's too limited, I would like a better tool.

I know TradingView, what else? It could be a cheap backtesting tool or free ones.

10 Comments
2025/02/01
18:08 UTC

19

Automate my stock and crypto strategy?

Hello again everyone. I posted the other day and have looked into some trading sites since then so I will try and be more detailed this time

I have a strategy that needs to place trades on different stocks and cryptos on different exchanges. I want to be able to automate this so that the trades get placed when my specific criteria are met and it must all happen quick or else I will not be profitable (because I need the best position entries and exits for my strategy). I have looked into these services like: Ninjatrader, Tradingview, Metrader, Multi charts, Alpaca markets but I am not so sure any would work for me……. Can I get advice?

I was suggested to build my own trading bot but I am not sure I can do this. My python skills are OK? My only other option is to hire someone to build it for me. What do you all think? Thank you everyone

27 Comments
2025/02/01
12:20 UTC

6

Using live power outage data as a signal

Anyone integrated live power outage data (USA / CA) as a signal in their energy arbitraging? If so, what data sources do you use? I've tried scraping data directly from utility websites, but there are over 1,000 companies and their websites change quite often (especially during major events), which breaks things. I'd prefer to have a service (paid is fine) that just handles those issues for me.

5 Comments
2025/02/01
09:59 UTC

6

Best historical data and market data?

There seems to be a lot of discussion about this here with no clear answers. So I wanted to clarify a few things.

  1. Can you get full historical minute data from Schwab for free? Does it have fundamentals too?
  2. If not, eodhd.com is the only provider with decent reviews on Trust pilot. Every other provider has pretty bad reviews.
  3. I'm thinking of getting historical data from one of the above, and then get real market data from IBKR/Schwab depending on which broker I decide to use. Has anyone else done this and what has their experience been like?

Thank you!

8 Comments
2025/02/01
09:18 UTC

9

I would buy yours.

I've been searching for like 5 years of exper advisor that really work. I know they exists but they are at a different place than i am looking now. Its difficult to find it and those who are in your face don't even work properly. I'd never understand why you would upload something that doesn't work for yourself, why would it work for others. The market is absolutely flooded with bs. Considering there 1.8 million people here some genius has been working and workinf and it works. And yes sharing a strategy could really kill yourself when people use it too much and thats exactly what will happen so they must keep it very limited and the clients must get it as well cause cooying and pasting is easy too.

If somebody out here really got something good, shiiiit wouldn't i like to know.

40 Comments
2025/02/01
08:01 UTC

16

I quit trying backtesting intraday

Nothing seems to work for intraday, daily and weekly timeframes are better.

1 min, 5 min, 15 min, 30, min... Nothing works, bad returns, bad drawdown.

Of course you can build an algorithm that beats the market for intraday, but it will be very hard.

My advice after weeks of backtesting: focus on longer timeframes.

28 Comments
2025/02/01
01:12 UTC

5

Backtesting Platforms/Tools?

Hey guys. I’m not a technical person, but I’m looking for resources for someone else.

Is there any platform that lets you backtest with python? Just stocks. Maybe derivatives later.

If you had to code a strategy that involves data source APIs, is there any platform where I could code the strategy in its entirety and backtest it too? I should be able to backtest multiple positions/tickers at once.

If not, do you separately code and generate signals and then use a separate backtesting platform

I know there’s python libraries for backtesting, and I probably sounds silly- but I’d love to get some direction on steps/tools/platforms you use.

Thanks guys!

7 Comments
2025/01/31
23:04 UTC

33

I know you guys don't read but what papers would you recommend

Title says it all, basically getting more into the research side of everything and wondering what's actually worth reading. The other day I spent maybe 2 hours reading this massive paper on pairs trading and I genuinely feel like I learned nothing useful except a few of the tricks the researchers used in their analysis

25 Comments
2025/01/31
22:58 UTC

12

Do you pay margin interest when trading with unsettled funds?

Let's say I have $100K cash in a margin account

09:30 I buy $100K worth of stock

10:00 I sell it for $110K

10:30 I buy $100K worth of stock

11:00 I sell it for $110K

11:30 I buy $100K worth of stock

12:00 I sell it for $110K

  1. Do I pay margin interest for trading with unsettled funds?

  2. If so, how much interest do I pay, do I pay for 30 minutes worth of interest at 10% APY or do I pay for 24 hours worth of interest (until it settles)?

9 Comments
2025/01/31
18:47 UTC

1

NT8 Code for Schwab API ?

Anyone aware of existing code to connect to Schwab API to pull options data into ninjatrader?

2 Comments
2025/01/31
13:17 UTC

7

What are good ways to account the volatility of the stock price?

I'm trying to come up with a screener and one of the things i've been trying to do for a while now is creating support/resistance levels that can help me identify price action. The support/resistance levels are automatically generated and have their own properties such as how many times it was tested/strength and etc. These support/resistance levels have its own parameters which will be tested to different settings as part of the backtest so we can do things like be more conservative and have less levels or push it to have more. The image below is a sample of this.

https://preview.redd.it/sdwdvttrrage1.png?width=1487&format=png&auto=webp&s=cca5503a13966b2c39e86bd054ae2c3733cfd885

I am currently backtesting the support/resistance levels but I realized that the results of the backtest are currently unreliable because the tolerance between buy and sell depends on the volatility of the stock's price as well. If the the stock is generally erratic then the backtest should be able to account this volatility to prevent false signals (as seen below where there are multiple buy and sell signals that are absurd).

I did put some tolerance to account for volatility, but it's not dynamic where it changes from stock to stock, it's just a constant like a +/- of [tolerance] * [support/resistance level]. I'm wondering what's the best measure of volatility out there that will minimize the errors of signal generation. I was thinking the best would be some kind of probability distribution that can capture the behavior properly. Not sure if something like a simple standard deviation can capture it properly so I need some leads on these.

The plots below are the plots from the backtest so each stock will have 1 plot using the same support/resistance level logic from above but applied to each stock.

https://preview.redd.it/jjgp434trage1.png?width=1080&format=png&auto=webp&s=56669109fce1a64fbe3c5a3da087906c94a5d9bd

https://preview.redd.it/dvvgp5ltrage1.png?width=1080&format=png&auto=webp&s=1b585c10bb9f9482eb5b1610c293e75a00141f01

https://preview.redd.it/dtz0ve2urage1.png?width=1080&format=png&auto=webp&s=0e837837944ec40491d8d64d6f716be00d7f0ed7

EDIT: The previous charts had a look ahead bias due so I remedied it by having a training data set and a test data set. Training dataset is historical data minus the most recent data which I was going to use as the test dataset. Levels based entirely on the training dataset. Although the measures for volatility is still needed. Still lots of polishing but the idea is there

https://preview.redd.it/oe38pse18dge1.png?width=1428&format=png&auto=webp&s=97553d134bd7df072d6bfd5b8f9dc046423984da

27 Comments
2025/01/31
09:21 UTC

0

Didn't like drawdown, sold. Looking for...

Hi all. I use Composer. I wasn't liking the drawdown in "V2.11 The Manhattan Project | 6mo 42,000% AR | 9.5% DD" in my IRA so I sold at a loss and redistributed my proceeds to the other symphonies in the acct. all of whom are doing a fair bit better and don't have the drawdown Man. Proj. seems to have. That said does anyone have a suggestion for a symphony or symphonies that have been around a few years and have a consistent history of small drawdowns and generally trend upward?

Am I asking for the Grail here? :)

Thanks in advance.

4 Comments
2025/01/30
19:31 UTC

12

Help Automating Bitcoin Futures Trading

Hello all. I'm here asking for help getting pointed in the right direction. I've identified some spot price cash-and-carry opportunities in the Bitcoin futures market and I'm looking for a way to automate it. I have experience in Python and know the basics of several languages but I'm willing to learn something new.

The two things I'd like suggestions on are 1. exchange and 2. automation method. I'm trying to keep my exchange in the U.S. to keep things strictly legal so I've been looking at CME Group and Coinbase mostly. As far as automation method, I'm really struggling to narrow things down. It seems everywhere I turn there's a different suggestion and an endless amount of platforms that seem shady.

If anyone has experience on this and wants to share their experience I would really appreciate it!

Edit: corrected terminology

22 Comments
2025/01/30
19:00 UTC

115

what api's are you guys using for stock data?

I'm looking for APIs that provide real-time stock data including volume and detailed metrics. I also need access to fundamental reports for companies (like earnings, balance sheets, etc.).Additionally, it would be great if the API offers the ability to categorize companies based on their industry. Yeah real time stock data doesnt comes without paying i'm ready to buy the paid api's too

62 Comments
2025/01/30
07:24 UTC

21

Need some advice

All I do in my free time is code. I really like it, in fact I really enjoyed it but it is waning now. I have spent 600 plus hours trying to develop 1 algorithm but I have not seen any good results yet. Let me tell you a little about what I have been doing. I have dabbled and coded various machine learning models, genetic algos, gradient boosting algos, deep reinforcement learning agents, implemented various types of crossovers for filters and signals, researched many research articles, augmented my learning and coding with AI, implemented robust and varying feature generation, risk management, backtesting and forward testing criteria. I can go on and on. I have even spent additional funds for Pro subscription of ChatGPT along with Gemini, enrolled in a bootcamp, have years of experience in crypto and stocks. Watched hundreds of hours of YouTube videos. I cant list it all.

If there is 1, 2 or 3 things you can suggest to me what are they? Thank you for your help.

44 Comments
2025/01/30
04:35 UTC

17

How to deal with choppy market conditions?

Hello reddit gods,

I'm new to algotrading and have made the typical EMA crossover with a trailing stop loss, and it appears to achieve a decent return as it can capture big waves of price movements.

Are there any reliable methods to reduce false signals for this strategy in terms of preventing entries during sideways choppy conditions?

ChatGPT has recommended a few things, but I wanted to get advice from some actual algotraders first! Suggestions have been ATR, Bollinger Bands, adx and slope of EMA etc. Any of these good?

Thank you.

34 Comments
2025/01/29
23:04 UTC

12

C/C++ API to trade U.S. stocks

I am looking for a C/C++ API where I can:

  1. fetch OHLC for any given period for any U.S. stock (NASDAQ, NYSE etc)
  2. get real time data (Open, Current High, Current Low, Close)

I would like to create a program in C/C++ which runs price analysis continuously and decides when to buy/sell a stock on a broker account that I fund based on that analysis.

Are there any reputable, low cost platforms for this in Europe or the U.S. ?

Either an API that is offered by the brokerage company or an API that can connect to an account at a brokerage company.

32 Comments
2025/01/29
20:58 UTC

18

Are there any situations where an algo is still worth deploying if it is beaten by the 'Buy and Hold ROI%'?

I'm fairly new to algotrading. Not the newest, but definitely still cutting my teeth.

I am running extensive backtests, and sometimes I get algos which have a good ROI %, but which are lower than the buy and hold ROI %.

It seems pretty intuitive to me that these algos are not worth running. If buy-and-hold beats them comfortably, why would I deploy the algo rather than buying and holding?

But it also strikes me that I might be looking at these metrics simplistically, and I would appreciate any feedback from more experienced algo traders.

Put short: Are there any situations in which you would run an algo which has a lower ROI % in backtests than the buy-and-hold ROI %?

Thanks!

32 Comments
2025/01/29
17:13 UTC

0

How to optimize your trading return

So lets say i have strategy to get 100% ROI every year, then i have problem not every year i have same amount of total trade. sometime in a year i got 100 trade signal sometimes in a year only got 1 trade signal. so even with average trade return 2x, with unknown date to trade my "actual" trade return become far less than 1.5x . i tried many ways to get better trade return, like only take 2 trade every month and many more,yet the actual income is still far less than it should. so how do you guys solve such problem??

21 Comments
2025/01/29
12:16 UTC

5

Deepseek news study

Hi,

As you probably know a chinese company released deepseek AI model which coused NVDA and other AI connected stock to drop massively.

I want to investigate this and reverse engineer this event to come up with a strategy to peofit from such occessions.

Sentimental approach is my first idea here, but I wonder if anyone has some tips here?

I would prefer to setup a trade based on some TA, but I am affraid that sentimental analysis is the right approach here

All other ideas are welcome

34 Comments
2025/01/28
17:52 UTC

6

Data feed company for (among others) newsfeeds with "entity recognition"? Starts with D

I was browsing through linkedin and in the section comments of one of the many deepseek related threads I saw the CEO of this company (which I thought it was interesting to get an API feed from) that said "Distilling reasoning layers is easier than distilling facts".

But I forgot to follow or screenshot smh.

The company has been around for a decade (as far as I remember from the founder's BIO) and starts with D, one word only.

They claim to have FactSet and Alphasense among their users.

Do you guys know what I am talking about ? Anyone can help me find it again

8 Comments
2025/01/28
13:49 UTC

5

Weekly Discussion Thread - January 28, 2025

This is a dedicated space for open conversation on all things algorithmic and systematic trading. Whether you’re a seasoned quant or just getting started, feel free to join in and contribute to the discussion. Here are a few ideas for what to share or ask about:

  • Market Trends: What’s moving in the markets today?
  • Trading Ideas and Strategies: Share insights or discuss approaches you’re exploring. What have you found success with? What mistakes have you made that others may be able to avoid?
  • Questions & Advice: Looking for feedback on a concept, library, or application?
  • Tools and Platforms: Discuss tools, data sources, platforms, or other resources you find useful (or not!).
  • Resources for Beginners: New to the community? Don’t hesitate to ask questions and learn from others.

Please remember to keep the conversation respectful and supportive. Our community is here to help each other grow, and thoughtful, constructive contributions are always welcome.

7 Comments
2025/01/28
11:01 UTC

16

Is it possible to do algo trading without holding your funds in exchanges?

I’ll coming from crypto industry where holding money in exchange is a foolish thing. I usually kept it off exchange in cold wallet however since I’m getting into alto trading, how can i minimize keeping funds on exchange as much as possible?

Mainly I plan to make bots using python.

38 Comments
2025/01/28
09:56 UTC

20

Price Distribution Predicting Models (not VI models)

I would like to build model predicting stock price distribution for 2 future dates +180d and +360d. Based on historical data. And use that distribution to price European Options with Monte Carlo simulation.

I want to use different approach than Implied Volatility models. I want to ignore current market expectation (ignore current option prices), and rely only on the past data.

Also, how the model fit would be different. IV models fit to match the IV surface with Empirical IV, I would like to use other goal - use backtesting and compare model to real realised probabilities - i.e. trade millions of stock options on past data and the balance should be as close to 0 as possible (in a way like Maximum Likelihood Fitting).

The Model Should:

- Use Stochastic Volatility, Volatility Clusters and Volatility Mean Reversion. (I plan to measure it as rolling averages. And model it with Hidden Markov Chain, say we have 5 regimes of volatility, from low to high, and it should also handle clustering and mean reversion).

- Not assume that price distribution is Normal. Although using the various approximations is ok. (I plan to use empirically fit Gaussian Mixture as approximation of Heavy Tailed Distribution).

- Account for missing data. Say we predict price for wonderful stable growing company with 10y history. Its empirical distribution (annual log returns) will be wonderfull, no downturns or huge drops. But it is wrong, we are missing the data here, it's only a part of the whole reality, a lucky part. (I plan to account for that by fitting some abstract distribution (possibly Gaussian Mixture) over all stocks, and then calibrate it to the specific stock. So, after tuning this all-stock-distribution, even for wonderful growing company, it will account for a chance for drops and downturns).

- Get the core concepts and the structure right, while sacrificing high precision. Having 20% error is ok, but having 200 or 2000% error is not. (as they say - better be approximately right, than precisely wrong). So, simplifications are ok - like using discretisation, say using rough 10-20 bar histogram, instead of a more precise continuous smooth curves to represent stock price distribution is ok. What's not ok - is to ignore some crucial aspects, like heavy tail or assuming volatility as a stationary etc. (I plan to use discrete models, Markov Chain, they should be able to model those things, while sacrificing a little bit precision on discretisation).

The Model should not:

- Model path dependence, it's optional, we don't care, as we consider European Options only.

- Beat the market. We don't need that. We want a model that close enough to reality, a safety net, that protect us from making huge mispricing and errors, stress testing, playground to try new ideas etc. And doing it independently, ignoring the current opinion of the market.

- No need for well shaped symbolic form or math proof or high performance. Numerical simulations, Monte Carlo are good enough, and being slow is ok, even if it's x1000 times slower than other models, it's ok.

I would like to find good practical book about Monte Carlo and Markov Chain that does something similar (I found many books about IV, and GARCH, but not on this approach). Also, if you find a mistake in my reasoning, would be interesting to know. Thanks.

11 Comments
2025/01/28
03:27 UTC

8

Sentiment data source for testing

Anyone know of a free source for sentiment data? I only need to go back roughly a year or 2 for testing and then if the data looks good il pay for it. But struggling to find a source with that free tier first.

3 Comments
2025/01/27
20:20 UTC

18

Algo trading memecoins

Has anyone been successful in algo trading memecoins?

I have monitored a couple of bots trading solana on pump fun and they seem extremely profitable. I just don't get their strategy. Mostly just buy and sell, crazy.

28 Comments
2025/01/27
20:00 UTC

5

Seeking Metrics for Measuring Investment Model Stability

I'm currently working on model risk management at a brokerage firm. One of our Key Risk Indicators (KRIs) for Model Risk involves assessing the stability of our investment models. As I'm relatively new to this field, I'm seeking advice on this topic.

Specifically, are there any established metrics or methods to measure the stability of investment models? Our models are like using algorithms to select the top 10 stocks based on stock signals and fundamental analysis to seek alpha. The idea is how do we know that it's deviating from back-testing and should be revisited?

Any insights or recommendations would be greatly appreciated!

5 Comments
2025/01/27
06:43 UTC

Back To Top