/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,754,403 Subscribers

59

Alternative data source (Yahoo Finance now requires paid membership)

I’m a 60 year-old trader who is fairly proficient using Excel, but have no working knowledge of Python or how to use API keys to download data. Even though I don’t use algos to implement my trades, all of my trading strategies are systematic, with trading signals provided by algorithms that I have developed, hence I’m not an algo trader in the true sense of the word. That being said, here is my dilemma: up until yesterday, I was able to download historical data (for my needs, both daily & weekly OHLC) straight from Yahoo Finance. As of last night, Yahoo Finance is now charging approximately $500/year to have a Premium membership in order to download historical data. I’m fine doing that if need be, but was wondering if anyone in this community may have alternative methods for me to be able to continue to download the data that I need (preferably straight into a CSV file as opposed to a text file so I don’t have to waste time converting it manually) for either free or cheaper than Yahoo. If I need to learn to become proficient in using an API key to do so, does anyone have any suggestions on where I might be able to learn the necessary skills in order to accomplish this? Thank you in advance for any guidance you may be able to share.

78 Comments
2024/09/07
14:22 UTC

32

Creating bots as a service?

THIS IS NOT A SOLICITATION. Please don't DM


That said. Would there be a market for automating and back/forward testing strategies for traders/investors that aren't quite as technically savvy?

No crazy promises of profits or anything.

Just: You give us the play by play of your strategy. And we will automate it for you?

My gut wants to say there would be. But I guess... my other gut... it says that if someone had a profitable strategy they wanted to automate. They wouldn't just give it to some nerd with every minute detail to their strategy.

Idk. Was taking a poop and the idea popped into my head. Figured I'd throw it out there and see if a legitimate discussion might start.

So... opinions?

Edit: so the collective opinion is that this can be a valuable business proposition.

Some guys are already doing it There some.bug boy companies offer8ng these services. And the AI/algo prop idea isn't all that bad.

The dude that said "Google it" what's your address. I wanna send you the biggest and prettiest, pink, hello Kitty dildo.. hmu.

Everyone else.. thank you! This is why I wanted to communicate rather than search.

I have no intentions of doing this anytime soon(if ever) but now I know it is a possibility and will be given some mental real estate.

I really appreciate the input What some of you are doing is really freaking cool!!

95 Comments
2024/09/06
00:55 UTC

1

Calendar history

Where can I get the calendar history for the past 2 years using an API?

2 Comments
2024/09/05
20:53 UTC

0

Does anyone have experience with Kaiko or Amberdata? I’m looking for historical order book data for crypto

Given crypto markets are decentralized, it seems like these two options provide data from several different exchanges. Does anyone have experience with either one, or an alternative? I’m looking for order book snapshots, or potentially full order book updates.

6 Comments
2024/09/05
12:08 UTC

1

What do you think is a good Masters Thesis topic combining finance/stock and machine learning?

Hello guys, i wanted to take your opinion on what topic should i study in my masters degree, a little background about me i am a computer engineering fresh grad and has some experience in ML from my uni courses and my bachelor thesis. also, i dabbled in stock trading, studying technical analysis, trends and company financials.
Me personally i want to research building a ML model which utilizes technical analysis indicators, stock data etc.. to predict whether the stock will go up or down (studying maybe different trading time frames), also there are some suggestions of utilizing NLP, i have no background in it so it would be much harder (which i dont mind ) but, whenever i search on predicting stock market using ML or any predictive way they say its impossible due to its random nature volatility, its like gambling and so on, even with complex ML models.

So, what do you think of a research topic like this, is it worth it or not?

I am also open to your suggestions and experience, Thank You.

5 Comments
2024/09/05
11:49 UTC

16

How can I safely increase trade frequency? Difficulty getting option chain universe.

So I developed a seemingly reliable options trading algorithm (largely selling mispriced puts). However, it only finds these mispriced options about once every two or three weeks.

