Replies: 2 comments 1 reply
-
Here's how to execute at the next open: open = pd.Series([1, 2, 3, 4, 5])
close = pd.Series([2, 3, 4, 5, 6])
entries = pd.Series([False, True, False, False, False])
exits = pd.Series([False, False, False, True, False])
pf = vbt.Portfolio.from_signals(
close,
entries.vbt.signals.fshift(),
exits.vbt.signals.fshift(),
price=open
)
print(pf.orders.records_readable)
Order Id Column Timestamp Size Price Fees Side
0 0 0 2 33.333333 3.0 0.0 Buy
1 1 0 4 33.333333 5.0 0.0 Sell |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you for the fast reply. I get the impression that this only takes long trades?
I would need both directions...
…-------- Original Message --------
On Jan 2, 2022, 23:05, Oleg Polakow wrote:
Here's how to execute at the next open:
open
=
pd
.
Series
([
1
,
2
,
3
,
4
,
5
])
close
=
pd
.
Series
([
2
,
3
,
4
,
5
,
6
])
entries
=
pd
.
Series
([
False
,
True
,
False
,
False
,
False
])
exits
=
pd
.
Series
([
False
,
False
,
False
,
True
,
False
])
pf
=
vbt
.
Portfolio
.
from_signals
(
close
,
entries
.
vbt
.
signals
.
fshift
(),
exits
.
vbt
.
signals
.
fshift
(),
price
=
open
)
print
(
pf
.
orders
.
records_readable
)
Order
Id
Column
Timestamp
Size
Price
Fees
Side
0
0
0
2
33.333333
3.0
0.0
Buy
1
1
0
4
33.333333
5.0
0.0
Sell
—
Reply to this email directly, [view it on GitHub](#317 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AQ56D3DJKF3ASLE6JOO7HM3UUDD3LANCNFSM5LEDJFYA).
Triage notifications on the go with GitHub Mobile for [iOS](https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675) or [Android](https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As I am moving into vectorbt for backtesting I am trying to figure out the tradinglogic.
I get completely different results with the codes below. For some reason I get completely different results. I am not talking about the log returns, but a complete different equity curve. There is a shift in the signalvalues of 1 because of the trading delay of 1 day.
What could be the reason for such a big difference?
#####################
def backtest(frame,signals,settings):
try:
#################################
#ML model predict price
prediction=model.predict(prices)
signals = list(prediction.astype(int))
full_prices['signal']=signals
print ('prediction done')
full_prices['signal_shift']=full_prices['signal'].shift(1)
full_prices.set_index('date',inplace=True)
#vectorbt backtest
entries = full_prices['signal_shift']>0
exits = full_prices['signal_shift']<0
pf = vbt.Portfolio.from_signals(full_prices['close'], entries, exits, init_cash=100,size=1000,fees=0)
print (pf.stats())
pf.plot().show()
Beta Was this translation helpful? Give feedback.
All reactions