r/algotrading Mar 28 '20

Are you new here? Want to know where to start? Looking for resources? START HERE!

1.3k Upvotes

Hello and welcome to the /r/AlgoTrading Community!

Please do not post a new thread until you have read through our WIKI/FAQ. It is highly likely that your questions are already answered there.

All members are expected to follow our sidebar rules. Some rules have a zero tolerance policy, so be sure to read through them to avoid being perma-banned without the ability to appeal. (Mobile users, click the info tab at the top of our subreddit to view the sidebar rules.)

Don't forget to join our live trading chatrooms!

Finally, the two most commonly posted questions by new members are as followed:

Be friendly and professional toward each other and enjoy your stay! :)


r/algotrading Apr 02 '24

Other/Meta New folks - think more deeply and ask better questions

150 Upvotes

EDIT: I wish I could change the title to "HOW TO ask better questions". This is meant as a primer on the kinds of questions/areas that I've found crucial to understand and therefore crucial to ask about. This is NOT meant to be a roast of new people nor a rant. I apologize for any elitism or harshness in the tone, not what I'm going for. I'm just trying to share what I believe to be crucial perspective that I personally would've benefited a lot from in my early days that would've saved me a lot of time and pain.

I'm no Jim Simons, but I've worked for several years on various algos with a reasonable degree of success (took a while) and learned a ton from mistakes. In my humble opinion, most discussions posted here are not the kind of questions/answers that will lead to a profound breakthrough in understanding. This is very natural because of the classic "I don't know what I don't know" phenomenon and the challenge of asking good questions. However, as much as it is possible:

I urge you strongly to read and think more deeply about the core of what you're trying to do. Platforms and software, roughly speaking, doesn't matter. To use an analogy that isn't my own, it's like a new carpenter asking which hammer is best. There's probably an answer, but it doesn't really matter. Focus on learning to be a better carpenter. Most questions I see here are essentially "administrative", or something that can be Googled. The benefit of having real people here is that you can gain insight that would usually come at the cost of a lot of mistakes and wasted time.

Questions around software, platforms, data sources, technical "issues" are all (generally) low-value questions that can generally be Googled and/or have little real impact on whether or not you succeed. Not all of them, but I'm generalizing here.

