/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

R Language in Finance Discord: Discord for R Programming for Financial Applications

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,758,899 Subscribers

6

Account for fees and slippage - am I doing it wrong?

I'm new to algotrading and in the process of trying to find systems that are profitable. In doing so, I've come across many systems which are profitable without fees and slippage, but once those are included the results are not so promising.

My way to incorporating fees and slippage is to apply a penalty to each trade's return.

So for example lets say I have fees of 10 bps and slippage of 5bps, and for a particular trade my return was 2%, it becomes 2% * (1-0.10%) * (1-0.005%) = 1.997%. This seems quite minuscule to me but for some reason after I make this alteration to my backtests, they all go from positive to negative returning.

I look at a system u/Russ_CW recently posted which was a SMA crossover strategy. Yes, this system is very simple and there is probably no edge there, but I just wanted to use it as an example - the returns looked good before I applied fees and slippage.

https://preview.redd.it/e678spvh3ayd1.png?width=671&format=png&auto=webp&s=72240eaf0254bef4431cede5f8918fdf878cc953

Once I apply fees and slippage, it now looks like this.

https://preview.redd.it/why450vl3ayd1.png?width=673&format=png&auto=webp&s=f8affeaa254ff647e7c077d79bdde0cd776213f6

How does it have so much impact? Am I accounting for fees and slippage incorrectly? Are my numbers for fees and slippage (10bps & 5 bps respectively) too high? What other methods do people recommend to account for this or do they just ignore fees and slippage and try forward test on a paper account?

22 Comments
2024/11/01
11:55 UTC

18

What is your experience with locally run databases and algos?

Hi all - I have a rapidly growing database and running algo that I'm running on a 2019 Mac desktop. Been building my algo for almost a year and the database growth looks exponential for the next 1-2 years. I'm looking to upgrade all my tech in the next 6-8 months. My algo is all programmed and developed by me, no licensed bot or any 3rd party programs etc.

Current Specs: 3.7 GHz 6-Core Intel Core i5, Radeon Pro 580X 8 GB, 64 GB 2667 MHz DDR4

Currently, everything works fine, the algo is doing well. I'm pretty happy. But I'm seeing some minor things here and there which is telling me the day is coming in the next 6-8 months where I'm going to need to upgrade it all.

Current hold time per trade for the algo is 1-5 days. It's doing an increasing number of trades but frankly, it will be 2 years, if ever, before I start doing true high-frequency trading. And true HFT isn't the goal of my algo. I'm mainly concerned about database growth and performance.

I also currently have 3 displays, but I want a lot more.

I don't really want to go cloud, I like having everything here. Maybe it's dumb to keep housing everything locally, but I just like it. I've used extensive, high-performing cloud instances before. I know the difference.

My question - does anyone run a serious database and algo locally on a Mac Studio or Mac Pro? I'd probably wait until the M4 Mac Studio or Mac Pro come out in 2025.

What is all your experiences with large locally run databases and algos?

Also, if you have a big setup at your office, what do you do when you travel? Log in remotely if needed? Or just pause, or let it run etc.?

53 Comments
2024/11/01
02:09 UTC

40

*Almost* Real-Time Intraday Stock Tracker

Hey Squad! 

I've recently put together an intraday stock price tracker that collects candlestick data using Yahoo Finance API, with configurable collection intervals and market hours enforcement. While not perfectly real-time, this implementation will provide granular enough data to produce approximately the same candles as the main stream providers. This API is not meant for high-frequency collection, and is currently limited in its functionality and scope.

Contrary to many other Yahoo Finance interfaces which collect historical data, this project collects intraday price data and aggregates the data into a candle over a specified time interval. A candle is a simple data structure holding the open, high, low and closing price of a stock over a predefined interval.

CandleCollector is originally designed to work in the ESP32 ecosystem, as these devices provide a small form factor, low power, wifi-connected interface to run this repetitive and low compute task.

Your basic steps to get started are:

  1. Clone the GitHub repo: https://github.com/melo-gonzo/CandleCollector.git
  2. Set up config.h file with your time zone in TimeConfig
  3. Set up config.h with the appropriate settings for market hours in StockConfig
  4. Set desired candle collection and query interval in StockConfig
  5. Add your WiFi credentials to credentials.h
  6. Upload to your client of choice.

Candle data is currently only stored on device, and can be monitored through serial output. I plan to integrate an easy-to-use database soon that anyone can easily set up on their own. This will enable many more possibilities to tie this into your own algotrading frameworks.

Note that when it comes to c++, I am merely a hobbyist and doing this in my free time, so before you roast the code just keep that in mind :) Let me know if you start using this, or if there are any issues you encounter!