While some of the issue is that these mispriced options may exist infrequently like unicorns, I think a bigger problem is that I cannot efficiently search the entire universe of option chains. There doesn't seem to be an API where one can quickly pull every securities' option chain. I have to tell the API which underlying security I want information about, then traverse the resulting chain by strike price and expiry date.

It's very cumbersome, so I'm only selecting about 200 securities each day that I think may have mispriced options. It's all very inefficient, sometimes my script times out, sometimes I hit the API rate limit.

Any suggestions on how I can search more options at once more quickly and without hitting API rate limits?

Is there an API where you can search options (like a finviz for options)?

Thanks!

61 Comments
2024/09/05
09:42 UTC

25

Hardware/Software Recommendations for Trading Algorithms

Does anyone have any recommendations for what hardware to use to run a trading algorithm, as well as what coding language to use to run it? I’m looking to forward test strategies, but I figure I need some hardware to have it run throughout the day rather than keeping my computer on permanently.

I’ve been messing around trying to develop strategies in Python, but I’m not sure if that’s going to work for forward testing or potentially live trading. I’m pretty good with Python, so are there any drawbacks to using it for live trading?

Lastly, do I need to use a specific broker, or do most brokers have an API that allows you to run an algorithm with your accounts?

Overall, any recommendations on how to go from backtesting a strategy to actually implementing it would be greatly appreciated.

43 Comments
2024/09/05
04:24 UTC

1

What platform are you using for walk forward analysis?

I have been limping along with tradestation for about year. SQX initially looked promising, but there have to be better tools available?

Edit: Anybody out there?

7 Comments
2024/09/04
21:06 UTC

22

How to calculate the historical futures rollover cost?

I've a swing strategy that holds trades for multiple months. The futures that I'm trading have a expiry of 3 months.

Since my strategy can hold a trade for more than 3 months, it needs to rollover the contract at each expiry.

Rollover usually comes at a cost because the next month contract trades at a higher price than the expiring contract - and the strategy must take this into account to report the correct PnL.

I can find stock futures data at multiple places, but this data is always back adjusted.

Because of the back-adjustment, it seems that the rollover cost is effectively lost from the data.

I looked online, and I am unable to find any place that shows the historical rollover costs for the futures!

  • isn't this an important piece of info? How come this info is not available anywhere!?
  • am I missing something here?
8 Comments
2024/09/04
20:11 UTC

314

Backtest Results for a Simple Reversal Strategy

Hello, I'm testing another strategy - this time a reversal type of setup with minimal rules, making it easy to automate.

Concept:

Strategy concept is quite simple: If today’s candle has a lower low AND and lower high than yesterday’s candle, then it indicates market weakness. Doesn’t matter if the candle itself is red or green (more on this later). If the next day breaks above this candle, then it may indicate a short or long term reversal.

Setup steps are:

Step 1: After the market has closed, check if today’s candle had a lower low AND a lower high than yesterday.

https://preview.redd.it/ac0jhgrn1tmd1.png?width=770&format=png&auto=webp&s=1dff19fc34a77a1189f9888d1350de2f0dacc48b

Step 2: Place BUY order at the high waiting for a reversal

https://preview.redd.it/z1zgwfdo1tmd1.png?width=842&format=png&auto=webp&s=3397520ce8f9a0542c2b9f2fc6152ac123f554e9

Step 3: If the next day triggers the buy order, then hold until the end of the day and exit at (or as close as possible to) the day’s close.

https://preview.redd.it/f6gkunyo1tmd1.png?width=1041&format=png&auto=webp&s=9a93422ae7316808c4e80fdd9ac5c88da3fbe4be

Analysis

To test this theory I ran a backtest in python over 20 years of S&P500 data, from 2000 to 2020. I also tested a buy and hold strategy to give me a benchmark to compare with. This is the resulting equity chart:

https://preview.redd.it/ej5nbklp1tmd1.png?width=2082&format=png&auto=webp&s=6aef5fd2d49d96fe7c9704968999e58ca4967b9f

Results