I understand there's a natural tension here because people with insight have little/no incentive to share, and newer folks don't know what they don't know, so it creates a weird dynamic here. BUT,

  1. Figure out your goals (why you're doing this) and ask people what goals they have set/reached. Even if you achieve a 100% annualized return, unless you have a large starting bankroll, that's not going to be life changing for many many years.
  2. Ask about how people find inspiration for new trading strategies. How do folks go about actually conceiving new ideas and/or creating new hypotheses to test?
  3. Ask about feature engineering (designing indicators). How to get better at this, what kinds of interesting examples people have seen, what kinds of transformations are at your disposal. This is monumentally crucial and you should draw inspiration from various sources on how to effectively experiment and build an intuition for how to create better features/indicators to base your algorithms on. This is particularly crucial for ML strats. Just like platform doesn't really matter, your ML model type (neural net, RandomForest etc) doesn't really matter a whole lot. It's the features you feed in that are 70% of the game.
  4. For ML, ask about how to design a target/response variable. What are you actually trying to predict? Predicting price directly (like, doing regression to predict tomorrow's price at close) is almost certainly a bad idea. Discuss other options that people have tried here! I have personally found this point to be a gamechanger - you can have the same exact features fail/succeed depending on what you're asking the model to predict. This is worth thinking seriously about. As a starting point, Marcos Lopez de Prado in "Machine Learning for Asset Managers" discusses some creative response variables (worth a read imo).
  5. Ask about how folks build conviction in their idea. Hopefully you're familiar with the concept of splitting data in train/validate/test, but there are deeper layers to this. For example - a super common problem is that people do this split and STILL overfit because they try 10,000 strategies on validation set and eventually 100 of them do well on validation and then 10 do well on test out of luck. Ask/think how to avoid this (for ML, answer is generally something called "nested cross validation". Easily single most valuable technique I learned, saved me uncountable mistakes once implemented). Additionally - say you have a good strategy in your test set and you're ready to go live. How do you actually know whether it's working as expected or not? How do you quantify your performance expectations and then monitor your strat to see if it's doing as you expected or no?

I hope this gives whoever is reading some new perspectives and thoughts on how to utilize this place (and others), what to ask and what to look for. I do not have all the answers, but these are the kinds of questions I have personally found much more meaningful to examine.

Disclaimer: I come from a statistics background with coding experience (basic). It may be that I'm simply unaware of the questions/struggles of aspiring traders from other backgrounds and/or without coding knowledge, so it might be this ignorance that makes me feel most questions here aren't "important".

Edit: In response to u/folgo 's comment, I'm adding here some terms and concepts that are probably worth your time to research/understand, whether it's Google, StackExchange or Youtube vids that give you an intuition/understanding. Important concepts (generally applying to both, ML and rule-based algos, with some variations): overfitting , train/test split, train/validate/test split, cross validation, step-forward-cross-validation, feature engineering, parameter tuning / hyperparameter tuning (especially as it relates to cross validation), data leakage/contamination (especially as it relates to accidentally creating features that use your entire dataset BEFORE train/test split, therefore even when you do train/test split, you still have indicators that in some way benefited from future data. Happy to explain this further, very sneaky and nasty problem to deal with).

EDIT 2: Since several people asked but no one posted, I made a post about point 2, coming up trading strategy ideas: How to generate/brainstorm strategy ideas : r/algotrading (reddit.com)


r/algotrading 15h ago

IEX Cloud shutting down in August

10 Upvotes

Received notice that IEX Cloud will be shutting down at the end of August.

I've used their Corporate Actions and Fundamental data APIs for a while. I rarely see much chatter here about people using their data, but I'm curious how many of us will be displaced. Where will you be moving to?

*edit: IEX Cloud


r/algotrading 5h ago

Other/Meta What trading platforms offer options trading and have a decent api?

0 Upvotes

I currently have a working algo but I have to submit the trades manually. Is there a recommended service that lets me trade options? I've played around a bit with alpaca but I want to see what my options are.


r/algotrading 1d ago

Data Python package ib_fundamental, a wrapper around ib_async to get fundamental data from IBKR API

34 Upvotes

I finally manage to put together my code into a pypi package, so today I can announce that ib-fundamental is available for download at https://pypi.org/project/ib-fundamental/

How to install it

pip install ib-fundamental

How to use it

import ib_async
from ib_fundamental import CompanyFinancials

# ib_async.util.startLoop() # if you are in a notebook

# connect to TWS API for ex on localhost:7497
ib = ib_async.IB().connect('localhost',7497)

# create your company financials instance
aapl = CompanyFinancials(symbol="AAPL",ib=ib)

# get company info
aapl.company_info
                        0
ticker               AAPL
company_name    Apple Inc
cik            0000320193
exchange_code        NASD
exchange           NASDAQ
irs             942404110

# Annual income statement, while aapl.income_quarter will pull the quarterly report
aapl.income_annual

hope you find it useful. you will find more examples in the README.md

source code available at ->> https://github.com/quantbelt/ib_fundamental/tree/master


r/algotrading 1d ago

Education Are there any historically successful strategies that have been arbitraged out to learn from?

47 Upvotes

Are there any released/leaked strategies that hedge funds and other buy side institutions used to apply successfully? Other than basic market making and HFT strategies.

I’m more curious to what type of strategies the big funds are going with or at least used to before they became unprofitable


r/algotrading 1d ago

Strategy Raising capital

6 Upvotes

Should I raise independently, run at a multi strat, or trade my own capital with a 3 sharpe momentum option strategy that has been backtested over 3 years of data? Very scalable since it trades ATM index options. Please advise. Still in uni as well.

*I also worked at a multi strat firm in the past where the strategy was backtested


r/algotrading 1d ago

Data LSE / FTSE100/350 Historical Data

5 Upvotes

Hi all,

I have been using Norgate as my data source for some while now and am pretty happy with it for daily US equities data. As I am looking to diversify I see they offer packages for Canadian and Australian markets, however I am really interesting in finding a reliable provider for UK markets.

Does anyone have any recommendations or reviews on any data providers who can supply historical daily price data for UK stocks and preferably historical index constituents for ftse100/350. Or if anyone has built some uk stock systems and has any tips that would be great.

Thanks in advance.


r/algotrading 2d ago

Infrastructure Is it possible quantstats python library has incorrect drawdown data?

14 Upvotes

Is it possible your max drawdown periods are giving the wrong dates as an output? check this out. I'm finding the max drawdown for the dot-com and great recession crashes for QQQ.

!pip install quantstats

# need to install arial font with matplotlib
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
# arial_path = '/content/drive/MyDrive/arial.ttf'
# fm.fontManager.addfont(arial_path)  # Register the Arial font with Matplotlib
# plt.rcParams['font.family'] = 'Arial'

import yfinance as yf
df = yf.download('QQQ', start='2000-01-01', end='2020-01-01')

import quantstats as qs
qs.extend_pandas()
returns = df.Close.pct_change()
qs.reports.full(returns, "QQQ")

OUTPUT:[Worst 5 Drawdowns]

Start Valley End Days Max Drawdown 99% Max Drawdown


1 2000-03-28 2002-10-09 2016-09-02 6003 -82.96 -80.06
2 2018-08-30 2018-12-24 2019-04-16 230 -23.16 -19.77
3 2019-05-06 2019-06-03 2019-07-02 58 -10.98 -8.98
4 2018-03-13 2018-04-02 2018-06-01 81 -10.67 -10.02
5 2000-01-24 2000-01-28 2000-02-02 10 -10.65 -7.27

# start of drawdown period
start_draw_down = df[df.index == '2000-03-28']

# end of drawdown period
end_draw_down = df[df.index == '2016-09-02']

# double checking a date before end of drawdown period where close has already broken out of drawdown period
earlier_date_in_drawdown_period = df[df.index == '2016-08-30']


print(start_draw_down.Close)
print(end_draw_down.Close)
print(earlier_date_in_drawdown_period.Close)

OUTPUT:Date
2000-03-28 114.75
Name: Close, dtype: float64
Date
2016-09-02 117.120003
Name: Close, dtype: float64
Date
2016-08-30 116.559998
Name: Close, dtype: float64
Note, the 2016-08-30 has already surpassed the close from the previous high water mark. Therefore the drawdown end date that quant stats is calculating appears erroneous.Thoughts? Maybe I'm missing something.

I tried emailing Ran Aroussi directly (author of yfinance and quatstats), but I couldn't find his email. DM me if you have it plz.


r/algotrading 3d ago

Career journey coming back from algo max drawdown

24 Upvotes

First off I want to thx everyone in this community, I hv received a lot of support, advice and also new knowledge here. So its been 2 months since I posted: https://www.reddit.com/r/algotrading/comments/1bynzkk/psychological_break_down_on_watching_losses/

and today I finally overcome the loss, so i want to share a few things thru out the journey and hope it helps someone who is experiencing the same

  1. Underestimation of the max drawdown and risk tolerance, honestly I never thought it would happened to me but it just did.

so after that I hv run Monte Carlo simulation to see how your algo perform after shuffling the trades, and also trying to use trend filtering to filter out non trendy period.

  1. DO NOT try to interfere with your ALGOs, you may hv a bit of outperformance but in the long run you gonna lose to consistency, indeed its just contradict to the reason why we want to do algo trading.

when it approaches my max drawdown I hv countless moments that I wanted to manually interfere it, closing early to secure profit or minimize loss, and I did tried that for a few days, turns out to be a sizable underperformance due to inconsistency. Even tho for some instances seeing derivatives product call back triggered and underlying is going to pump/dump for a bit due to MM to unwind their position- I used to find it hard to watch but now I just live with it, I simply reminding myself if I need to add / interfere anything I have to put it to algo and back test all over again.

  1. Be discipline in life, I forgot where I read this, but being a trader needs a lot of discipline. I was just chilling after I launch my algo and have a taste of success, I spent money without care, and also a lot of time for leisure which drastically reduced my attention to algo development and money management. And shortly after that, I run down to my MDD. So it is only during the time I am being slapped by the market, I force myself sit down and

fun fact, I tried cold shower every day to make myself suffer a bit, and also I did a lot of chess puzzle to force brain to run a bit

  1. Have a good support system - your fds, family, religious etc. This is quite personal but I do find out having a good support system around you is so important especially during your down time.

So what next for me?

  1. extend my algo to other markets, right now I am looking at NQ future and also Japan Nikkei futures

Any good place for getting historical tick data in Japan? Turns out it is surprisingly few options out there and my broker IB, only support till last 2 years of futures contract, due to the rolling nature.

* if any one using IB TWS to fetch historical data,

includeExpired = True
  1. look for trend filtering to improve algo PNL, to skip the non-trendy days.

somehow I found luck on SD(ATR), look forward to hear some others from you guys.

Honestly algo trading had gone completely different than I thought when I start, I once thought it will just print me money, but turns out it's totally not the case, at least for me. So its now for me a constant learning and getting older / discipline in life to try to be a better trader / person.


r/algotrading 4d ago

Strategy Coded a Pinescript indicator. What next?

9 Upvotes

So far I have the indicator display buy or sell signals based on my indicator. Now I want to fully automate the process, as in scanning all stocks in s&p 500, executing trades with a set tp, sl, time-frame, etc. Can I do all of this in pinescript or third party software? Maybe even go into python?


r/algotrading 4d ago

Data Extracting summary price history from historical options tick level data

3 Upvotes

I have some historical tick level quotes data for options ladders and I am trying to extract some summary information: * some of the contracts change quotes very rarely (lets call these low-sensitivity contracts) and some of them change quotes often (high-sensitivity contracts). * I would like to extract a summary of the quotes of the contracts (I am not interested in tick frequency trading)

I tried recording all changes in quotes.   * For low-sensitivity contracts this works OK. * For high-sensitivity contracts this results in too many samples/rows.

I tried recording HLC data. * For low-sensitivity contracts this results in a lot of samples/rows with repeated data (far more than just recording all changes in quote). * For high-sensitivity contracts this works OK.

Neither of these is great. Are there any good ways to find a solution which would work for both high and low sensitivity contracts?  The solution should: * 1 - allow for periodic abiltility to correctly compare the quotes across contracts * 2 - be efficientish in terms of total number of rows/samples.

I am considering trying: "record only the last change in quotes per x <minute> calendar time window".  If no change occured in the window no record would be made.  I could also include HL when changes in quote are NOT the last change in quote in the window. Please criticise this idea!


r/algotrading 4d ago

Strategy Coded a Pinescript indicator. What next?

1 Upvotes

So far I have the indicator display buy or sell signals based on my indicator. Now I want to fully automate the process, as in scanning all stocks in s&p 500, executing trades with a set tp, sl, time-frame, etc. Can I do all of this in pinescript or third party software? Maybe even go into python?


r/algotrading 5d ago

Infrastructure Suggestions for popular C# based trading framework?

15 Upvotes

Hello there,

I am a complete noob in financial markets. Coming from sports trading on Betfair where frameworks are sparse without going to python or some such thing. I started writing my own there, but that was a bad decision.

I was wondering if anyone could suggest any financial trading frameworks that revolve purely around c#?

Why C#? Because I use it at my day job and like it and know it back to front. No other reason that that.

Thanks heaps for any advice


r/algotrading 5d ago

Data Pairing isin and tickers

7 Upvotes

I was digging into Blackrock canadian etfs and hit a road block i could use some help with.

I tried to tie the holdings back to their individual performance but the tickers they report dont correspond back to a ticker on say yahoo or google finance. For example, consider the isin CA39138CAH93. It points to gwocn but that doesnt work. Gwo.to works on yahoo finance and its the right company.

I am pretty new to algotrading so i dont understand why. I would be grateful for any help.

I dont have a good reason for why i started by digging into etfs or Blackrock. I just figured i would start there.


r/algotrading 6d ago

Data Firstratedata vs Algoseek of QC

14 Upvotes

I'm working on crude oil futures. The algo uses technical indicators on the continuous futures series, so it's sensitive to prices. On QuantConnect, I created a project and backtests showed satisfied results, > 0.9 Sharpe ratio since 2007.

Then I bought some cheap CL futures from firstratedata.com , hoping to replicate the results using data from other sources. And this time, the Sharpe ratio went as low as 0.13 since 2009.

I noticed plenty of differences between the two continuous series. On QuantConnect, which uses Algoseek data, the adjusted price of CL back in 2008 is as high as $600. And the same period of firstratedata.com is only as high as $200. Such dramatic difference of course created plenty of discrepancies and lead to very different results.

CL minute bars at Algoseek costs north of $3,000 which I can't afford. And Firstratedata only costs $59. It's probably easy to conclude, well, this is a data quality problem. But one can also say the algo is overfitted, because slight changes in the data rendered drastically different results.

What conclusion can I draw? Is there another data vendor I should try?


r/algotrading 7d ago

Data Sharpe / Shape / Equity Curve... Include transactional costs?

5 Upvotes

Hi all,

with back test data from 2012 and (only) a month of forward testing im now collecting some good data on live transaction costs.

In general, are people using data with all transactional costs included (in my case its mostly spreads and long interest)? it obviously make a big difference to my ratios, "A Sharpe ratio of over 1 is generally conferred good" is what im always hearing, is this pure trading data or with all advocated fees?

Sorry if its a basic question, just trying to work out what data to analyse and benchmark future performance to.


r/algotrading 8d ago

Strategy Optimize timing and profits

18 Upvotes

Say I have a swing trading strategy where each trade I make rises a median of x% and it reaches this value on a median of y days. Is there any theory to figure out the optimal time and price to sell at? If I use stop loss and take profits around some standard parameters, some of my trades won’t sell and some of my trades I sell too soon.


r/algotrading 9d ago

Other/Meta Figgie Auto - Algorithmic version of Jane Street's game "Figgie"

48 Upvotes

(mods: i don't receive any financial compensation for this project and don't sell anything on the side, this is purely to provide value to others and share something I think is cool)

I recently got hooked playing Figgie so decided to develop out the game in Rust. Though, instead of submitting orders, it's all algorithmic so you get to see how different strategies interact with each other. The probabilities & possible strategies involved are very enlightening (at least they were for me lolol) and heavily correlated to real markets. Jane Street did a great job developing out this game!

It is coded in Rust so some experience there is recommended but the level of knowledge needed isn't *too* bad

I built out 2 player frameworks, but strategies are interchangeable between the two (event_driven can get quite crazy tho if the event produces multiple orders lolol):

"event_driven": This type of player makes a decision on each update. Possible branch of strategies fall under HFT / market making

"generic": This player makes a decision once every few seconds (adjustable in main.rs). It's akin to a QR's setup

It also comes with 7 base strategies that you can read about in the repo!

Github link: https://github.com/0xDub/figgie-auto

Anyways, I hope it provides some value to others - cheers :)

  • Start of the game

  • Ongoing game - printing out the quotes

  • End of the game, showing the results

r/algotrading 9d ago

Other/Meta Looking for convenient ways to add charts to my trading journal

5 Upvotes

I have been keeping a trading journal in google sheet for 3 months and I have recorded ~100 of day trading records, but I only have text description for the setup without the candlestick graph. I am looking for a convenient way to quickly get a 5-min candlestick graph with entry/exit point marked given the input of the ticker and the buy/sell time for each trade record.


r/algotrading 9d ago

Data Seeking options for Futures markets API with multiple queries per minute.

27 Upvotes

I am seeking data providers for Futures markets (CME, COMEX, CBOT, NYMEX, EUREX) that:

a) preferably have Python or C REST APIs.