-ransom

14 Comments
2024/11/01
01:55 UTC

18

Most Stable Futures Broker

Hey everyone, there's a lot of talk around here in terms of which brokers have good commissions, margins, API, etc. One thing I've noticed that isn't discussed as much is how reliable/safe each brokerage is for algo traders and I was hoping to have a discussion on that. Particularly for those that are going to be making 100+ trades per day and reliability needs to be very high.

Key Features:

  1. Good Live Support

  2. Good API error handling, particularly redundancy if things go wrong (hard limits on the broker side for maximum number of orders, max position, etc...)

  3. Good API docs, and a relatively stable platform that doesn't throw you indecipherable errors on the regular. (I've heard this about IB, anyways)

Bonus: Easy to use API for historical data (not as important because there's many data sources out there, just easier to stick to one API)

Choices I'm aware of:

NinjaTrader: Fairly Good API and Support, however I'm experiencing a lot of issues with dropped connections and the software not recovering stale orders, which is very concerning.

Interactive Brokers: Seems to have a finicky API, according to this sub.

TT: Pain in the butt to get started, very expensive, but should be very stable.

QuantConnect: Good API but terrible docs, not sure how good they are with respect to live trading but the backtesting suite is nice.

I've reviewed the features of all of these on my own, but its hard to say without committing to the platform and experiencing it myself, which is quite time consuming. Just hoping to here what everyone's experiences are here. Thanks!

20 Comments
2024/10/30
20:51 UTC

9

WTA as a form of alternative analysis?

I've currently got a few algos set up for my long term relativey low risk portfolio (25-30% consistently since 2012) however my free time is ever more enamored with trying to come up with ways to make more.

I'm currently fascinated by alternative analysis data predicting and arbitration (darknet activity to XRP is a good one, so is MSTR to BTC, which I coincidentally saw someone else implementing) and while I've yet to find one with consistent profitable results, I was wondering if any of you guys have gone that route successfully? Don't need specifics, just motivation that I'm heading in the right direction.

I've also thought about small caps and mid caps that generate their income predominantly from web traffic, so using some form of web traffic analysis (WTA) could give indications on their next earnings report. Now I'm not saying if N company increased web user traffic by 2% let's buy out all the outstanding shares and pray for a better life, but for example if they experienced an extreme exponential growth such as 5000%, then a speculatory play might be an option.

Just my two cents! Cheers.

9 Comments
2024/10/30
16:32 UTC

32

Upgrade your strategies by fundamental data

Hi,

here is the idea: You have a profitable strategy / algo for any market like gold, oil, forex, ... This strategy is good as it is. Now you add fundamental data. You analyse COT reports, saisonal statistics, contract curve (for futures)
With that fundamental data, you config the direction of your strategy. If you have a long short strategy, and fundamental data says short, then you deactivate the long side and just let the algo do short trades. If you have a long only algo and fundamental data says short, then you deactivate the algo and wait for a change in fundamental data.

Second idea is for index markets: Maybe you have a intraday strategy for markets like fdax, Dow, Russel. You take the spy or s&p500 index as direction handler by something like a ema200, macd or anything else that gives you an trend idea in the s&p. Because the correlation between these markets and the s&p index is very high, you do the same you did with fundamental data: if s&p500 is long, you just do long trades on fdax, Dow, russel with your strategy and vice versa. First tests seem pretty promising.

My opinion is, that could give a significant boost for your algo profits and reduce the drawdowns. I will take statistics about this in a long term and analyse, if that gives a positive return.

22 Comments
2024/10/28
18:35 UTC

21

Searching parameters to filter out big movers from false signals

Hello, i am building an algo that discovers big moves before they happen, planning to buy after the signals and sell a few hours later, 2 days at max. The thing is: it finds what it has to find, but there are also lots of false signals, like maybe 30 signals in a day, and 4 are big moves up, 2 down and the others move a little bit but nothing serious. I'm trying to find parameters to filter those out, not because they make me lose that much, but because entering 30 positions a day isn't really what i want.
So yeah just brainstorming some ideas if you want to help me, thanks!

45 Comments
2024/10/28
13:35 UTC

99

Best backtested Bitcoin Strategy i found

Hello Traders,

this simple Momentum Strategy works great on Momentum Assets like Bitcoin. Outperforms Bitcoin Buy and Hold.

  • Timeframe Daily(Coinbase)
  • Buy : RSI(5) > 70
  • Close : RSI(5) < 70

https://preview.redd.it/zqcdw1zgucxd1.png?width=2221&format=png&auto=webp&s=e9ea27bf9245f00ed8f744fd21b01e2b28f19b48

107 Comments
2024/10/27
20:05 UTC

27

ML evaluation process

Intraday Trading, Triple Barrier Method.

Entire data is split into 5 train/test folds, let's call it Split A.

Each of the 5 train folds is further split into 5 Train/Validation folds using StratifiedGroupKFold,

where I group by dates. I take care of data leakage between train/test/val by purging the data.

In total there are 25 folds, I select the best model by using the mean accross all folds.

Retrain/test using the best found params on the Split A data.

The union of Split A test results will give predictions over the entire dataset.

I reuse the predictions to hypertune/train/test a meta model using a similar procedure.

After the second stage models the ML metrics are very good, but I fail to get similar results on forward tests.

Is there something totally wrong with the evaluation process or should I look for issues on other

parts of the system.

Thank you.

Edit:

Advances in Financial Machine Learning

López de Prado

Methods for evaluation:

  1. Walk Forward
  2. Cross Validation
  3. Combinatorial Purged Cross Validation

I have used a Cross Validation (Nested) because for CPCV there were too many tests to be made.

Many of you suggest to use only WF.

Here is what Lopez de Prado says about it:

"WF suffers from three major disadvantages: First, a single scenario is tested (the

historical path), which can be easily overfit (Bailey et al. [2014]). Second, WF is

