MiniXC / simple-back

A simple daily python backtester that works out of the box.
Mozilla Public License 2.0
59 stars 12 forks source link

change in ordering api #5

Closed MiniXC closed 4 years ago

MiniXC commented 4 years ago

At the moment the ordering is a bit clumsy and counter-intuitive (see example below).

b.order_pct('MSFT', 0.5) # long 50% of value in MSFT (will fail if >50% are invested)
b.order_abs('MSFT', 1_000) # long 1_000$ MSFT
b.order_abs('MSFT', b.balance.current*0.5) # long 50% of available funds in MSFT

b.order_pct('MSFT', -1) # short 100% MSFT
...

Proposed

b.long('MSFT', percent=.5)
b.long('MSFT', absolute=1_000)
b.long('MSFT', percent_available=.5)
b.long('MSFT', nshares=1)
# equivalent for short

Any other suggestions? What (if anything) should it default to when the keyword isn't set?

1D0BE commented 4 years ago

Good idea. I like it.

Would suggest also allowing num_shares=x as a parameter. Would also suggest adding a default for b.long("ticker", 1) Maybe 1 is interpreted as # of shares or dollar amount? Specify in any case.

I think the wording for percent_balance is unclear, as a balance can denote multiple things. I think a more understandable wording might be percent_available

MiniXC commented 4 years ago

Thanks for the input, agree with percent_available, will also change b.balance.current to b.balance.available then. I also added num_shares to the proposal.

I have no idea for what would be a sensible default, because all options are equivalent. It might just make more sense to not allow use of the function without a specific kwarg for now, and when a clear "favourite" emerges that is used most of the time, we can still make it default.

MiniXC commented 4 years ago

Changed num_shares to nshares

MiniXC commented 4 years ago

Implemented in 51812e5530ec5ced7e7837b02f247b86a1fbdc66