Going by the equity chart, the strategy seemed to perform really well, not only did it outperform buy and hold, it was also quite steady and consistent, but it was when I looked in detail at the metrics that the strategy really stood out - see table below.

  • The annualised return from this strategy was more than double that of buy and hold, but importantly, that was achieved with it only being in the market 15% of the time! So the remaining 85% of the time, the money is free to be used on other strategies.
  • If I adjust the return based on the time in market (return / exposure), the strategy comes out miles ahead of buy and hold.
  • The drawdown is also much lower, so it protects the capital better and mentally is far easier to stomach.
  • Win rate and R:R are also better for the strategy vs buy and hold.
  • I wanted to pull together the key metrics (in my opinion), which are annual return, time in the market and drawdown, and I combined them into one metric called “RBE / Drawdown”. This gives me an overall “score” for the strategy that I can directly compare with buy and hold.

https://preview.redd.it/d3h157qq1tmd1.png?width=1683&format=png&auto=webp&s=20199c9b1b959ed11943984df3df14c7b2e8fa53

Improvements

This gave me a solid start point, so then I tested two variations:

Variation 1: “Down reversal”: Rules same as above, BUT the candle must be red. Reasoning for this is that it indicates even more significant market weakness.

Variation 2: “Momentum”: Instead of looking for a lower low and lower high, I check for a higher low and higher high. Then enter at the break of that high. The reasoning here is to check whether this can be traded as a momentum breakout

The chart below shows the result of the updated test.

https://preview.redd.it/uac02nkr1tmd1.png?width=2082&format=png&auto=webp&s=ca84df5268eded664125db9e4ee6ab3570bfe8c3

Results

At first glance, it looks like not much has changed. The reversal strategy is still the best and the two new variations are good, not great. But again, the equity chart doesn’t show the full picture. The table below shows the same set of metrics as before, but now it includes all 4 tested methods.

https://preview.redd.it/e3dqxy2s1tmd1.png?width=1864&format=png&auto=webp&s=4f1fe9dd5f06fac5e4cd0e76579f3766a9b36d74

Going by the equity chart, the “Down reversal” strategy barely outperformed buy and hold, but the metrics show why. It was only in the market 9% of the time. It also had the lowest drawdown out of all of the tested methods. This strategy generates the fewest trade signals, but the ones that it does generate tend to be higher quality and more profitable. And when looking at the blended metric of “return by exposure/drawdown”, this strategy outperforms the rest.

EDIT: Added "out of sample testing" section below on 04/09:

Out of Sample Testing

All of the results in the sections above were done on the "in-sample" data from 2000 to 2020. I then ran the test from 2020 to today to show the results of the "out-of-sample" test. Equity chart below

https://preview.redd.it/m9m7hls3aumd1.png?width=1387&format=png&auto=webp&s=c41f594fd35aca945c3180a7ee91fe1ed1d108bb

The equity chart only shows half the picture though, the metrics below show that the system performance has held on well, especially the drawdown, which has been minimal considering the market shocks over the last 4 years:

https://preview.redd.it/rlao1yibaumd1.png?width=857&format=png&auto=webp&s=dc066c8a925a437ee3f551e789aa4c0628bdaa5f

Overfitting

When testing on historic data, it is easy to introduce biases and fit the strategy to the data. These are some steps I took to limit this:

  • I kept the strategy rules very simple and minimal.
  • I also limited my data set up until 2020. This left me with 4.5 years worth of out of sample data. I ran my backtest on this out of sample dataset and got very similar results with “reversal” and “down reversal” continuing to outperform buy and hold when adjusted for the time in the market.
  • I tested the strategy on other indices to get a broader range of markets. The results were similar. Some better, some worse, but the general performance held up.

Caveats:

The results look really good to me, but there are some things that I did not account for in the backtest:

  1. The test was done on the S&P 500 index, which can’t be traded directly. There are many ways to trade it (ETF, Futures, CFD, etc.) each with their own pros/cons, therefore I did the test on the underlying index.
  2. Trading fees - these will vary depending on how the trader chooses to trade the S&P500 index (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.
  4. Dividend payments from S&P500. Not considered in the backtest.
  5. And of course - historic results don’t guarantee future returns :)