not necessarily representative of future performance, as results can be biased by

the particular sequence of datapoints. Proponents of the WF method typically

argue that predicting the past would lead to overly optimistic performance

estimates. And yet, very often fitting an outperforming model on the reversed

sequence of observations will lead to an underperforming WF backtest"

Edit2.

I wanted to have a test result over a long period of time to catch different

market dynamics. This is why I use a nested cross validation.

To make the splits more visible is something like this:

Outer A, B, C, D, E

1.Train A, B, C, D Test E

2.Train A, B, C, E Test D

3.Train A, B, E, D Test C

4.Train A, C, D, E Test B

5.Train B, C, D, E Test A

Further on each split the Train, for example at 1. A, B, C, D is further split into 5 folds.

I select the best parameters using the inner folds 5x5 and retrain 1, 2, 3, 4, 5. The model is

selected by averaging the performance of the validation folds.

After train, I have a Test Result over the entire Dataset A, B, C, D, E.

This result is very good.

As a final step I've used an F data that is the most recent, and here the performance is not

as good as in the A, B, C, D, E results.

31 Comments
2024/10/27
12:35 UTC

149

Backtest results for a simple “Multiple Lower Highs” Strategy

I’ve been testing out various ideas for identifying reversals and this particular one produced interesting results, so I wanted to share it and get some feedback / suggestions to improve it.

Concept:

Strategy concept is quite simple: If the price is making continuous lower highs, then eventually it will want to revert to the mean. The more lower highs in a row, the more likely it is that there will be a reversal and the more powerful that reversal. This is an example of what I mean. Multiple lower highs building up, until eventually it breaks in the opposite direction:

https://preview.redd.it/9r88fdv9l4xd1.png?width=431&format=png&auto=webp&s=2266a2598f640e077d563f172bbd6223ad8c09fa

Analysis:

To verify this theory, I ran a backtest in Python on S&P500 data on the daily chart going back about 30 years. I counted the number of lower highs in a row and then recorded whether the next day was a winner or loser, as well as the size of the move.

These are the results. The x-axis is the number of lower highs in a row (I stopped at 6 because after that the number of trades was too low). The y axis is the next day’s winrate. It shows that the more lower highs you get in a row, the more likely it is that the day after will be a green candle.

https://preview.redd.it/86nsk2oml4xd1.png?width=1003&format=png&auto=webp&s=9028429881b5d1f1c20757d48501d134e7ae8df1

This second chart shows the size of the winners vs the number of consecutive lower highs. Interestingly, both the winners and losers get bigger. But there’s a consistent gap between the average winner and average loser.

https://preview.redd.it/h6hfk11ol4xd1.png?width=1009&format=png&auto=webp&s=aa0c8fc2a5484306c27919941ce4b3c59961dc95

This initial test backed up my theory that a string of consecutive lower highs, builds “pressure” and the result is an increased probability of a reversal. This probability increases with the number of lower highs. Problem is that the longer sequences are less frequent:

https://preview.redd.it/ev88kjtol4xd1.png?width=448&format=png&auto=webp&s=dd7c8b7d68b5cd0948e15d0668e36f5ae2523b03

So based on this I picked a middle ground and used 4 lower highs in a row for my strategy

Strategy Rules

I then tested this out properly with some entry / exit rules and a starting balance of 10,000 for reference.

I tested a few entries and exits so I won’t go into them all, but the ones that performed best were:

Entry: After I get at least 4 lower highs in a row, I place an order at the most recent high. There are then 3 outcomes:

  • If the high is broken, then the trade is entered
  • If the price gaps up above the high, then the trade is manually entered at the open
  • If the price doesn’t hit the high all day and instead creates a new lower high, then the entry is moved to the new high and the process repeats tomorrow.

Exit: At the close of the day. The system didn’t hold overnight or let winners run. Just exit on the close of the same day that the trade is opened.

Using the same example from above, the entry would be at the high of the last red candle and the exit would be at the close of the green candle.

https://preview.redd.it/822tvwaql4xd1.png?width=545&format=png&auto=webp&s=644dfada558297a2251e47531fc272919013b7b8

Results:

I tested it long and short and it worked on both. Long was much better but that’s to be expected for indices that generally go up over time.

These are the results from a few indices:

https://preview.redd.it/noo49iitl4xd1.png?width=2080&format=png&auto=webp&s=8416a08c309d5aa91c60383ca29ad6a888dc4cc7

https://preview.redd.it/srsza9wtl4xd1.png?width=2078&format=png&auto=webp&s=6e91be49c93412ddd586b822dda135774677e7fa

https://preview.redd.it/1fco4djul4xd1.png?width=2083&format=png&auto=webp&s=918eb33e492371538072cf99e422a500d0ab3ce8

Pretty good and consistent returns. I also tested dow jones, nasdaq and russel index all with similar results - some better some worse.

Trade Volume

The trade signals aren’t generated often enough to give a good return though, so I set up a scanner that looked at a bunch of indices and checked them for signals every day. I split the capital evenly between them depending on how many signals were generated per day. i.e. Only 1 signal means 100% capital on that trade. 2 signals means 50% capital on each trade.

The result was that the number of trades increased a lot and the amount of profit went up with it, giving me this equity chart trading multiple indices with combined long and short trades:

https://preview.redd.it/86ok3qovl4xd1.png?width=2086&format=png&auto=webp&s=ae652a94743fb2c69cab5742fe0a47693469dc60

These are a few metrics that I pulled from it. Decent annual return with a fairly small drawdown and a good, steady equity curve

https://preview.redd.it/kand5o5wl4xd1.png?width=433&format=png&auto=webp&s=6dbb07fbfad56fcd5bcebcfa76060aca4741b9e1

Caveats:

There are some things I didn’t consider with my backtest:

  1. The test was done on the index data, which can’t be traded directly. There are many ways to trade them (ETF, Futures, CFD, etc.) each with their own pros/cons, therefore I did the test on the underlying indices.
  2. Trading fees - these will vary depending on how the trader chooses to trade (as mentioned in point 1). So i didn’t model these and it’s up to each trader to account for their own expected fees.
  3. Tax implications - These vary from country to country. Not considered in the backtest.

Final Thoughts:

I’m impressed with the results, but would need to test it on live data to really see if it performs well. The exact price entries in the backtest won’t always be possible in live trading, which will eat into the results significantly. Regardless, I’d like to continue working with this one and see where it goes.

What do you guys think?

Code

The code for this backtest can be found on my github: https://github.com/russs123/lower_highs

Video:

I go into a lot more detail and explain the strategy, as well as some of the other entry and exit variants in the short 7 minute video here: https://youtu.be/RX-yyFHVwdk

116 Comments
2024/10/26
16:19 UTC

15

Using automated signals for discretionary trading

I know this is an algo trading sub, however, I was wondering if folks here do discretionary trading.

Something where they have a script, alert that gives them entry signals and they manually execute it via their broker. The reasoning behind the manual execution is the need for a human to verify the signal first.

Also, for folks who do this, what time horizon are they trading?

34 Comments
2024/10/26
13:30 UTC

20

Experience using IBKR

Does anyone have experience with IBKR as a broker ? I'm considering them for thier us stock options offering and API's, if yes are they any good specifically;

  • Cost wise on trading, market data, Api use
  • how good is their API documentation
30 Comments
2024/10/26
10:21 UTC

33

Range Breakout Strategy

Hi,

Ive created a range breakout strategy on the micro russel future. The backtest is from 2019 Till now.

https://preview.redd.it/u3rvw7bbq2xd1.png?width=1830&format=png&auto=webp&s=0b718ea0933c4c173ad5fb6051602b18fd4112b3

