ta-oliver / infertrade

Open source trading and investment strategy library designed for accessibility and compatibility
Apache License 2.0
34 stars 20 forks source link

Fixed calculation results found in performance.py #179

Closed NikolaR01 closed 3 years ago

NikolaR01 commented 3 years ago

I found a couple values that are calculated using hard coded values of 0 and 1 where after the calculation checks for the result are unusable since the equation will always give the same result.

For example:

current_valuation = spot_price * last_securities_after_transaction + last_cash_after_trade

In this instance last_securities_after_transaction = 0 and last_cash_after trade = 1

The result of the calculation will always be 1.

I'm not sure if this is a mistake in the formula used or if last_cash_after_trade and last_securities_after_transaction should be set to different values.

The same issue can be seen with current_allocation:

current_allocation = (spot_price * last_securities_after_transaction) / current_valuation

ta-oliver commented 3 years ago

that are calculated using hard coded values of 0 and 1

Typically these vaues would not be hardcoded but depend on the allocations taken. Maybe worth checking in debug mode as variable value should be changing.

ta-oliver commented 3 years ago

@NikolaR01 - please can you add links to the specific lines of code that are hardcoded and/or a feature branch that replicates unexpected behaviour.

NikolaR01 commented 3 years ago

First instance of issue can be seen here

and the second instance is found here

the hard coded values are declared here

ta-oliver commented 3 years ago
current_allocation = (spot_price * last_securities_after_transaction) / current_valuation

Which are hardcoded?

last_securities_after_transaction is modified on the following line:

https://github.com/ta-oliver/infertrade/blob/29a4b99496bf5e5e275c5cb62779e70e5de0ae0a/infertrade/utilities/performance.py#L232

Spot_price and current_valuation also vary day to day.

NikolaR01 commented 3 years ago

Spot price varies day to day but in the case of the two calculations i mentioned last_securities_after_transaction and last_cash_after_trade are not changed at any point following up to them, resulting in current_allocation and current_valuation constantly having the same outcome

ta-oliver commented 3 years ago

are not changed at any point following up to them, resulting in current_allocation and current_valuation constantly having the same outcome

last_securities_after_transaction is changed in line 232.

This whole statement is in a loop, so when it is changed on line 232 it will change the next value calculated on line 135.