Code

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

More info

This post is even longer than my previous backtest posts, so for a more detailed explanation I have linked a vide below. In that video I explain the setup steps, show a few examples of trades, and explain my code. So if you want to find out more or learn how to tweak the parameters of the system to test other indices and other markets, then take a look at the video here:

Video: https://youtu.be/-FYu_1e_kIA

What do you all think about these results? Does anyone have experience trading a similar reversal strategy?

Looking forward to some constructive discussions :)

140 Comments
2024/09/04
14:47 UTC

9

Looking for historical consensus revenue and EPS forecasts

Like the title says, I'm looking for historical consensus revenue and EPS forecasts for US stocks that doesn't cost an arm and a leg. "TrueBeats" on QuantConnect wants $825/year, and Zacks wants $250/year and I'm not sure the EPS info is even available at that tier.

I'm willing to do some programming to scrape and store, or pay maybe $100 for a one-time dump for data from approx. 2021 through 2023.

Any suggestions where to look?

23 Comments
2024/09/04
14:03 UTC

3

Schwab Historical data source?

Does anyone know what Schwab bases their historical data off of? I've been doing some testing with the Schwab API and have noticed that some of their historical data doesn't seem in line with other sources (Alpaca, Tradingview) and is sometimes off by several dollars. I know this could potentially be due to the source of data for each system. Trying to narrow down where these discrepencies are coming from

4 Comments
2024/09/04
13:46 UTC

1

Computing NAV of SPY

Total noob here. I was trying to compute the NAV of SPY.(I saw the ticker on ToS, but it gets updated only once a day and I wanted to get more updated results). I was thinking of getting the NAV by getting the value of all the holdings that is updated daily and updating the value based on the latest stock price. Is this a reasonable apporach?

This also leads me to the next question: what's the frequency with which the number of shares held by SPY change?

2 Comments
2024/09/04
12:42 UTC

20

ideas on algo result optimisation

Would like to brainstorm on the optimisation techniques for algo trading.

Disclaimer I run algo trading on technical indicators trading intraday.

Things I hv found

  1. Remove hard stop loss based on % or so, use only indicator to stop.

  2. Use SD(ATR) to filter out non trending days

  3. If you trade non US products, consider not to open a trade in non continuous trading session before US market open

29 Comments
2024/09/04
06:44 UTC

4

How Far Back Do I need To Backtest Intra-Day Strategy?

I am testing a strategy in python and finding the optimal parameters for the indicators I will be using and wanted to get an opinion on how far back I need to go to backtest this. I will be trading on a 3 min time frame, and I initially started to backtest with 3 years' worth of data, but do I need to go further back 5 years, 8, 10? Markets change repeatedly and my conclusions was anything past 3 years is worthless.

10 Comments
2024/09/04
04:34 UTC

96

The impossibility of predicting the future

I am providing my reflections on this industry after several years of study, experimentation, and contemplation. These are personal opinions that may or may not be shared by others.

The dream of being able to dominate the markets is something that many people aspire to, but unfortunately, it is very difficult because price formation is a complex system influenced by a multitude of dynamics. Price formation is a deterministic system, as there is no randomness, and every micro or macro movement can be explained by a multitude of different dynamics. Humans, therefore, believe they can create a trading system or have a systematic approach to dominate the markets precisely because they see determinism rather than randomness.

When conducting many advanced experiments, one realizes that determinism exists and can even discover some "alpha". However, the problem arises when trying to exploit this alpha because moments of randomness will inevitably occur, even within the law of large numbers. But this is not true randomness; it's a system that becomes too complex. The second problem is that it is not possible to dominate certain decisive dynamics that influence price formation. I'm not saying it's impossible, because in simpler systems, such as the price formation of individual stocks or commodity futures, it is still possible to have some margin of predictability if you can understand when certain decisive dynamics will make a difference. However, these are few operations per year, and in this case, you need to be an "outstanding" analyst.