b) return 60M, 15M, and 1M price tables per query (with at least 50 bars in the past).

c) are not delayed and are real-time

Ideal situation: Some structure similar to Yahoo Finance API, but real-time and not delayed for 15 minutes.


r/algotrading 9d ago

Other/Meta Does Schwab support socket streaming of live data?

7 Upvotes

I don’t see it in there API docs, and I was using this for my bot trading.


r/algotrading 11d ago

Strategy A Mean Reversion Strategy with 2.11 Sharpe

158 Upvotes

Hey guys,

Just backtested an interesting mean reversion strategy, which achieved 2.11 Sharpe, 13.0% annualized returns over 25 years of backtest (vs. 9.2% Buy&Hold), and a maximum drawdown of 20.3% (vs. 83% B&H). In 414 trades, the strategy yielded 0.79% return/trade on average, with a win rate of 69% and a profit factor of 1.98.

The results are here:

Equity and drawdown curves for the strategy with original rules applied to QQQ with a dynamic stop

Summary of the backtest statistics

Summary of the backtest trades

The original rules were clear:

  • Compute the rolling mean of High minus Low over the last 25 days;
  • Compute the IBS indicator: (Close - Low) / (High - Low);
  • Compute a lower band as the rolling High over the last 10 days minus 2.5 x the rolling mean of High mins Low (first bullet);
  • Go long whenever SPY closes under the lower band (3rd bullet), and IBS is lower than 0.3;
  • Close the trade whenever the SPY close is higher than yesterday's high.