Ive already included order fee of 4$ per trade.

it depends on 60 minute candles.

SL under range. TP 1.5 CRV.

It has a trend filter, orders will only be executed as reversals against the current trend.

I also tested both sides, with and against the trend and with the trend performs pretty poor.

Russel also is a market with less volatility and not so strong trends, so I think its explainable.

Ive got a time filter, trades only will be executed 1.5 hours before US cash session until 4.5 hours after US cash session. So 6 hours.

the time filter after close of cash session is really important.

I can also add london session until us cash session, but that also adds bigger drawdown.

https://preview.redd.it/q97h878gt2xd1.png?width=2394&format=png&auto=webp&s=1a3720a5f7237bc4d323dfebf7cdfe1b1f77d944

trades: 300

Winners: 49.67%

profit tactor: 1.46

wins: 16570

losses: 11369
biggest win: 387

avg win: 111

biggest loss: 273

avg loss: 75

max drawdown: 580

I will forward test that for a few month and report.

Edit: Some details for the range breakout system: Build a range by 10 candles. For 1hr candles that means 10 hour range. If price breaks out of that range, long on upper breakout or short on lower breakout. SL on the end of the range. TP is Range height * 1.5 Here are the filters: Only do an order between 08:00 AM and 14:00 ETC So the breakout needs to be in that time interval, otherwise no trade. Find out the upper trend: You can do that bs MACD Filter or EMA 100, 200 or something like that. Now you have to decide: trade with the trend or against it? On Russell, against the trend works fine with these parameters. So just open a long trade if upper trend is short and vice versa. So the parameters for this strategy are: Candle timeframe (1 HOUR) CRV (1.5) Trades with or against the trend? Or both (against) Time filter (08:00-14:00)

I think this system can work on many markets. Every time you have consolidations and after that breakouts. That should work very good on indices like S&p500, Dow, or raw materials like gold, ...

Edit 2024-11-01:

Ive done some backtests on market Micro Dow Future.

There the strategy is also working. Looks pretty good.

you need to slightly change the parameters:

time filter for trades: 07:00-16:00 ETC gives a better outcome.

ONLY LONG!!! Short Trades kill the peformance completely.

risk to reward: 2.0

here is the backtest:

https://preview.redd.it/f8dtaf7mwayd1.png?width=1567&format=png&auto=webp&s=c68c610f6b4e4d8937ee7fa2d56afd754ba94010

51 Comments
2024/10/26
10:00 UTC

15

Which API for earnings data/surprises? accurate data

Hello there,

I'm trying to make a very simple table where I have eps and revenue estimates as well as actuals per quarter.

