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

Custom sizing in portfolio.from_signals. #684

Open
IgorDrgonec opened this issue Jan 30, 2024 · 0 comments
Open

Custom sizing in portfolio.from_signals. #684

IgorDrgonec opened this issue Jan 30, 2024 · 0 comments

Comments

@IgorDrgonec
Copy link

IgorDrgonec commented Jan 30, 2024

Hi. I'm trying to get either OrderContext.cash_now or SimulationContext_last_cash (should be the same) from my portfolio from signals to get current cash and then calculate size of the position to always risk 1% (lose 1% of cash when stop loss is hit). I saw in documentation that SizeType "Percentage" is calculated from OrderContext.cash_now, but I can not get this done. Could you please help me? Somehow I can't manage to get OrderContext.cash_now or SimulationContext_last_cash out of portfolio for my function where I calculate sizing.

This is my portfolio without sizing calculation:

portfolio_signals = vbt.Portfolio.from_signals(
    df['Close'], 
    signal_func_nb=nb.dir_enex_signal_func_nb,
    signal_args=(np.asarray(long_entries), np.asarray(long_exits_final), np.asarray(Direction.LongOnly)),
    init_cash = initial_capital,
    freq="1d")
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

No branches or pull requests

1 participant