What makes predictions impossible, therefore, is the system being "too" complex. For example, an earthquake can be predicted with 100% accuracy within certain time windows if one has omniscient knowledge and data. Humans do not yet possess this omniscient knowledge, and thus they cannot know which and how certain dynamics influence earthquakes (although many dynamics that may seem esoteric are currently under study). The same goes for data. Having complete data on the subsoil, including millions of drill cores, would be impossible. This is why precursor signals are widely used in earthquakes, but in this case, the problem is false signals. So far, humans have only taken precautions once, in China, because the precursor signals were very extreme, which saved many lives. Unfortunately, most powerful earthquakes have no precursor signals, and even if there were some, they would likely be false alarms.

Thus, earthquakes and weather are easier to predict because the dynamics are fewer, and there is more direct control, which is not possible in the financial sector. Of course, the further ahead you go in time, the more complicated it becomes, just like climatology, which studies the weather months, years, decades, and centuries in advance. But even in this case, predictions become detrimental because, once again, humans do not yet have the necessary knowledge, and a small dynamic of which we are unaware can "influence" and render long-term predictions incorrect. Here we see chaos theory in action, which teaches us the impossibility of long-term predictions.

The companies that profit in this sector are relatively few. Those that earn tens of billions (like rentec, tgs, quadrature) are equally few as those who earn "less" (like tower, jump, tradebot). Those who earn less focus on execution on behalf of clients, latency arbitrage, and high-frequency statistical arbitrage. In recent years, markets have improved, including microstructure and executions, so those who used to profit from latency arbitrage now "earn" much less. Statistical arbitrage exploits the many deterministic patterns that form during price formation due to attractors-repulsors caused by certain dynamics, creating small, predictable windows (difficult to exploit and with few crumbs). Given the competition and general improvement of operators, profit margins are now low, and obviously, this way, one cannot earn tens of billions per year.

What rentec, tgs, quadrature, and a few others do that allows them to earn so much is providing liquidity, and they do this on a probabilistic level, playing heavily at the portfolio level. Their activity creates a deterministic footprint (as much as possible), allowing them to absorb the losses of all participants because, simply, all players are losers. These companies likely observed a "Quant Quake 2" occurring in the second week of September 2023, which, however, was not reported in the financial news, possibly because it was noticed only by certain types of market participants.

Is it said that 90% lose and the rest win? Do you want to delude yourself into being in the 10%? Statistics can be twisted and turned to say whatever you want. These statistics are wrong because if you analyze them thoroughly, you'll see that there are no winners, because those who do a lot of trading lose, while those who make 1-2 trades that happen to be lucky then enter the statistics as winners, and in some cases, the same goes for those who don't trade at all, because they enter the "non-loser" category. These statistics are therefore skewed and don't tell the truth. Years ago, a trade magazine reported that only 1 "trader" out of 200 earns as much as an employee, while 1 in 50,000 becomes a millionaire. It is thus clear that it's better to enter other sectors or find other hobbies.

Let's look at some singularities:

Warren Buffett can be considered a super-manager because the investments he makes bring significant changes to companies, and therefore he will influence price formation.

George Soros can be considered a geopolitical analyst with great reading ability, so he makes few targeted trades if he believes that decisive dynamics will influence prices in his favor.

Ray Dalio with Pure Alpha, being a hedge fund, has greater flexibility, but the strong point of this company is its tentacular connections at high levels, so it can be considered a macro-level insider trading fund. They operate with information not available to others.

Therefore, it is useless to delude oneself; it is a too complex system, and every trade you make is wrong, and the less you move, the better. Even the famous hedges should be avoided because, in the long run, you always lose, and the losses will always go into the pockets of the large liquidity providers. There is no chance without total knowledge, supreme-level data, and direct control of decisive dynamics that influence price formation.

The advice can be to invest long-term by letting professionals manage it, avoiding speculative trades, hedging, and stock picking, and thus moving as little as possible.