So far I've tried Polygon.io but they don't have the eps and revenue estimates and their financials API is in 'experiment' mode for 1 year + I believe (not sure what it means but doesn't scream confidence)

And so I tried financialmodelingprep but their data is inaccurate i.e. revenue for ticker AA is negative (which tbh I find quite shocking cause it basically means that they don't run any sanity checks), and eps for AAL is incorrect for latest quarter. tl;dr the data is unusable from fmp for this

Can anyone share their experience with some other API providers?

Help and advise much appreciated!

EDIT: EODHD has same issue with revenue negative. I thought that paying 3x more will mean higher data quality but I was wrong.

10 Comments
2024/10/26
08:00 UTC

15

Source for Historical Market Events?

I'm looking for a source for historical market events.

Something like ForexFactory.com/calendar - if it had an API, would be perfect.

But, they don't have an API, and it's quite unreliable trying to use Selenium to scrape it (randomly missing events, slow, needs to be scraped almost daily because events are changing, inconsistent formats making handling with code quite painful and error prone...)

Does anyone know of something similar with an API and with the same event quality as ForexFactory?

At a minimum, I'm interested in high and medium impact intraday events affecting USD, although having all event impacts and currencies would be ideal.

5 Comments
2024/10/26
01:00 UTC

24

Historical Data

Where do you guys generally grab this information? I am trying to get my data directly from the "horses mouth" so to speak. Meaning. SEC API/FTP servers, same with nasdaq and nyse

I have filings going back to 2007 and wanted to start grabbing historical price info based off of certain parameters in the previously stated scraps.

It works fine. Minus a few small(kinda significant) hangups.

I am using Alpaca for my historical information. Primarily because my plan was to use them as my brokerage. So I figured. Why not start getting used to their API now... makes sense, right?

Well... using their IEX feed. I can only get data back to 2008 and their API limits(throttling) seems to be a bit strict.. like. When compared to pulling directly from nasdaq. I can get my data 100x faster if I avoid using Alpaca. Which begs the question. Why even use Alpaca when discount brokerages like webull and robinhood have less restrictive APIs.

I am aware of their paid subscriptions but that is pretty much a moot point. My intent is to hopefully. One day. Be able to sell subscriptions to a website that implements my code and allows users to compare and correlate/contrast virtually any aspect that could effect the price of an equity.

Examples: Events(feds, like CPI or earnings) Social sentiment Media sentiment Inside/political buys and sells Large firm buys and sells Splits Dividends Whatever... there's alot more but you get it..

I don't want to pull from an API that I am not permitted to share info. And I do not want to use APIs that require subscriptions because I don't wanna tell people something along the lines of. "Pay me 5 bucks a month. But also. To get it to work. You must ALSO now pat Alpaca 100 a month..... it just doesn't accomplish what I am working VERY hard to accomplish.

I am quite deep into this project. If I include all the code for logging and error management. I am well beyond 15k lines of code (ik THATS NOTHING YOU MERE MORTAL) Fuck off.. lol. This is a passion project. All the logic is my own. And it absolutely had been an undertaking foe my personal skill level. I have learned ALOT. I'm not really bitching.... kinda am... bur that's not the point. My question is..

Is there any legitimate API to pull historical price info. That can go back further than 2020 at a 4 hour time frame. I do not want to use yahoo finance. I started with them. Then they changed their api to require a payment plan about 4 days into my project. Lol... even if they reverted. I'd rather just not go that route now.

Any input would be immeasurably appreciated!! Ty!!

✌️ n 🫶 algo bros(brodettes)

Closing Edit: post has started to die down and will dissappear into the abyss of reddit archives soon.

Before that happens. I just wanted to kindly tha k everyone that partook in this conversation. Your insights. Regardless if I agree or not. Are not just waved away. I appreciate and respect all of you and you have very much helped me understand some of the complexities I will face as I continue forward with this project.

For that. I am indebted and thankful!! I wish you all the best in what you seek ✌️🫶

54 Comments
2024/10/25
21:53 UTC

220

Please put down your knives

Yes, I too am tired of all the fake gurus, all the scammers, all the course/indicator/strategy sellers, and all the wannabes that claim infeasible performance strats.

Yes, every time I read that someone made 10% in 1 month, I too think that they just got lucky and there's no way it's sustainable.

It's right to be skeptical of everything - I get it.


But please put down your knives.

Every time a real algotrader on this sub discovers a little edge, feel happy and proud, and try to share their little joy in this sub, they get attacked to oblivion.

All they're trying to do is share their happiness, bounce off ideas, get a healthy discussion and perhaps learn something new.

Instead, all they end up doing is defending themselves while trying to explain that they're not claiming to have found the holy grail.

Chill out guys - let's at least try to make this a calm and rational place where people can have healthy discussions. Please put down your knives.

Thanks :)

68 Comments
2024/10/23
21:15 UTC

105

"You should never test in production"

"You should never test in production" doesn't hold true in algo trading. This is my antithetical conclusion about software development in algo trading.

Approximately 2 years ago, I started building a fully automated trading system from scratch. I had recently started a role as a trading manager at a HFT prop firm. So, I was eager to make my own system (though not HFT) to exercise my knowledge and skills. One thing that mildly shocked me at the HFT firm was discovering how haphazardly the firm developed.. Sure, we had a couple of great back-testing engines, but it seemed to me that we'd make something, test it, and launch it... Sometimes this would all happen in a day. I thought it was sometimes just a bit too fast... I was often keen to run more statistical tests and so on to really make sure we were on the money before launching live. The business has been going since almost the very beginning of HFT, so they must be doing something right.

After a year into development on the side, I was finally forward testing. Unfortunately, I realised that my system didn't handle the volumes of data well, and my starting strategy was getting demolished by trading fees. Basic stuff, but I wasted so much time coming to these simple discoveries. I spent ages building a back-testing system, optimiser, etc, but all for nothing, it seemed.

So, I spent a while just trying to improve the system and strategy, but I didn't get anywhere very effectively. I learnt heaps from a technical point of view, but no money printing machine. I was a bit demoralised, honestly.

So I took a break for 6 months to focus on other stuff. Then a mate told me about another market where he was seeing arb opportunities. I was interested. So, I started coding away... This time, I thought to just go live and develop with a live system and small money. I had already a couple of strategy ideas that I manually tested that were making money. This time, I had profitable strategies, and it was just a matter of building it and automating.

Today, I'm up 76% for the month with double digit Sharpe and 1k+ trades. I won't share my strategies, but it is inspired on HFT strategies. Honestly, I think I've been able to develop so much faster launching a live system with real money. They say not to test in production,... That does not hold true in algo trading. Go live, test, lose some money, and make strides to a better system.

Edit:

I realise the performance stats are click bait-y 🤣. Note that the strategy and market capacity is so super low that I can only work a few grand before I am working capital with no returns on it. Basically, in absolute terms, I likely could make more cash selling sausages on the road each weekend than this system. It is a fun wee project for sole pocket money though 😉.

I.e., Small capital, low capacity, great stats, but super small money. Not a get rich quick scheme.

112 Comments
2024/10/23
08:53 UTC

42

Revenue Breakdown by Product & Geography based on Quarterly SEC Filings -> Code is Open Source

Hey everyone,

This weekend, I built a Python program that parses SEC filings to extract the quarterly revenue breakdown by product and geography over the years. The code is completely open-source, so feel free to use it and filter the dataset however you'd like.

I utilized the edgartools library, which made parsing the SEC files much easier—highly recommend it if you're working with similar data!

Exampe 1: https://imgur.com/a/yIhxIwi

Example 2: https://imgur.com/a/WFrZGX7

I'd love to hear your feedback and suggestions on how I can improve the project. Thanks!

Repo: https://github.com/stocknear/backend/blob/main/app/cron_business_metrics.py

Live demo: https://stocknear.com/stocks/AAPL/metrics

11 Comments
2024/10/21
11:18 UTC

132

I made a tool that hopefully some of you will find helpful

It's totally free, and isn't really algotrading specific per se, but it is markets adjacent so im assuming at least some people on the sub might care to give it a look: https://www.assetsrank.com/

It's effectively just an asset returns ranking website where you can set your own time ranges. If you use this type of thing as a signal for what to trade (seasonal based, etc...) you might find this helpful!

EDIT: this site is much better on desktop than it is on mobile btw! datatables on mobile are sort of a lost cause imo

49 Comments
2024/10/19
01:04 UTC

13

better fees? - crypto

So, myself and a small team, have created a trading system that does hft running a wide gamut of strategies. The system does about 1.5MM trades a day, and is slightly losing money (loses 0.005bps or 5/100,000% ). Binance have basically said they want us to buy more BNB and stake it for better fees, and we are right now paying 0.8bps/2.7bps make/take fees. Others have been more lenient such as OKx/bybit

We don’t need or want more capital but would a large hft be willing to partner with us and what should our ask be?Given we don’t want to increase the size of book as it is capacity constrained, should our ask just be the delta between fees? Ie provide some kickback for the firm allowing us to trade? (Guessing top tier hft firms have not much counterparty risk so happy to send capital to their accounts to trade). Second thing worried about is them profiling our trades and slightly reverse engineering but I guess chances are small(?)

13 Comments
2024/10/18
23:23 UTC

0

SL and TP with Interactive Brokers API

Hello, i have a problem with SL and TP with the IB api: i'm making an algo in python that, when i receive an alert, buys at market and places a stop at -5% and a tp at +5%, but when it gets an alert it only places the market order and the stop loss, then when it gets another alert, it places the tp of the alert before, the new market order and its stop. I'm really confuse, can someone please help?
I figured it out but i don't really know how: now it sends the market order, tp and sl together, but then it can't receive any other signal since it's waiting for the sl and tp orders to be executed before checking for new signals. Do you have some ideas on how to do that? Thank you

17 Comments
2024/10/18
21:01 UTC

27

Correlation between Sharpe and Returns

For context: I have a (modestly) profitable algo running using statistical techniques that performs well in strongly trending markets but not so much in sideways/choppy markets. I'm doing some exploratory prototyping using Monte Carlo simulations to try to identify interesting ways to profit reliably from chop.

What I'm noticing is that my prototype seems to exhibit an inverse correlation between Sharpe ratio and total returns. For example, if I simulate a $1000 portfolio beginning on 1 Jan 2018 and running until today with randomized parameters:

  • some of the Monte Carlo trials will show an ending balance of less than $2000 (i.e. it doesn't double its portfolio in 6 years) on a Sharpe of like 30000+, which is absurd.
  • other trials will show annualized return of 85% on a Sharpe of less than 1, making very few trades, which seems like obvious overfitting

The problem is that if I simply search the solution space for the highest Sharpe, or the highest total return, I'm getting bogus results that are unlikely to be achievable in the real world, but other strategies I have prototyped didn't exhibit this correlation between Sharpe and returns.

I am confident that these extreme results are not due to lookahead bias (because I have combed through the algorithm several times looking for this) nor due to slippage (because I account for slippage and the products I'm trading are highly liquid).

What insights, if any, should I be drawing from this apparent inverse correlation between Sharpe and returns?

28 Comments
2024/10/18
20:39 UTC

6

Ideas to build broker transaction portfolios

I am currently looking into L2 data and want to see the trade crossed by the brokers

My ideas is if the trade is cross by a non MM broker then it is on behalf of clients, if the broker is the big banks then the clients will be institutions, representing the market momentum / smart money.

Anyone have done sth similar / have ideas how to practically do it?

I think at first we need to get L2 with broker code, happy to know which market data source is supporting that.

6 Comments
2024/10/18
07:55 UTC

11

Question on SPX / SPXW option chain using the Schwab (formerly TDA) API

My algo trades options on SPX, which involves requesting the option chain for "$SPX".

Usually that returns the chain for SPXW (the daily expiration, which stops trading at ~4:15pm) but requesting the "$SPX" option chain for this friday/tomorrow returns the chain for SPX (not SPXW) which is the monthly and it stops trading sometime in the AM.

(background comment on SPX vs. SPXW https://old.reddit.com/r/thetagang/comments/1buelyh/0dte_spx_expiration_time_4pm_or_1159pm/kxvd3t9/ )

If I use ThinkOrSwim https://trade.thinkorswim.com/trade?symbol=SPX to look at the option chain tomorrow has "October 18th 2024 AM" AND "October 18th 2024" (the PM version).

I want to get the second one in my code (the one that doesn't expire in the AM)

I tried requesting tomorrow's option chain for "SPXW" and "$SPXW", but both error with 'invalid ticker'.

I am asking the Schwab team but I'm not expecting a quick response, so I thought I'd see if anyone here had experience / suggestions for this.

SOLVED

When getting the option chain, Schwab returns an array of strike prices, and each strike price has an array of quotes - first element is for SPX, second element is for SPXW. Every other expiration of the month returns the standard single element array (of just SPXW) for each strike.

4 Comments
2024/10/17
23:35 UTC

29

Need thoughts on my approach to reduce slippage

I have been running an automated algo for about 8 months with around 160 trades. At first I used market order for both entry and exit, thinking naively that slippage cant hurt that much, resulting in average 0.4 point of slippage per trade (translating into ~18% ytd profit reduction due to slippage only).

After much thinking and testing, I decided to implement a way which dynamically adjusts my limit order price to the changes in current market price, specially most recent two ticks. Say if price moves up from my entry price, order price will move up by a larger amount to ensure order execution and if it goes down order price will go down as well so that I can capture some positive slippage. After ~15 trades with this approach, average slippage is around 0.1 per trade. I need some outside thoughts on my approach so that I don't get naively overconfident going forward lol

53 Comments
2024/10/16
15:25 UTC

25

At what point is my strategy considered to be datamined or overfitted?

The most common example of data mining that is often discouraged is trying to train a NN on a OHCL dataset to find patterns in past prices and predict future prices. Are there any other examples of common mistakes?

Also, how would I determine whether my strategy is “legitimate” or have any alpha?

13 Comments
2024/10/16
05:48 UTC

48

Full auto algo trading tool, free, purchase or subscription?

I've been trading my strategy using python and IB API for about 2 years now and I find that its upkeep is pretty expensive, time-wise. That and the bugs in my code eats into my edge pretty badly (like missing a stop might cost 20x the edge from a trade)

have you guys found good full auto trading tool to use, buy or subscribe to?

ideally, the tool will have a language to enact things like:

  • at 11:05am every day

  • find the strike that is 30 less than At the Money, and the expiration that is nearest

  • after executing trade A, immediately put in a stop order for x% of the execution price

  • create an indicator based off of [instrument] straddle price

  • when indicator I is 30% more than its price 20 minutes ago, execute Y trade

  • calculate delta of portfolio

  • when net delta of portolio exceeds Z, execute trade C

  • execute strategy S every day whether I log in or not

  • (might be contradictory to the previous requirement) run locally so my strategies don't get mined by the host

and so on

I looked online and found things like Quantower, Multicharts, Ctrader, MT4/5.

I also wouldn't be opposed to a python library or something that abstracts away some of the more complicated coding.

I don't really mind how much this thing costs as long as it is cheaper than hiring a developer

Thoughts?

Edit: y'all are useless. When I did my research, I found 6 tools and had trouble choosing between them. Now that I've posted here and you guys responded, I now know about 12 tools and still can't choose between them. ❤️ /r/algotrading

78 Comments
2024/10/15
19:16 UTC

Back To Top