Bitcoin Forum
June 28, 2024, 01:42:35 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: zipline / Quantopian - backtesting / trading framework  (Read 26829 times)
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 15, 2013, 04:45:07 AM
Last edit: May 15, 2013, 05:03:33 AM by c0inbuster
 #21

Quote
Am I correct to assume it should be
Code:
size=self.trade_volume

no, it's
Code:
size=self.invested
[/quote]
(because of commission fees)
 that's fixed in my gist now...

if you have some coding ability could you try to implement this
http://www.onestepremoved.com/backtesting-efficiency/

Quote
Really fascinating stuff, playing with these examples to try and get up to speed.

Overfitting a backtest, is really easy... but it does not reflect future results
https://www.google.fr/search?q=backtest+overfitting

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 15, 2013, 11:24:12 AM
 #22

New feature :
variable lot size (instead of fixed lot size)
self.trade_volume is now a function which returns volume to trade according
portfolio cash and BTCUSD price.

http://nbviewer.ipython.org/587a80f5e2eb9cf41d6d

alpha= 138.7%
max DD = 7.5%

should I order the rolls-royce?  Grin

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
MtQuid
Newbie
*
Offline Offline

Activity: 24
Merit: 0



View Profile
May 15, 2013, 12:18:15 PM
Last edit: May 15, 2013, 01:50:18 PM by MtQuid
 #23

New feature :
variable lot size (instead of fixed lot size)
self.trade_volume is now a function which returns volume to trade according
portfolio cash and BTCUSD price.

http://nbviewer.ipython.org/587a80f5e2eb9cf41d6d

alpha= 138.7%
max DD = 7.5%

should I order the rolls-royce?  Grin

Nice work.... if only we could go back in time Smiley
I think there were some missing rows in the method I used to pull from bitcoincharts so I've made some modifications and a cache that stays up to date.
I've also include frequency information but still 'minute' runs are not working correctly.  We might have to tamper with zipline internals to get them going.
You should update your work to at least use the better bitcoincharts methods.

Now in my testing I keep an up to date cache of minute data from bitcoincharts and resample that to how I want it.

Fractional trades are still an issue.  
A fix would be to use satoshi but then the prices will all have to be suitable scaled and the results will just look a mess.
Or bump the initial portfolio value up to a few billion and increase the trade volume so that there will be no fractions but then slippage is very unrealistic.
Or modify zipline internals or use an inherited object

About passing live trade data to an algorithm:
I'm thinking of creating a new TradingAlgorithm object that is passed a DateTimeIndex and will take trade data from the phantom sqlite3 db and create OHCL and pass both simulated live data and OHCL to an algorithm under test.  So the wrapper gets a datetime and frequency from zipline and extracts the data from the phantom db, passes this to the algo inder test and then passes the results back to zipline.
Just an idea bu this might also be a way to fix the fractional trades issue.

Updated - http://nbviewer.ipython.org/5572250


Edit: In fact even if the zipline results records are always daily it does not matter because we can put minute results into something else, or accumulate them for a day.  Depends on what you want to log in the results.  Currently, I guess that, the same record gets overwritten a lot for each minute in a day so only the last record of the day is saved in the results
Also seams like there is a bug in my example because the trade volumes are messed up and I've lost a lot of money :/

Edit:  All working now.  I was not using ohlc resampling
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 15, 2013, 03:33:33 PM
 #24

Quote
Nice work.... if only we could go back in time

zipline uses Delorean...
http://delorean.readthedocs.org/en/latest/quickstart.html
maybe it could help  Wink

+1 for splitting work into 2 parts:
a data producer (which store OHLC values into database)
a data consumer which will read data, show prices, apply strategy

but in such a case I wonder how you can    
inform data consumer that new data are just coming in...

but maybe in your idea data consumer will only react every 5 minutes...

that's quite different from Metrader start function which is launch
every tick...

but when I'm saying that "Metrader start function is launch every tick..."
in fact I think that start function is launch every tick **if that's possible**
(if previous start function call is finished)
if previous start function call is not finished, even if a new tick is coming
start will not be executed again.
(but Metatrader shows on the GUI the new price from last tick,
but expert advisor start function is not executed again)

So I think a kind of mechanism with signal/slot is needed but we also need a kind of "lock"
mechanism.

I hope you understand what I mean...

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
monsterer
Legendary
*
Offline Offline

Activity: 1008
Merit: 1002


View Profile
May 15, 2013, 04:40:52 PM
 #25

I don't want to be disparaging, but I found that just using OHLCV was giving very misleading results for bitcoin when testing algorithms.

The reason is liquidity. The top-of-the-book Bid/Ask values often don't have enough volume associated with them to be tradable   - in real life you'd get a partial fill on your orders, or no fill at all.

You really need the entire order-book, which is what I ended up capturing. This perfectly captures the liquidity of the market for the period tested. Requires a lot of data, but storage is cheap.

Smiley

Cheers, Paul.
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 15, 2013, 04:50:02 PM
 #26

don't worry... I don't consider you as disparaging us...
A volume dependant model for spread could help...
Maybe you can help us to get it (using historical orderbook depth)

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
monsterer
Legendary
*
Offline Offline

Activity: 1008
Merit: 1002


View Profile
May 15, 2013, 05:01:56 PM
 #27

don't worry... I don't consider you as disparaging us...
A volume dependant model for spread could help...
Maybe you can help us to get it (using historical orderbook depth)

I'm not sure how you could approximate the order-book well enough with just two values - it works fine for forex symbols because of the huge liquidity, but bitcoin is a different kettle of fish.

Like I say, I just store the whole order-book every 10 seconds - really it wants to be tick by tick, though for total accuracy Smiley
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 15, 2013, 05:44:53 PM
 #28

Could you provide such data ?

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
monsterer
Legendary
*
Offline Offline

Activity: 1008
Merit: 1002


View Profile
May 15, 2013, 06:11:24 PM
 #29

Could you provide such data ?

Unfortunately, I've only been collecting it for the last 6 days. I had been collecting for 1 month last year but there was a big gap between that and now so I don't have anything worth while to give you :|

Best thing to do is to start collecting it now and then if you decide you need it, you've got it Smiley
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 16, 2013, 07:06:24 AM
 #30

Live trading / paper trading with Quantopian

http://blog.quantopian.com/paper-trading-and-live-trading/

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
c0inbuster (OP)
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
May 16, 2013, 02:56:31 PM
Last edit: May 16, 2013, 03:06:58 PM by c0inbuster
 #31

zipline / quantopian developers seems to be interested by this thread

you can also share your experiences at
https://groups.google.com/forum/#!topic/zipline/M39VhqDRORM

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!