In the end, it can be said that there is no chance unless you are an exceptional manager, analyst, mathematician-physicist with supercomputers playing at a probabilistic level, or an IT specialist exploiting latency and statistical arbitrage (where there are now only crumbs left in exchange for significant investments). Everything else is just an illusion. The system is too complex, so it's better to find other hobbies.

119 Comments
2024/09/02
17:03 UTC

1

Hoping to get some feedback on Text based approach to processing data

Hoping to get some feedback on an approach for processing Text Based Data

I'm pretty new to trading. I've created a Jupyter notebook to test out an idea I had to process the Google Trends newsletter and see if there was any correlation to the movement of the S&P 500 (via SPY ETF).

My idea was:

  1. Convert the text into embeddings using OpenAI's embedding api
  2. Generate labels as the possible movement of the next business day's high and low using the price at the time the newsletter was received as the baseline.

I've also created a similar model but instead of embeddings, vectorized the words and applied a TfidTransformer to extract the most relevant word/char vectors. To evaluate both models I've created a a daily cron process since I wasn't able to find back dated Google Trends newletters.

With more data the Vectorized model actually ended up performing better (while with less data embedding we’re better). I thought embedding a would’ve done a better job of extracting context as more data was incorporated.

As I'm relatively new to trading, I was curious if the approach for trying to guess the next day's high and low made sense or if there was some kind of more standard indicator that I could be using?

0 Comments
2024/09/02
15:10 UTC

1

FrontEnd for custom backend backtest/forwardtest engine

Hello there !

I spent a bit of time building a platform to run backtests and forwardtests (and one day live ones).

But for now, I'm just doing my strategies through a console, which is not ideal when you want to analyse things.

So, it already took a lot of times for doing my own engine (which was much more for the fun part, than for the real utility of it), so I would prefer not to reinvent the wheel on the frontside and use whatever is already available.

What are you using and/or what would you use ?

I have several ideas:

  • Extract data and display them with a bunch of Python scripts to run analysis

  • Use an existing front-end (Is it possible to use TradingView with a custom data feed for anything ?)

  • Any other idea ?

Thanks a lot ! :)

0 Comments
2024/09/02
13:13 UTC

15

Does any broker allow algotrading in a HSA?

Is there any broker that has API access to a health savings account? Particularly, can one trade options?

If you didn't know, an HSA is triple tax advantaged. (I just learned that part this week)

https://smartasset.com/insurance/hsa-triple-tax-advantage

38 Comments
2024/09/01
06:40 UTC

100

Poor man's vol dispersion hedge fund larp trade

I am only half kidding:

  1. Filter for stocks with weekly options and penny options
  2. Split the account in 20 parts
  3. With the 10 parts buy bear put spreads at the money for 50/50 risk return on 10 random stocks. Yes, random because you are not a stock picker.
  4. With the remaining 10 parts, buy an at the money bull call spread on SPY, at 50/50 risk return
  5. Wait until midday Friday, then roll for next week
  6. Keep rolling

This will take you an hour on Fridays, and you can larp to be a hedge fund manager.

The implicit assumptions are:

  1. Full on vol diserpsion arb is cost prohibitive for retail traders
  2. Retail traders pick the wrong stocks, so put spreads are the the weapon of choice
  3. Vertical spreads are easy to manage, or in this case, monitor
  4. SPY goes up most weeks
  5. Even if SPY tanks, individual random stocks will drop more than SPY

I run a version of this trade, and it's been good.

Shoot holes in this and tear it apart - would love to hear your harshest criticisms.

PS: For the hotheats, algotrading means that the trades are formulated by an algorithm, and the stuff spelled out above is an algorithm coded in English. No need to code in another language, or automate, in order to qualify as algo. just so we are clear and we get that out of the way.

EDIT: For the curious, the randomizer spit out these stocks this week. You can find the full list of weeklys here: https://www.cboe.com/available\_weeklys/. No position yet, but I am sticking to it, small part of the account obviously.

|| || |Ticker|Name| |DBX|DROPBOX INC CL A| |JPM|JPMORGAN CHASE & CO. COM| |PEP|PEPSICO INC COM| |MDLZ|MONDELEZ INTL INC CL A| |TSCO|TRACTOR SUPPLY CO COM| |HRL|HORMEL FOODS CORP COM| |NTAP|NETAPP INC COM| |JBLU|JETBLUE AWYS CORP COM| |PBI|PITNEY BOWES INC COM| |RDFN|REDFIN CORP COM|

EDIT2: I have put verticals on all but PEP which had horrible pricing today and I could not get anywhere close to even. I also have a 560/561 long call spread on SPY.

EDIT3: 231 people saved/shared the link and will be running random stocks against SPY - let's get it ; ) In all seriousness, thanks for the feedback and don't literally do this at home, as you will probably lose money. I run this strategy with a small amount of my trading capital, and with certain refinements, so do your own research, make your own trades, keep your trades small, and trade carefully. Cheers!

https://preview.redd.it/acf94q6vtdmd1.png?width=725&format=png&auto=webp&s=bcf7892e4cd9a364adafb33b6376f5853f0c410e

40 Comments
2024/08/29
12:45 UTC

23

Best historical data for ninja strategy analyzer

Hi all, I currently have a kinetick data feed subscription which gives me 2 years worth of historical bar data for most futures (which is what im trying to backtest on). I want to forward test on samples outside of a 2 year range and also just have a larger sample size.

I’m looking for the best source of data to get around 5-10 years of bar data (I don’t need tick data), was wondering if people are buying data from a source other than kinetick for cheaper? Also if market replay data is available to download in bulk or not

Thanks in advance

15 Comments
2024/08/28
16:05 UTC

7

Quick question, does tvdatafeed return raw or adjusted data?

tvdatafeed is a python package that links to the trading view websocket and grabs data. it's a neat project. I looked through its github, searched the web, and looked through stack overflow. I couldn't find the answer in my online search. does tvdatafeed return raw or adjusted data? I'm hoping someone with better networking, maybe developer tool skills, or just general sleuthing can figure this out. I'm trying to get my forward-testing straightened out. Happy algo-trading!

4 Comments
2024/08/28
08:56 UTC

12

Who is working out of shared codebases?

Are you working out or a shared codebase source, or working based on your own specs? Doesn’t have to be full on scrum ceremony. Are you the main stakeholders of this codebase? Running your money, or someone else’s? Very curious how the many facets of this business impact the SDLC of a project

12 Comments
2024/08/28
06:04 UTC

1

Server Side Automated TP/SL

I’m dealing with a lot of connection issues from my broker on weekends and it’s disrupting my bracket orders which are sitting on my local PC. Leaving me with a naked position on Sunday night when the futures market opens back up.

I understand ninjatrader allow traders to enable “server side orders” for traders who use their brokerage but it’s only for discretionary traders who use an “ATM Strategy” not for system traders.

Is there a platform and broker combo that’s allows traders to have server side systems running and keep their system functioning? Meaning a trailing stop or any other functionality according to their script would still work and not just keep a stop loss fixed at a certain price?

2 Comments
2024/08/27
13:07 UTC

108

Any good textbook that covers financial data (like vendors)

I need a textbook recommendation.
I'm looking for a textbook that covers the general knowledge you need to handle financial data like:

  1. security id system like CUSIP, ISIN, CIK, TICKER, etc

  2. financial database architecture to handle data like adjusted close price

  3. caveats when handling financial time series data covering topics like point-in-time, filing date, etc

  4. data preprocessing tips like outlier detection, winsorization in the context of finance domain

  5. Handling data pipeline for finance, DB(MS) for this.

  6. Other topics like DMA execution, order book data handling, etc

Is there any good textbook that covers topics like these?

I have seem many quant textbooks on factors and strategies or even system trading but I've never seen a book dedicated solely to the financial data.

Any good book I can look into?

20 Comments
2024/08/27
02:54 UTC

8

Hedging Short-Term Futures Feasibility

Hi all,