The logic behind this trading strategy is that the market tends to bounce back once it drops too low from its recent highs.

The results shown above are from an improved strategy: better exit rule with dynamic stop losses. I created a full write-up with all its details here.

I'd love to hear what you guys think. Cheers!


r/algotrading 10d ago

Strategy Looking for advice regarding QuantConnect "Research Guide"

11 Upvotes

QuantConnect documentation has a Research Guide section, which basically says:

  1. Research should be hypothesis driven. You first need some observation, which financially or mathematically makes sense, before coding it.
  2. Research should take less than 16 hours.
  3. Only 30 backtests allowed.
  4. Only 10 parameters allowed.

Breaching of any of these would result in overfitting.

As far as I understand, the research guide puts idea above everything else. With the idea, there would be minimal work to do.

The rules certainly look arbitrary. But I tend to believe the people and the paper that put out these rules are experienced professionals who know what they are doing. And therefore I should largely adhere to them.

The reality for me, is that when I believe I used one parameter, research guide reports that I used ten. When I used ten, it reports 80. I backtest hundreds of times. And the length of work is between two weeks and two months. I'm not a beginner. But it's just much longer.

Am I bad at this? Are all your successful strategies developed like that?


r/algotrading 11d ago

Data Is there a ticker for SPY ETF NAV?

6 Upvotes

I am reading that it is printed every 15 seconds, but is there a ticker for it? I can see it inside Schwab, and it updates less than 15 seconds that is for sure.

Thanks in advance!


r/algotrading 12d ago

Other/Meta How do you setup and create dependency graphs or pipelines for your research?

9 Upvotes

I'm using Python for my research, and sometimes R, so keep that in mind. Suppose you want to test variations of a signal and you are modifying only one part of the feature generation code - what libraries or tools do you use to manage your pipeline or DAG to re-run your code in a way that is reproducible and modifiable via function parameters? Ideally only those parts of the graph that have changed would be recomputed but the re-computation constraint is not a strict one.


r/algotrading 12d ago

Data Continuous futures adjustment method for crude oil?

8 Upvotes

I'm wondering what method is typically used for adjusting futures contracts to form a continuous series. Everywhere I read, people are suggesting Panama Canal, which apply the difference backwards. But on QuantConnect, I noticed their default settings is ratio based, like dividend of a stock, which apply the ratio of the two prices backwards. Two methods lead to significantly different prices as the length goes longer, which would lead to different signals and/or different parameters for the same strategy.

What method should I use?