@søren-pallesen Directly from your favorite exchange, using the ccxt module, which is embedded in backtrader (see Ed Bartosh's branch, you'll find instructions above in this thread on how to install it).
Alternatively, you can use cryptocompare.com API. They keep the daily OHLCV of pretty much any cryptocurrency from the beginning. There you can specify if you want the volume-weighted average price across all listed exchanges, or if you prefer the price at a particular exchange.
Instructions on the API are available at https://min-api.cryptocompare.com/
A python wrapper for this API is available at https://github.com/stefs304/cryCompare
Best posts made by Benoît Zuber
-
RE: Anyone use backtrader to do live trading on Bitcoin exchange?
-
RE: Backtesting multiple symbols with different date ranges - backtest won't start until all data feeds have data
Note that data0 is the master data and sets the time when trades will start (using Paska Houso's trick above). So make sure data0 is the data feed with the oldest start date.
Latest posts made by Benoît Zuber
-
closing a cerebro plot
What would be the python command to close a figure generated by the plot method of a cerebro instance?
-
RE: progress bar / ETA during optimization
@tw00000 no I did not try much...
-
RE: Where is position opening date stored?
Thanks! In fact I would like to check the opening date of a few specific positions after a cerebro run finished. I can make a dictionary containing the last opening date for each position within the strategy but I was wondering if there was a built-in function.
-
Where is position opening date stored?
Say a position was opened on 1 June 2018. Is this information saved in the strategy? If yes, where?
Thanks -
position sizing when you have short positions in your portfolio
I have a conceptual question regarding position sizing. So far I have not been margin trading. I have calculated new position sizing as a function of my account value. Namely I have sized each position to risk 0.2 % of my account value.
Now I want to add shorting to my strategy. I am not too sure how to calculate new position sizing if I have some short positions in my account. Let us take an example.- I start with $1000 cash. My account value is therefore $1000.
- Then I get a short position for $400 of asset A.
My new account value is $600, and my new cash value is $1400.
Let us now consider that I want to get a long position of asset B. If I bought it before I shorted asset A, asset B position size would have been, say, $200.
If I bought i after I shorted asset A, asset B position size would have been 200*600/1000 = $120.Do you guys think this is the right thing to do, or should I have bought in both cases for $200 of asset B? If you think the latter is better, how would you calculate position sizing? would you calculate it as a function of (account value + absolute value of all short postions) ?
Thanks
-
RE: allow cash to get negative
@backtrader Thanks! Yes I am exploring this route. I may come up with a few questions later.
Cheers -
allow cash to get negative
Is it possible to let broker trade even if there is not enough cash? Say, get_cash() reports $1000. My strategy says it should buy some asset for a value of $2000. Backtrader broker normal behaviour will be not to execute the order since the trade would cost more cash than available.
I would like to let the trade happen and allow cash to get negative (equivalent to having borrowed cash). Is this possible? Or should I determine that I have not enough cash, and add a certain amount of cash to my account?
I'd prefer the first option, since I don't want my account value to increase when I borrow. I'd rather like to keep track of my dept in account value. My position sizing indeed depends on account value and I don't want the strategy to start oversizing positions because it sees fresh cash coming and does not understand that this is borrowed money and that the net account value does not increase when money is borrowed. -
RE: Anyone use backtrader to do live trading on Bitcoin exchange?
@søren-pallesen Directly from your favorite exchange, using the ccxt module, which is embedded in backtrader (see Ed Bartosh's branch, you'll find instructions above in this thread on how to install it).
Alternatively, you can use cryptocompare.com API. They keep the daily OHLCV of pretty much any cryptocurrency from the beginning. There you can specify if you want the volume-weighted average price across all listed exchanges, or if you prefer the price at a particular exchange.
Instructions on the API are available at https://min-api.cryptocompare.com/
A python wrapper for this API is available at https://github.com/stefs304/cryCompare -
RE: progress bar / ETA during optimization
@backtrader Sorry I am still kind of lost. In my main function I understand that I should have
cerebro.optstrategy(MyStrategy, **param_range, printlog=False) cerebro.optcallbacks(my_callback) cerebro.run()
But where do I define my_callback? And what should it look like? Will it call some method of the strategies? If yes, which one?
I was trying to do the dumbest test, i.e. print("finished") after each strategy finishes, but I couldn't get it to work. How would you do that?