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

Live trade session #190

Merged
merged 2 commits into from
Mar 9, 2017
Merged

Conversation

ryankennedyio
Copy link
Contributor

Minor refactor of the original backtest.py class to also allow for live trading. Live trading only differs in that it's "end-condition" is the passing of time, until and end_session_time. All loop logic remains the same.

This branch is a dependancy of #186. I created a new branch here as the logic has no overlap with IB integration.

I'm suggesting we don't do the IBService setup/teardown in the TradingSession -- we must do it in the setup scripts where the user defines their strategy, symbols, handlers, etc.

Otherwise we need to create a TradingSession for each service, or create an abstraction where we take in a list of services (unnecessarily complex). As it stands, the TradingSession simply takes in a set of QSTrader components (price, risk, execution handlers, etc) -- each of these components may have services/external system dependancies, but the trading loop does not -and should not- care.

Would appreciate prompt integration with master so I can get cracking with live market data in the IB-PriceHandler

@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage increased (+0.04%) to 57.143% when pulling fdb7a55 on ryankennedyio:live_trade_session into ca05a06 on mhallsmoore:master.

@femtotrader
Copy link
Contributor

femtotrader commented Mar 9, 2017

I wonder if such a class can handle

  • backtest
  • live trade
  • but also paper trader (live price feed but simulated execution)

I really think that an abstract class AbstractTradingSession and 3 inherited classes BacktestSession, LiveTradeSession, PaperTradeSession is a cleaner approach.

But renaming simulate_trading method to start_trading (or simply start or run) is a good idea.

@mhallsmoore mhallsmoore merged commit 5f8d23a into mhallsmoore:master Mar 9, 2017
@mhallsmoore
Copy link
Owner

No problem - promptly done! ;-)

If you feel you need to change some of the logic in the previous (to this merge) Backtest object (which is now TradingSession), go ahead. I modified it to make the API cleaner, such that we didn't end up with these rather large ***_backtest.py files containing all of the instantiations of the respective components.

I'm definitely open to trying to find ways to make this simpler for new users, but at the same time extensible for those who wish to tinker a bit more.

@ryankennedyio
Copy link
Contributor Author

Thanks @mhallsmoore

@femtotrader with regard to paper trade, don't all brokers offer a separate paper trading account ? I.e. from the system point of view, live is the same as paper?

I think even if we did do that, the trading loop logic should be the same; it's just the ExecutionHandler and Portfolio classes wouldn't have feeds to the broker for live execution/portfolio stats?

Just IMO more abstraction here probably isn't going to be used too often? I think we should have abstract base classes where we expect that users will implement their own inherited classes "fairly" often. I guess if we find people often need to override the trading sessions, we can add the abstraction in.

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 this pull request may close these issues.

None yet

4 participants