I’ve written up an algo that is doing very well live, trading futures. I’m no quant and am unexperienced with options. I’m just curious whether incorporating options could raise my RR per trade. If so, how might you approach this?

Some potentially relevant information: Trades currently take about 1-5 minutes to hit TP/SL, longer ones taking being between 5-15 minutes. RR is fixed at 1:1. I could de-leverage a bit and get average trade duration up to 15-30 minutes, but would have less trades during the average day.

Thanks! :)

23 Comments
2024/08/26
05:12 UTC

54 Comments
2024/08/24
15:08 UTC

560

Backtest results for a simple "Buy the Dip" strategy

I came across this trading strategy quite a while ago, and decided to revisit it and do some backtesting, with impressive results, so I wanted to share it and see if there's anything I missed or any improvements that can be made to it.

Concept:

Strategy concept is quite simple: If the day's close is near the bottom of the range, the next day is more likely to be an upwards move.

Setup steps are:

Step 1: Calculate the current day's range (Range = High - Low)

Step 2: Calculate the "close distance", i.e. distance between the close and the low (Dist = Close - Low)

Step 3: Convert the "close distance" from step 2 into a percentage ([Dist / Range] * 100)

This close distance percentage number tells you how near the close is to the bottom of the day's range.

Analysis:

To verify the concept, I ran a test in python on 20 years worth of S&P 500 data. I tested a range of distances between the close and the low and measured the probability of the next day being an upwards move.

This is the result. The x axis is the close distance percentage from 5 to 100%. The y axis is the win rate. The horizontal orange line is the benchmark "buy and hold strategy" and the light blue line is the strategy line.

Close distance VS win percentage

What this shows is that as the "close distance percentage" decreases, the win rate increases.

Backtest:
I then took this further into an actual backtest, using the same 20 years of S&P500 data. To keep the backtest simple, I defined a threshold of 20% that the "close distance" has to be below.

EDITED 25/08: In addition to the signal above, the backtest checks that the day's range is greater than 10 points. This filters out the very small days where the close is near the low, but the range is so small that it doesn't constitute a proper "dip". I chose 10 as a quick filter, but going forward with this backtest, it would be more useful to calculate this value from the average range of the previous few days

If both conditions are met, then that's a signal to go long so I buy at the close of that day and exit at the close of the next day. I also backtested a buy and hold strategy to compare against and these are the results:

Balance over time. Cyan is buy and hold, green is buy dips strategy

Benchmark vs strategy metrics.

The results are quite positive. Not only does the strategy beat buy and hold, it also comes out with a lower drawdown, protecting the capital better. It is also only in the market 19% of the time, so the money is available the rest of the time to be used on other strategies.

Overfitting

There is always a risk of overfitting with this kind of backtest, so one additional step I took was to apply this same backtest across a few other indices. In total I ran this on the S&P, Dow Jones, Nasdaq composite, Russel and Nikkei. The results below show the comparison between the buy and hold (Blue) and the strategy (yellow), showing that the strategy outperformed in every test.

https://preview.redd.it/blqhj6fibmkd1.png?width=630&format=png&auto=webp&s=5aa3e5cb3e6979e32b936b4a3b4ba6e01b3e1f71

Caveats
While the results look promising, there are a few things to consider.

  1. Trading fees/commission/slippage not accounted for and likely to impact results
  2. Entries and exits are on the close. Realistically the trades would need to be entered a few minutes before the close, which may not always be possible and may affect the results

Final thoughts

This definitely seems to have potential so it's a strategy that I would be keen to test on live data with a demo account for a few months. This will give a much better idea of the performance and whether there is indeed an edge.

Does anyone have experience with a strategy like this or with buying dips in general?

More Info

This post is long enough as it is, so for a more detailed explanation I have linked the code and a video below:

Code is here on GitHub: https://github.com/russs123/Buy-The-Dip/tree/main

Video explaining the strategy, code and backtest here: https://youtu.be/rhjf6PCtSWw

146 Comments
2024/08/24
14:12 UTC

Back To Top