Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue]: ValueError: Invalid frequency value. The only frequencies supported frequencies are: Frequency.DAILY and Frequency.MIN_1 #128

Closed
fercabr03 opened this issue Sep 28, 2023 · 5 comments · Fixed by #135

Comments

@fercabr03
Copy link

Summary

Hello there!

I am testing the QF-lib framework and when I tried load Frequency.5M, Frequency.15M and others, I got the following message: "Invalid frequency value. The only frequencies supported frequencies are: Frequency.DAILY and Frequency.MIN_1".
I was wondering why the backtesting tool has this limitation? Is there a way to run a backtest using other intraday frequencies?
Thanks !

@myrmarachne
Copy link
Member

Hi!

The whole idea was to use either 1 minute or daily frequency for for the simulation of the backtest, because some of the additional functionality available in the project might not work as desired when using e.g. 15 min frequency.

One of the examples would be the scheduling_time_delay which you can set on the BacktestTradingSessionBuilder. By default trades are not executed immediately on the same bar as the signal was computed, but with a certain delay. Default delay for intraday backtests is 1 minute, so if the DataHandler used for the backtesting flow would use 5 min or 15 min data, depending on the strategy the behaviour could be ambiguous (order could wait or be cancelled) and we thought it would overcomplicate the whole setup. To sum up - this restriction really matters only for the DataHandler used for the backtest flow, but you could use a different DataProvider, with a different frequency, to just run your strategy, compute signals etc.

Nevertheless, thanks for reaching out with this issue, we will investigate further if it is something we will be able to work on in the future releases, as many changes were introduced already since the initial design. And in the meantime - what is exactly your use case? Do you have 1 minute frequency data or the issue is that you simply have access only to the 5 / 15 minutes bars? If you give us some more details maybe we can find a workaround.

@fercabr03
Copy link
Author

Hello! Thanks for you response!
To guive you some context, I am a retail trader and was testing some backtesting frameworks to work on my own strategies. I found out about qf-lib from a twitter post and was very impressed. Qf-lib is the most advanced backtesting open-source framework I ´ve seen.
Then I setup an environment and tested the examples availiable with success. My next step was to apply it to my data. I have tick data from a continuous future contract on the Brazilian Equities Index, which I converted to the following :

  • time bars intervals (minutes): 1,3,5,15,30 and 60
  • volume bars (1000 contracts)
    The 1 minute data worked, but that was it. This is too "high-frequency" for a retail trading with my capabilities. I want to take advantage of intraday strategies in the range of 5 to 30 minutes, but the "1-minute limitation" did not allow me to do that. At least I did not find a way to solve this problem. If there is a workaround let me know.
    My intention is also to explore other "non-time" type bars, which would be the next step in my research. These bars have different behavior than time bars. In this case a the customization is a little more complex.
    For now I have decided to use another framework cause it allows for an easier customization for my current needs, but I have my eyes on qf-lib and will keep following this project, so in the future I migrate to qf-lib cause it is more robust and complete library. I am very interested in this project.
    If you need any other information or I can be of assitance in any other way, please let know.

Regards
Fernando

@myrmarachne
Copy link
Member

Hi,
Thanks for the details. From what I understand from your description I believe the following setup would work for you, is that right?

  • 1 minute data bars used for the backtest flow
  • 30 minutes data bars used to compute signals / orders
  • signals / orders computed every 1 hour

So in general - new order would be created only once per hour and data used for this purpose would be the 30 mins bars. 1 minute data would be needed to just feed the backtest trading session, to run the whole backtest, but will not be used to actually trade with such frequency.
If this is what you were looking for we can create a demo script with some sample strategy working like that, in case it's still different let us know.

Regarding the "non-time" bars - currently all of our events that are used to generate orders are time based events.
The simplest thing that can be done is the following: using 1 minute bars for backtest flow, scheduling the orders calculation every 30 minutes and computing your non-time bars to make a decision every 30 minutes.
We will look into this more and see if we can provide some example that would make sense.

@fercabr03
Copy link
Author

fercabr03 commented Oct 31, 2023 via email

myrmarachne pushed a commit that referenced this issue Nov 9, 2023
* Add intraday strategy example
@myrmarachne
Copy link
Member

Hi Fernando,

we added a demo with additional notes on how to set the frequency separately for bars and separately for orders calculation in our tutorials:

https://qf-lib.readthedocs.io/en/latest/tutorials/first_strategy_backtest.html#intraday-strategy-example

I hope this fits your requirements, but if you have more questions please let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants