karlwancl / Trady

Trady is a handy library for computing technical indicators, and it targets to be an automated trading system that provides stock data feeding, indicator computing, strategy building and automatic trading. It is built based on .NET Standard 2.0.
https://lppkarl.github.io/Trady
Apache License 2.0
545 stars 185 forks source link

Negative numbers in result.Transactions[x].Quantity #70

Closed irperez closed 5 years ago

irperez commented 6 years ago

I'm seeing negative numbers consistently in the Quantity field in the Transactions after a back test run. See below.

image

And this is the builder code to set things up.

image

karlwancl commented 6 years ago

@irperez The case happens because the Fee parameter is misused in the builder, the fee here is used for currency exchange when use foreign currency to buy stock, it should be the fee for exchange, and should be a rate (between 0 and 1).

To clarify the use case, I've renamed those method in the Builder class, 'Fee' is changed to 'FlatExchangeFeeRate', 'BuyCompleteCurrencies' is changed to 'BuyWithAllAvailableCash', and moved premium to the Builder class.

The document has also been updated for the case, you can also refer the case there.

irperez commented 6 years ago

That makes a ton more sense. We should put validation so that the Fee is only ever between 0 and 1.

irperez commented 6 years ago

Is there a way to track transaction costs per trade?

karlwancl commented 6 years ago

The cost are not currently added into each Transaction object, but should be easy to implement, you can study Runner.cs line number 101-147 for creation of Transaction object.

irperez commented 6 years ago

Ok, I'll see if I can make a PR for this.

karlwancl commented 5 years ago

@irperez Would like to confirm if it has been implemented or abandoned? Thanks.

irperez commented 5 years ago

@lppkarl I've put in a PR for this one. Sorry it took so long.

karlwancl commented 5 years ago

@irperez it's ok, just want to confirm it's done. Thanks 👍